ed5367dc19428643269c735c04de04628ff04193
[pandora-kernel.git] / drivers / staging / rtl8192su / ieee80211 / rtl819x_HTProc.c
1
2 //As this function is mainly ported from Windows driver, so leave the name little changed. If any confusion caused, tell me. Created by WB. 2008.05.08
3 #include "ieee80211.h"
4 #include "rtl819x_HT.h"
5 u8 MCS_FILTER_ALL[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
6
7 u8 MCS_FILTER_1SS[16] = {0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
8
9 u16 MCS_DATA_RATE[2][2][77] =
10         {       {       {13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78 ,104, 156, 208, 234, 260,
11                         39, 78, 117, 234, 312, 351, 390, 52, 104, 156, 208, 312, 416, 468, 520,
12                         0, 78, 104, 130, 117, 156, 195, 104, 130, 130, 156, 182, 182, 208, 156, 195,
13                         195, 234, 273, 273, 312, 130, 156, 181, 156, 181, 208, 234, 208, 234, 260, 260,
14                         286, 195, 234, 273, 234, 273, 312, 351, 312, 351, 390, 390, 429},                       // Long GI, 20MHz
15                         {14, 29, 43, 58, 87, 116, 130, 144, 29, 58, 87, 116, 173, 231, 260, 289,
16                         43, 87, 130, 173, 260, 347, 390, 433, 58, 116, 173, 231, 347, 462, 520, 578,
17                         0, 87, 116, 144, 130, 173, 217, 116, 144, 144, 173, 202, 202, 231, 173, 217,
18                         217, 260, 303, 303, 347, 144, 173, 202, 173, 202, 231, 260, 231, 260, 289, 289,
19                         318, 217, 260, 303, 260, 303, 347, 390, 347, 390, 433, 433, 477}        },              // Short GI, 20MHz
20                 {       {27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540,
21                         81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648, 864, 972, 1080,
22                         12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324, 378, 378, 432, 324, 405,
23                         405, 486, 567, 567, 648, 270, 324, 378, 324, 378, 432, 486, 432, 486, 540, 540,
24                         594, 405, 486, 567, 486, 567, 648, 729, 648, 729, 810, 810, 891},       // Long GI, 40MHz
25                         {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600,
26                         90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720, 960, 1080, 1200,
27                         13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360, 420, 420, 480, 360, 450,
28                         450, 540, 630, 630, 720, 300, 360, 420, 360, 420, 480, 540, 480, 540, 600, 600,
29                         660, 450, 540, 630, 540, 630, 720, 810, 720, 810, 900, 900, 990}        }       // Short GI, 40MHz
30         };
31
32 static u8 UNKNOWN_BORADCOM[3] = {0x00, 0x14, 0xbf};
33 static u8 LINKSYSWRT330_LINKSYSWRT300_BROADCOM[3] = {0x00, 0x1a, 0x70};
34 static u8 LINKSYSWRT350_LINKSYSWRT150_BROADCOM[3] = {0x00, 0x1d, 0x7e};
35 static u8 NETGEAR834Bv2_BROADCOM[3] = {0x00, 0x1b, 0x2f};
36 static u8 BELKINF5D8233V1_RALINK[3] = {0x00, 0x17, 0x3f};       //cosa 03202008
37 static u8 BELKINF5D82334V3_RALINK[3] = {0x00, 0x1c, 0xdf};
38 static u8 PCI_RALINK[3] = {0x00, 0x90, 0xcc};
39 static u8 EDIMAX_RALINK[3] = {0x00, 0x0e, 0x2e};
40 static u8 AIRLINK_RALINK[3] = {0x00, 0x18, 0x02};
41 static u8 DLINK_ATHEROS_1[3] = {0x00, 0x1c, 0xf0};
42 static u8 DLINK_ATHEROS_2[3] = {0x00, 0x21, 0x91};
43 static u8 CISCO_BROADCOM[3] = {0x00, 0x17, 0x94};
44 static u8 LINKSYS_MARVELL_4400N[3] = {0x00, 0x14, 0xa4};
45 // 2008/04/01 MH For Cisco G mode RX TP We need to change FW duration. Shoud we put the
46 // code in other place??
47 //static u8 WIFI_CISCO_G_AP[3] = {0x00, 0x40, 0x96};
48 /********************************************************************************************************************
49  *function:  This function update default settings in pHTInfo structure
50  *   input:  PRT_HIGH_THROUGHPUT        pHTInfo
51  *  output:  none
52  *  return:  none
53  *  notice:  These value need be modified if any changes.
54  * *****************************************************************************************************************/
55 void HTUpdateDefaultSetting(struct ieee80211_device* ieee)
56 {
57         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
58         //const typeof( ((struct ieee80211_device *)0)->pHTInfo ) *__mptr = &pHTInfo;
59
60         //printk("pHTinfo:%p, &pHTinfo:%p, mptr:%p,  offsetof:%x\n", pHTInfo, &pHTInfo, __mptr, offsetof(struct ieee80211_device, pHTInfo));
61         //printk("===>ieee:%p,\n", ieee);
62         // ShortGI support
63         pHTInfo->bRegShortGI20MHz= 1;
64         pHTInfo->bRegShortGI40MHz= 1;
65
66         // 40MHz channel support
67         pHTInfo->bRegBW40MHz = 1;
68
69         // CCK rate support in 40MHz channel
70         if(pHTInfo->bRegBW40MHz)
71                 pHTInfo->bRegSuppCCK = 1;
72         else
73                 pHTInfo->bRegSuppCCK = true;
74
75         // AMSDU related
76         pHTInfo->nAMSDU_MaxSize = 7935UL;
77         pHTInfo->bAMSDU_Support = 0;
78
79         // AMPDU related
80         pHTInfo->bAMPDUEnable = 1; //YJ,test,090311
81         pHTInfo->AMPDU_Factor = 2; //// 0: 2n13(8K), 1:2n14(16K), 2:2n15(32K), 3:2n16(64k)
82         pHTInfo->MPDU_Density = 0;// 0: No restriction, 1: 1/8usec, 2: 1/4usec, 3: 1/2usec, 4: 1usec, 5: 2usec, 6: 4usec, 7:8usec
83
84         // MIMO Power Save
85         pHTInfo->SelfMimoPs = 3;// 0: Static Mimo Ps, 1: Dynamic Mimo Ps, 3: No Limitation, 2: Reserved(Set to 3 automatically.)
86         if(pHTInfo->SelfMimoPs == 2)
87                 pHTInfo->SelfMimoPs = 3;
88         // 8190 only. Assign rate operation mode to firmware
89         ieee->bTxDisableRateFallBack = 0;
90         ieee->bTxUseDriverAssingedRate = 0;
91
92 #ifdef  TO_DO_LIST
93         // 8190 only. Assign duration operation mode to firmware
94         pMgntInfo->bTxEnableFwCalcDur = (BOOLEAN)pNdisCommon->bRegTxEnableFwCalcDur;
95 #endif
96         // 8190 only, Realtek proprietary aggregation mode
97         // Set MPDUDensity=2,   1: Set MPDUDensity=2(32k)  for Realtek AP and set MPDUDensity=0(8k) for others
98         pHTInfo->bRegRT2RTAggregation = 1;//0: Set MPDUDensity=2,   1: Set MPDUDensity=2(32k)  for Realtek AP and set MPDUDensity=0(8k) for others
99
100         // For Rx Reorder Control
101         pHTInfo->bRegRxReorderEnable = 1;//YJ,test,090311
102         pHTInfo->RxReorderWinSize = 64;
103         pHTInfo->RxReorderPendingTime = 30;
104
105
106
107 }
108 /********************************************************************************************************************
109  *function:  This function print out each field on HT capability IE mainly from (Beacon/ProbeRsp/AssocReq)
110  *   input:  u8*        CapIE       //Capability IE to be printed out
111  *           u8*        TitleString //mainly print out caller function
112  *  output:  none
113  *  return:  none
114  *  notice:  Driver should not print out this message by default.
115  * *****************************************************************************************************************/
116 void HTDebugHTCapability(u8* CapIE, u8* TitleString )
117 {
118
119         static u8       EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};       // For 11n EWC definition, 2007.07.17, by Emily
120         PHT_CAPABILITY_ELE              pCapELE;
121
122         if(!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap)))
123         {
124                 //EWC IE
125                 IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __FUNCTION__);
126                 pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[4]);
127         }else
128                 pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[0]);
129
130         IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Capability>. Called by %s\n", TitleString );
131
132         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupported Channel Width = %s\n", (pCapELE->ChlWidth)?"20MHz": "20/40MHz");
133         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport Short GI for 20M = %s\n", (pCapELE->ShortGI20Mhz)?"YES": "NO");
134         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport Short GI for 40M = %s\n", (pCapELE->ShortGI40Mhz)?"YES": "NO");
135         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport TX STBC = %s\n", (pCapELE->TxSTBC)?"YES": "NO");
136         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMax AMSDU Size = %s\n", (pCapELE->MaxAMSDUSize)?"3839": "7935");
137         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport CCK in 20/40 mode = %s\n", (pCapELE->DssCCk)?"YES": "NO");
138         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMax AMPDU Factor = %d\n", pCapELE->MaxRxAMPDUFactor);
139         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMPDU Density = %d\n", pCapELE->MPDUDensity);
140         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMCS Rate Set = [%x][%x][%x][%x][%x]\n", pCapELE->MCS[0],\
141                                 pCapELE->MCS[1], pCapELE->MCS[2], pCapELE->MCS[3], pCapELE->MCS[4]);
142         return;
143
144 }
145 /********************************************************************************************************************
146  *function:  This function print out each field on HT Information IE mainly from (Beacon/ProbeRsp)
147  *   input:  u8*        InfoIE       //Capability IE to be printed out
148  *           u8*        TitleString //mainly print out caller function
149  *  output:  none
150  *  return:  none
151  *  notice:  Driver should not print out this message by default.
152  * *****************************************************************************************************************/
153 void HTDebugHTInfo(u8*  InfoIE, u8* TitleString)
154 {
155
156         static u8       EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};      // For 11n EWC definition, 2007.07.17, by Emily
157         PHT_INFORMATION_ELE             pHTInfoEle;
158
159         if(!memcmp(InfoIE, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
160         {
161                 // Not EWC IE
162                 IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __FUNCTION__);
163                 pHTInfoEle = (PHT_INFORMATION_ELE)(&InfoIE[4]);
164         }else
165                 pHTInfoEle = (PHT_INFORMATION_ELE)(&InfoIE[0]);
166
167
168         IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Information Element>. Called by %s\n", TitleString);
169
170         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tPrimary channel = %d\n", pHTInfoEle->ControlChl);
171         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tSenondary channel =");
172         switch(pHTInfoEle->ExtChlOffset)
173         {
174                 case 0:
175                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Not Present\n");
176                         break;
177                 case 1:
178                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Upper channel\n");
179                         break;
180                 case 2:
181                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Reserved. Eooro!!!\n");
182                         break;
183                 case 3:
184                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Lower Channel\n");
185                         break;
186         }
187         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tRecommended channel width = %s\n", (pHTInfoEle->RecommemdedTxWidth)?"20Mhz": "40Mhz");
188
189         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tOperation mode for protection = ");
190         switch(pHTInfoEle->OptMode)
191         {
192                 case 0:
193                         IEEE80211_DEBUG(IEEE80211_DL_HT, "No Protection\n");
194                         break;
195                 case 1:
196                         IEEE80211_DEBUG(IEEE80211_DL_HT, "HT non-member protection mode\n");
197                         break;
198                 case 2:
199                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Suggest to open protection\n");
200                         break;
201                 case 3:
202                         IEEE80211_DEBUG(IEEE80211_DL_HT, "HT mixed mode\n");
203                         break;
204         }
205
206         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tBasic MCS Rate Set = [%x][%x][%x][%x][%x]\n", pHTInfoEle->BasicMSC[0],\
207                                 pHTInfoEle->BasicMSC[1], pHTInfoEle->BasicMSC[2], pHTInfoEle->BasicMSC[3], pHTInfoEle->BasicMSC[4]);
208         return;
209 }
210
211 /*
212 *       Return:         true if station in half n mode and AP supports 40 bw
213 */
214 bool IsHTHalfNmode40Bandwidth(struct ieee80211_device* ieee)
215 {
216         bool                    retValue = false;
217         PRT_HIGH_THROUGHPUT      pHTInfo = ieee->pHTInfo;
218
219         if(pHTInfo->bCurrentHTSupport == false )        // wireless is n mode
220                 retValue = false;
221         else if(pHTInfo->bRegBW40MHz == false)  // station supports 40 bw
222                 retValue = false;
223         else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))      // station in half n mode
224                 retValue = false;
225         else if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw
226                 retValue = true;
227         else
228                 retValue = false;
229
230         return retValue;
231 }
232
233 bool IsHTHalfNmodeSGI(struct ieee80211_device* ieee, bool is40MHz)
234 {
235         bool                    retValue = false;
236         PRT_HIGH_THROUGHPUT      pHTInfo = ieee->pHTInfo;
237
238         if(pHTInfo->bCurrentHTSupport == false )        // wireless is n mode
239                 retValue = false;
240         else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))      // station in half n mode
241                 retValue = false;
242         else if(is40MHz) // ap support 40 bw
243         {
244                 if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI40Mhz) // ap support 40 bw short GI
245                         retValue = true;
246                 else
247                         retValue = false;
248         }
249         else
250         {
251                 if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI20Mhz) // ap support 40 bw short GI
252                         retValue = true;
253                 else
254                         retValue = false;
255         }
256
257         return retValue;
258 }
259
260 u16 HTHalfMcsToDataRate(struct ieee80211_device* ieee,  u8      nMcsRate)
261 {
262
263         u8      is40MHz;
264         u8      isShortGI;
265
266         is40MHz  =  (IsHTHalfNmode40Bandwidth(ieee))?1:0;
267         isShortGI = (IsHTHalfNmodeSGI(ieee, is40MHz))? 1:0;
268
269         return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate&0x7f)];
270 }
271
272
273 u16 HTMcsToDataRate( struct ieee80211_device* ieee, u8 nMcsRate)
274 {
275         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
276
277         u8      is40MHz = (pHTInfo->bCurBW40MHz)?1:0;
278         u8      isShortGI = (pHTInfo->bCurBW40MHz)?
279                                                 ((pHTInfo->bCurShortGI40MHz)?1:0):
280                                                 ((pHTInfo->bCurShortGI20MHz)?1:0);
281         return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate&0x7f)];
282 }
283
284 /********************************************************************************************************************
285  *function:  This function returns current datarate.
286  *   input:  struct ieee80211_device*   ieee
287  *           u8                         nDataRate
288  *  output:  none
289  *  return:  tx rate
290  *  notice:  quite unsure about how to use this function //wb
291  * *****************************************************************************************************************/
292 u16  TxCountToDataRate( struct ieee80211_device* ieee, u8 nDataRate)
293 {
294         //PRT_HIGH_THROUGHPUT   pHTInfo = ieee->pHTInfo;
295         u16             CCKOFDMRate[12] = {0x02 , 0x04 , 0x0b , 0x16 , 0x0c , 0x12 , 0x18 , 0x24 , 0x30 , 0x48 , 0x60 , 0x6c};
296         u8      is40MHz = 0;
297         u8      isShortGI = 0;
298
299         if(nDataRate < 12)
300         {
301                 return CCKOFDMRate[nDataRate];
302         }
303         else
304         {
305                 if (nDataRate >= 0x10 && nDataRate <= 0x1f)//if(nDataRate > 11 && nDataRate < 28 )
306                 {
307                         is40MHz = 0;
308                         isShortGI = 0;
309
310                       // nDataRate = nDataRate - 12;
311                 }
312                 else if(nDataRate >=0x20  && nDataRate <= 0x2f ) //(27, 44)
313                 {
314                         is40MHz = 1;
315                         isShortGI = 0;
316
317                         //nDataRate = nDataRate - 28;
318                 }
319                 else if(nDataRate >= 0x30  && nDataRate <= 0x3f )  //(43, 60)
320                 {
321                         is40MHz = 0;
322                         isShortGI = 1;
323
324                         //nDataRate = nDataRate - 44;
325                 }
326                 else if(nDataRate >= 0x40  && nDataRate <= 0x4f ) //(59, 76)
327                 {
328                         is40MHz = 1;
329                         isShortGI = 1;
330
331                         //nDataRate = nDataRate - 60;
332                 }
333                 return MCS_DATA_RATE[is40MHz][isShortGI][nDataRate&0xf];
334         }
335 }
336
337
338
339 bool IsHTHalfNmodeAPs(struct ieee80211_device* ieee)
340 {
341         bool                    retValue = false;
342         struct ieee80211_network* net = &ieee->current_network;
343 #if 0
344         if(pMgntInfo->bHalfNMode == false)
345                 retValue = false;
346         else
347 #endif
348         if((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3)==0) ||
349                      (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3)==0) ||
350                      (memcmp(net->bssid, PCI_RALINK, 3)==0) ||
351                      (memcmp(net->bssid, EDIMAX_RALINK, 3)==0) ||
352                      (memcmp(net->bssid, AIRLINK_RALINK, 3)==0) ||
353                      (net->ralink_cap_exist))
354                 retValue = true;
355         else if((memcmp(net->bssid, UNKNOWN_BORADCOM, 3)==0) ||
356                     (memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
357                     (memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
358                     (memcmp(net->bssid, NETGEAR834Bv2_BROADCOM, 3)==0) ||
359                     (net->broadcom_cap_exist))
360                   retValue = true;
361         else if(net->bssht.bdRT2RTAggregation)
362                 retValue = true;
363         else
364                 retValue = false;
365
366         return retValue;
367 }
368
369 /********************************************************************************************************************
370  *function:  This function returns peer IOT.
371  *   input:  struct ieee80211_device*   ieee
372  *  output:  none
373  *  return:
374  *  notice:
375  * *****************************************************************************************************************/
376 void HTIOTPeerDetermine(struct ieee80211_device* ieee)
377 {
378         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
379         struct ieee80211_network* net = &ieee->current_network;
380         //FIXME: need to decide  92U_SOFTAP //LZM,090320
381         if(net->bssht.bdRT2RTAggregation){
382                 pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK;
383                 if(net->bssht.RT2RT_HT_Mode & RT_HT_CAP_USE_92SE){
384                         pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK_92SE;
385                 }
386         }
387         else if(net->broadcom_cap_exist)
388                 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
389         else if((memcmp(net->bssid, UNKNOWN_BORADCOM, 3)==0) ||
390                         (memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
391                         (memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
392                         (memcmp(net->bssid, NETGEAR834Bv2_BROADCOM, 3)==0) )
393                 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
394         else if((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3)==0) ||
395                         (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3)==0) ||
396                         (memcmp(net->bssid, PCI_RALINK, 3)==0) ||
397                         (memcmp(net->bssid, EDIMAX_RALINK, 3)==0) ||
398                         (memcmp(net->bssid, AIRLINK_RALINK, 3)==0) ||
399                          net->ralink_cap_exist)
400                 pHTInfo->IOTPeer = HT_IOT_PEER_RALINK;
401         else if((net->atheros_cap_exist )||
402                 (memcmp(net->bssid, DLINK_ATHEROS_1, 3) == 0)||
403                 (memcmp(net->bssid, DLINK_ATHEROS_2, 3) == 0))
404                 pHTInfo->IOTPeer = HT_IOT_PEER_ATHEROS;
405         else if(memcmp(net->bssid, CISCO_BROADCOM, 3)==0)
406                 pHTInfo->IOTPeer = HT_IOT_PEER_CISCO;
407         else if ((memcmp(net->bssid, LINKSYS_MARVELL_4400N, 3) == 0) ||
408                   net->marvell_cap_exist)
409                 pHTInfo->IOTPeer = HT_IOT_PEER_MARVELL;
410         else
411                 pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
412
413         IEEE80211_DEBUG(IEEE80211_DL_IOT, "Joseph debug!! IOTPEER: %x\n", pHTInfo->IOTPeer);
414 }
415 /********************************************************************************************************************
416  *function:  Check whether driver should declare received rate up to MCS13 only since some chipset is not good
417  *           at receiving MCS14~15 frame from some AP.
418  *   input:  struct ieee80211_device*   ieee
419  *           u8 *                       PeerMacAddr
420  *  output:  none
421  *  return:  return 1 if driver should declare MCS13 only(otherwise return 0)
422   * *****************************************************************************************************************/
423 u8 HTIOTActIsDisableMCS14(struct ieee80211_device* ieee, u8* PeerMacAddr)
424 {
425         u8 ret = 0;
426 #if 0
427         // Apply for 819u only
428 #if (HAL_CODE_BASE==RTL8192 && DEV_BUS_TYPE==USB_INTERFACE)
429         if((memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0) ||
430                 (memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)
431             )
432         {
433                 ret = 1;
434         }
435
436
437         if(pHTInfo->bCurrentRT2RTAggregation)
438         {
439                 // The parameter of pHTInfo->bCurrentRT2RTAggregation must be decided previously
440                 ret = 1;
441         }
442 #endif
443 #endif
444         return ret;
445  }
446
447
448 /**
449 * Function:     HTIOTActIsDisableMCS15
450 *
451 * Overview:     Check whether driver should declare capability of receving MCS15
452 *
453 * Input:
454 *                       PADAPTER                Adapter,
455 *
456 * Output:               None
457 * Return:       true if driver should disable MCS15
458 * 2008.04.15    Emily
459 */
460 bool HTIOTActIsDisableMCS15(struct ieee80211_device* ieee)
461 {
462         bool retValue = false;
463
464 #ifdef TODO
465         // Apply for 819u only
466 #if (HAL_CODE_BASE==RTL8192)
467
468 #if (DEV_BUS_TYPE == USB_INTERFACE)
469         // Alway disable MCS15 by Jerry Chang's request.by Emily, 2008.04.15
470         retValue = true;
471 #elif (DEV_BUS_TYPE == PCI_INTERFACE)
472         // Enable MCS15 if the peer is Cisco AP. by Emily, 2008.05.12
473 //      if(pBssDesc->bCiscoCapExist)
474 //              retValue = false;
475 //      else
476                 retValue = false;
477 #endif
478 #endif
479 #endif
480         // Jerry Chang suggest that 8190 1x2 does not need to disable MCS15
481
482         return retValue;
483 }
484
485 /**
486 * Function:     HTIOTActIsDisableMCSTwoSpatialStream
487 *
488 * Overview:     Check whether driver should declare capability of receving All 2 ss packets
489 *
490 * Input:
491 *               PADAPTER                Adapter,
492 *
493 * Output:       None
494 * Return:       true if driver should disable all two spatial stream packet
495 * 2008.04.21    Emily
496 */
497 bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee)
498 {
499         bool retValue = false;
500 #ifdef TODO
501         // Apply for 819u only
502 //#if (HAL_CODE_BASE==RTL8192)
503
504         //This rule only apply to Belkin(Ralink) AP
505         if(IS_UNDER_11N_AES_MODE(Adapter))
506         {
507                 if((PlatformCompareMemory(PeerMacAddr, BELKINF5D8233V1_RALINK, 3)==0) ||
508                                 (PlatformCompareMemory(PeerMacAddr, PCI_RALINK, 3)==0) ||
509                                 (PlatformCompareMemory(PeerMacAddr, EDIMAX_RALINK, 3)==0))
510                 {
511                         //Set True to disable this function. Disable by default, Emily, 2008.04.23
512                         retValue = false;
513                 }
514         }
515
516 //#endif
517 #endif
518 #if 1
519 #if (defined(RTL8192SE) || (defined(RTL8192SU)))
520        PRT_HIGH_THROUGHPUT      pHTInfo = ieee->pHTInfo;
521         if(ieee->is_ap_in_wep_tkip && ieee->is_ap_in_wep_tkip(ieee->dev))
522         {
523                 if( (pHTInfo->IOTPeer != HT_IOT_PEER_ATHEROS) &&
524                     (pHTInfo->IOTPeer != HT_IOT_PEER_UNKNOWN) &&
525                     (pHTInfo->IOTPeer != HT_IOT_PEER_MARVELL) )
526                         retValue = true;
527         }
528 #endif
529 #endif
530         return retValue;
531 }
532
533 /********************************************************************************************************************
534  *function:  Check whether driver should disable EDCA turbo mode
535  *   input:  struct ieee80211_device*   ieee
536  *           u8*                        PeerMacAddr
537  *  output:  none
538  *  return:  return 1 if driver should disable EDCA turbo mode(otherwise return 0)
539   * *****************************************************************************************************************/
540 u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device*  ieee, u8* PeerMacAddr)
541 {
542         u8      retValue = false;       // default enable EDCA Turbo mode.
543         // Set specific EDCA parameter for different AP in DM handler.
544
545         return retValue;
546 #if 0
547         if((memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0)||
548                 (memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
549                 (memcmp(PeerMacAddr, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
550                 (memcmp(PeerMacAddr, NETGEAR834Bv2_BROADCOM, 3)==0))
551
552         {
553                 retValue = 1;   //Linksys disable EDCA turbo mode
554         }
555
556         return retValue;
557 #endif
558 }
559
560 /********************************************************************************************************************
561  *function:  Check whether we need to use OFDM to sned MGNT frame for broadcom AP
562  *   input:  struct ieee80211_network *network   //current network we live
563  *  output:  none
564  *  return:  return 1 if true
565   * *****************************************************************************************************************/
566 u8 HTIOTActIsMgntUseCCK6M(struct ieee80211_network *network)
567 {
568         u8      retValue = 0;
569
570         // 2008/01/25 MH Judeg if we need to use OFDM to sned MGNT frame for broadcom AP.
571         // 2008/01/28 MH We must prevent that we select null bssid to link.
572
573         if(network->broadcom_cap_exist)
574         {
575                 retValue = 1;
576         }
577
578         return retValue;
579 }
580
581 u8 HTIOTActIsForcedCTS2Self(struct ieee80211_network *network)
582 {
583         u8      retValue = 0;
584
585         if(network->marvell_cap_exist)
586         {
587                 retValue = 1;
588         }
589
590         return retValue;
591 }
592
593 u8 HTIOTActIsForcedRTSCTS(struct ieee80211_device *ieee, struct ieee80211_network *network)
594 {
595         u8      retValue = 0;
596         printk("============>%s(), %d\n", __FUNCTION__, network->realtek_cap_exit);
597         // Force protection
598 #if defined(RTL8192SE) || defined(RTL8192SU)
599         if(ieee->pHTInfo->bCurrentHTSupport)
600         {
601                 //if(!network->realtek_cap_exit)
602                 if((ieee->pHTInfo->IOTPeer != HT_IOT_PEER_REALTEK)&&
603                    (ieee->pHTInfo->IOTPeer != HT_IOT_PEER_REALTEK_92SE))
604         {
605                         if((ieee->pHTInfo->IOTAction & HT_IOT_ACT_TX_NO_AGGREGATION) == 0)
606                                 retValue = 1;
607                 }
608         }
609 #endif
610         return retValue;
611 }
612
613 u8
614 HTIOTActIsForcedAMSDU8K(struct ieee80211_device *ieee, struct ieee80211_network *network)
615 {
616         u8 retValue = 0;
617
618         return retValue;
619 }
620
621 u8 HTIOTActIsCCDFsync(u8* PeerMacAddr)
622 {
623         u8      retValue = 0;
624 #ifndef RTL8192SE
625         if(     (memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0) ||
626                 (memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0) ||
627                 (memcmp(PeerMacAddr, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) ==0))
628         {
629                 retValue = 1;
630         }
631 #endif
632         return retValue;
633 }
634
635 /*
636   *  819xS single chip b-cut series cannot handle BAR
637   */
638 u8
639 HTIOCActRejcectADDBARequest(struct ieee80211_network *network)
640 {
641         u8      retValue = 0;
642         //if(IS_HARDWARE_TYPE_8192SE(Adapter) ||
643         //      IS_HARDWARE_TYPE_8192SU(Adapter)
644         //)
645 #if (defined RTL8192SE || defined RTL8192SU)
646         {
647                 // Do not reject ADDBA REQ because some of the AP may
648                 // keep on sending ADDBA REQ qhich cause DHCP fail or ping loss!
649                 // by HPFan, 2008/12/30
650
651                 //if(pBssDesc->Vender == HT_IOT_PEER_MARVELL)
652                 //      return FALSE;
653
654         }
655 #endif
656
657         return retValue;
658
659 }
660
661 /*
662   *  EDCA parameters bias on downlink
663   */
664   u8
665   HTIOTActIsEDCABiasRx(struct ieee80211_device* ieee,struct ieee80211_network *network)
666 {
667         u8      retValue = 0;
668         //if(IS_HARDWARE_TYPE_8192SU(Adapter))
669 #ifdef RTL8192SU
670         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
671         {
672 //#if UNDER_VISTA
673 //              if(pBssDesc->Vender==HT_IOT_PEER_ATHEROS ||
674 //                      pBssDesc->Vender==HT_IOT_PEER_RALINK)
675 //#else
676                 if(pHTInfo->IOTPeer==HT_IOT_PEER_ATHEROS ||
677                    pHTInfo->IOTPeer==HT_IOT_PEER_BROADCOM ||
678                    pHTInfo->IOTPeer==HT_IOT_PEER_RALINK)
679 //#endif
680                         return 1;
681
682         }
683 #endif
684         return retValue;
685 }
686
687 u8
688 HTIOTActDisableShortGI(struct ieee80211_device* ieee,struct ieee80211_network *network)
689 {
690         u8      retValue = 0;
691         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
692
693         if(pHTInfo->IOTPeer==HT_IOT_PEER_RALINK)
694         {
695                 if(network->bssht.bdHT1R)
696                         retValue = 1;
697         }
698
699         return retValue;
700 }
701
702 u8
703 HTIOTActDisableHighPower(struct ieee80211_device* ieee,struct ieee80211_network *network)
704 {
705         u8      retValue = 0;
706         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
707
708         if(pHTInfo->IOTPeer==HT_IOT_PEER_RALINK)
709         {
710                 if(network->bssht.bdHT1R)
711                         retValue = 1;
712         }
713
714         return retValue;
715 }
716
717 void
718 HTIOTActDetermineRaFunc(struct ieee80211_device* ieee,  bool    bPeerRx2ss)
719 {
720         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
721         pHTInfo->IOTRaFunc &= HT_IOT_RAFUNC_DISABLE_ALL;
722
723         if(pHTInfo->IOTPeer == HT_IOT_PEER_RALINK && !bPeerRx2ss)
724                 pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_PEER_1R;
725
726         if(pHTInfo->IOTAction & HT_IOT_ACT_AMSDU_ENABLE)
727                 pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_TX_AMSDU;
728
729         printk("!!!!!!!!!!!!!!!!!!!!!!!!!!!IOTRaFunc = %8.8x\n", pHTInfo->IOTRaFunc);
730 }
731
732
733 u8
734 HTIOTActIsDisableTx40MHz(struct ieee80211_device* ieee,struct ieee80211_network *network)
735 {
736         u8      retValue = 0;
737
738 #if (defined RTL8192SU || defined RTL8192SE)
739         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
740         if(     (KEY_TYPE_WEP104 == ieee->pairwise_key_type) ||
741                 (KEY_TYPE_WEP40 == ieee->pairwise_key_type) ||
742                 (KEY_TYPE_WEP104 == ieee->group_key_type) ||
743                 (KEY_TYPE_WEP40 == ieee->group_key_type) ||
744                 (KEY_TYPE_TKIP == ieee->pairwise_key_type) )
745         {
746                 if((pHTInfo->IOTPeer==HT_IOT_PEER_REALTEK) && (network->bssht.bdSupportHT))
747                         retValue = 1;
748         }
749 #endif
750
751         return retValue;
752 }
753
754 u8
755 HTIOTActIsTxNoAggregation(struct ieee80211_device* ieee,struct ieee80211_network *network)
756 {
757         u8 retValue = 0;
758
759 #if (defined RTL8192SU || defined RTL8192SE)
760         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
761         if(     (KEY_TYPE_WEP104 == ieee->pairwise_key_type) ||
762                 (KEY_TYPE_WEP40 == ieee->pairwise_key_type) ||
763                 (KEY_TYPE_WEP104 == ieee->group_key_type) ||
764                 (KEY_TYPE_WEP40 == ieee->group_key_type) ||
765                 (KEY_TYPE_TKIP == ieee->pairwise_key_type) )
766         {
767                 if(pHTInfo->IOTPeer==HT_IOT_PEER_REALTEK ||
768                     pHTInfo->IOTPeer==HT_IOT_PEER_UNKNOWN)
769                         retValue = 1;
770         }
771 #endif
772
773         return retValue;
774 }
775
776
777 u8
778 HTIOTActIsDisableTx2SS(struct ieee80211_device* ieee,struct ieee80211_network *network)
779 {
780         u8      retValue = 0;
781
782 #if (defined RTL8192SU || defined RTL8192SE)
783         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
784         if(     (KEY_TYPE_WEP104 == ieee->pairwise_key_type) ||
785                 (KEY_TYPE_WEP40 == ieee->pairwise_key_type) ||
786                 (KEY_TYPE_WEP104 == ieee->group_key_type) ||
787                 (KEY_TYPE_WEP40 == ieee->group_key_type) ||
788                 (KEY_TYPE_TKIP == ieee->pairwise_key_type) )
789         {
790                 if((pHTInfo->IOTPeer==HT_IOT_PEER_REALTEK) && (network->bssht.bdSupportHT))
791                         retValue = 1;
792         }
793 #endif
794
795         return retValue;
796 }
797
798
799 bool HTIOCActAllowPeerAggOnePacket(struct ieee80211_device* ieee,struct ieee80211_network *network)
800 {
801         bool    retValue = false;
802 #if defined(RTL8192SE) || defined(RTL8192SU)
803         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
804         {
805                 if(pHTInfo->IOTPeer == HT_IOT_PEER_MARVELL)
806                         return true;
807
808         }
809 #endif
810         return retValue;
811 }
812
813 void HTResetIOTSetting(
814         PRT_HIGH_THROUGHPUT             pHTInfo
815 )
816 {
817         pHTInfo->IOTAction = 0;
818         pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
819         pHTInfo->IOTRaFunc = 0;
820 }
821
822
823 /********************************************************************************************************************
824  *function:  Construct Capablility Element in Beacon... if HTEnable is turned on
825  *   input:  struct ieee80211_device*   ieee
826  *           u8*                        posHTCap //pointer to store Capability Ele
827  *           u8*                        len //store length of CE
828  *           u8                         IsEncrypt //whether encrypt, needed further
829  *  output:  none
830  *  return:  none
831  *  notice:  posHTCap can't be null and should be initialized before.
832   * *****************************************************************************************************************/
833 void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u8* len, u8 IsEncrypt)
834 {
835         PRT_HIGH_THROUGHPUT     pHT = ieee->pHTInfo;
836         PHT_CAPABILITY_ELE      pCapELE = NULL;
837         //u8 bIsDeclareMCS13;
838
839         if ((posHTCap == NULL) || (pHT == NULL))
840         {
841                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTCap or pHTInfo can't be null in HTConstructCapabilityElement()\n");
842                 return;
843         }
844         memset(posHTCap, 0, *len);
845         if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
846         {
847                 u8      EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};       // For 11n EWC definition, 2007.07.17, by Emily
848                 memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap));
849                 pCapELE = (PHT_CAPABILITY_ELE)&(posHTCap[4]);
850         }else
851         {
852                 pCapELE = (PHT_CAPABILITY_ELE)posHTCap;
853         }
854
855
856         //HT capability info
857         pCapELE->AdvCoding              = 0; // This feature is not supported now!!
858         if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
859         {
860                 pCapELE->ChlWidth = 0;
861         }
862         else
863         {
864                 pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0);
865         }
866
867 //      pCapELE->ChlWidth               = (pHT->bRegBW40MHz?1:0);
868         pCapELE->MimoPwrSave            = pHT->SelfMimoPs;
869         pCapELE->GreenField             = 0; // This feature is not supported now!!
870         pCapELE->ShortGI20Mhz           = 1; // We can receive Short GI!!
871         pCapELE->ShortGI40Mhz           = 1; // We can receive Short GI!!
872         //DbgPrint("TX HT cap/info ele BW=%d SG20=%d SG40=%d\n\r",
873                 //pCapELE->ChlWidth, pCapELE->ShortGI20Mhz, pCapELE->ShortGI40Mhz);
874         pCapELE->TxSTBC                 = 1;
875         pCapELE->RxSTBC                 = 0;
876         pCapELE->DelayBA                = 0;    // Do not support now!!
877         pCapELE->MaxAMSDUSize   = (MAX_RECEIVE_BUFFER_SIZE>=7935)?1:0;
878         pCapELE->DssCCk                 = ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0);
879         pCapELE->PSMP                   = 0; // Do not support now!!
880         pCapELE->LSigTxopProtect        = 0; // Do not support now!!
881
882
883         //MAC HT parameters info
884         // TODO: Nedd to take care of this part
885         IEEE80211_DEBUG(IEEE80211_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk);
886
887         if( IsEncrypt)
888         {
889                 pCapELE->MPDUDensity    = 7; // 8us
890                 pCapELE->MaxRxAMPDUFactor       = 2; // 2 is for 32 K and 3 is 64K
891         }
892         else
893         {
894                 pCapELE->MaxRxAMPDUFactor       = 3; // 2 is for 32 K and 3 is 64K
895                 pCapELE->MPDUDensity    = 0; // no density
896         }
897
898         //Supported MCS set
899         memcpy(pCapELE->MCS, ieee->Regdot11HTOperationalRateSet, 16);
900         if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS15)
901                 pCapELE->MCS[1] &= 0x7f;
902
903         if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS14)
904                 pCapELE->MCS[1] &= 0xbf;
905
906         if(pHT->IOTAction & HT_IOT_ACT_DISABLE_ALL_2SS)
907                 pCapELE->MCS[1] &= 0x00;
908
909         // 2008.06.12
910         // For RTL819X, if pairwisekey = wep/tkip, ap is ralink, we support only MCS0~7.
911         if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
912         {
913                 int i;
914                 for(i = 1; i< 16; i++)
915                         pCapELE->MCS[i] = 0;
916         }
917
918         //Extended HT Capability Info
919         memset(&pCapELE->ExtHTCapInfo, 0, 2);
920
921
922         //TXBF Capabilities
923         memset(pCapELE->TxBFCap, 0, 4);
924
925         //Antenna Selection Capabilities
926         pCapELE->ASCap = 0;
927 //add 2 to give space for element ID and len when construct frames
928         if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
929                 *len = 30 + 2;
930         else
931                 *len = 26 + 2;
932
933
934
935 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTCap, *len -2);
936
937         //Print each field in detail. Driver should not print out this message by default
938 //      HTDebugHTCapability(posHTCap, (u8*)"HTConstructCapability()");
939         return;
940
941 }
942 /********************************************************************************************************************
943  *function:  Construct  Information Element in Beacon... if HTEnable is turned on
944  *   input:  struct ieee80211_device*   ieee
945  *           u8*                        posHTCap //pointer to store Information Ele
946  *           u8*                        len   //store len of
947  *           u8                         IsEncrypt //whether encrypt, needed further
948  *  output:  none
949  *  return:  none
950  *  notice:  posHTCap can't be null and be initialized before. only AP and IBSS sta should do this
951   * *****************************************************************************************************************/
952 void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* len, u8 IsEncrypt)
953 {
954         PRT_HIGH_THROUGHPUT     pHT = ieee->pHTInfo;
955         PHT_INFORMATION_ELE             pHTInfoEle = (PHT_INFORMATION_ELE)posHTInfo;
956         if ((posHTInfo == NULL) || (pHTInfoEle == NULL))
957         {
958                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTInfo or pHTInfoEle can't be null in HTConstructInfoElement()\n");
959                 return;
960         }
961
962         memset(posHTInfo, 0, *len);
963         if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported
964         {
965                 pHTInfoEle->ControlChl                  = ieee->current_network.channel;
966                 pHTInfoEle->ExtChlOffset                        = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT:
967                                                                                         (ieee->current_network.channel<=6)?
968                                                                                                 HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER);
969                 pHTInfoEle->RecommemdedTxWidth  = pHT->bRegBW40MHz;
970                 pHTInfoEle->RIFS                                        = 0;
971                 pHTInfoEle->PSMPAccessOnly              = 0;
972                 pHTInfoEle->SrvIntGranularity           = 0;
973                 pHTInfoEle->OptMode                             = pHT->CurrentOpMode;
974                 pHTInfoEle->NonGFDevPresent             = 0;
975                 pHTInfoEle->DualBeacon                  = 0;
976                 pHTInfoEle->SecondaryBeacon             = 0;
977                 pHTInfoEle->LSigTxopProtectFull         = 0;
978                 pHTInfoEle->PcoActive                           = 0;
979                 pHTInfoEle->PcoPhase                            = 0;
980
981                 memset(pHTInfoEle->BasicMSC, 0, 16);
982
983
984                 *len = 22 + 2; //same above
985
986         }
987         else
988         {
989                 //STA should not generate High Throughput Information Element
990                 *len = 0;
991         }
992         //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTInfo, *len - 2);
993         //HTDebugHTInfo(posHTInfo, "HTConstructInforElement");
994         return;
995 }
996
997 /*
998   *  According to experiment, Realtek AP to STA (based on rtl8190) may achieve best performance
999   *  if both STA and AP set limitation of aggregation size to 32K, that is, set AMPDU density to 2
1000   *  (Ref: IEEE 11n specification). However, if Realtek STA associates to other AP, STA should set
1001   *  limitation of aggregation size to 8K, otherwise, performance of traffic stream from STA to AP
1002   *  will be much less than the traffic stream from AP to STA if both of the stream runs concurrently
1003   *  at the same time.
1004   *
1005   *  Frame Format
1006   *  Element ID         Length          OUI                     Type1           Reserved
1007   *  1 byte                     1 byte          3 bytes         1 byte          1 byte
1008   *
1009   *  OUI                = 0x00, 0xe0, 0x4c,
1010   *  Type       = 0x02
1011   *  Reserved   = 0x00
1012   *
1013   *  2007.8.21 by Emily
1014 */
1015 /********************************************************************************************************************
1016  *function:  Construct  Information Element in Beacon... in RT2RT condition
1017  *   input:  struct ieee80211_device*   ieee
1018  *           u8*                        posRT2RTAgg //pointer to store Information Ele
1019  *           u8*                        len   //store len
1020  *  output:  none
1021  *  return:  none
1022  *  notice:
1023   * *****************************************************************************************************************/
1024 void HTConstructRT2RTAggElement(struct ieee80211_device* ieee, u8* posRT2RTAgg, u8* len)
1025 {
1026         if (posRT2RTAgg == NULL) {
1027                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "posRT2RTAgg can't be null in HTConstructRT2RTAggElement()\n");
1028                 return;
1029         }
1030         memset(posRT2RTAgg, 0, *len);
1031         *posRT2RTAgg++ = 0x00;
1032         *posRT2RTAgg++ = 0xe0;
1033         *posRT2RTAgg++ = 0x4c;
1034         *posRT2RTAgg++ = 0x02;
1035         *posRT2RTAgg++ = 0x01;
1036         *posRT2RTAgg = 0x10;//*posRT2RTAgg = 0x02;
1037
1038         if(ieee->bSupportRemoteWakeUp) {
1039                 *posRT2RTAgg |= 0x08;//RT_HT_CAP_USE_WOW;
1040         }
1041
1042         *len = 6 + 2;
1043         return;
1044 #ifdef TODO
1045 #if(HAL_CODE_BASE == RTL8192 && DEV_BUS_TYPE == USB_INTERFACE)
1046         /*
1047         //Emily. If it is required to Ask Realtek AP to send AMPDU during AES mode, enable this
1048            section of code.
1049         if(IS_UNDER_11N_AES_MODE(Adapter))
1050         {
1051                 posRT2RTAgg->Octet[5] |=RT_HT_CAP_USE_AMPDU;
1052         }else
1053         {
1054                 posRT2RTAgg->Octet[5] &= 0xfb;
1055         }
1056         */
1057
1058 #else
1059         // Do Nothing
1060 #endif
1061
1062         posRT2RTAgg->Length = 6;
1063 #endif
1064
1065
1066
1067
1068 }
1069
1070
1071 /********************************************************************************************************************
1072  *function:  Pick the right Rate Adaptive table to use
1073  *   input:  struct ieee80211_device*   ieee
1074  *           u8*                        pOperateMCS //A pointer to MCS rate bitmap
1075  *  return:  always we return true
1076  *  notice:
1077   * *****************************************************************************************************************/
1078 u8 HT_PickMCSRate(struct ieee80211_device* ieee, u8* pOperateMCS)
1079 {
1080         u8                                      i;
1081         if (pOperateMCS == NULL)
1082         {
1083                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "pOperateMCS can't be null in HT_PickMCSRate()\n");
1084                 return false;
1085         }
1086
1087         switch(ieee->mode)
1088         {
1089         case IEEE_A:
1090         case IEEE_B:
1091         case IEEE_G:
1092                         //legacy rate routine handled at selectedrate
1093
1094                         //no MCS rate
1095                         for(i=0;i<=15;i++){
1096                                 pOperateMCS[i] = 0;
1097                         }
1098                         break;
1099
1100         case IEEE_N_24G:        //assume CCK rate ok
1101         case IEEE_N_5G:
1102                         // Legacy part we only use 6, 5.5,2,1 for N_24G and 6 for N_5G.
1103                         // Legacy part shall be handled at SelectRateSet().
1104
1105                         //HT part
1106                         // TODO: may be different if we have different number of antenna
1107                         pOperateMCS[0] &=RATE_ADPT_1SS_MASK;    //support MCS 0~7
1108                         pOperateMCS[1] &=RATE_ADPT_2SS_MASK;
1109                         pOperateMCS[3] &=RATE_ADPT_MCS32_MASK;
1110                         break;
1111
1112         //should never reach here
1113         default:
1114
1115                         break;
1116
1117         }
1118
1119         return true;
1120 }
1121
1122 /*
1123 *       Description:
1124 *               This function will get the highest speed rate in input MCS set.
1125 *
1126 *       /param  Adapter                 Pionter to Adapter entity
1127 *                       pMCSRateSet             Pointer to MCS rate bitmap
1128 *                       pMCSFilter              Pointer to MCS rate filter
1129 *
1130 *       /return Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter.
1131 *
1132 */
1133 /********************************************************************************************************************
1134  *function:  This function will get the highest speed rate in input MCS set.
1135  *   input:  struct ieee80211_device*   ieee
1136  *           u8*                        pMCSRateSet //Pointer to MCS rate bitmap
1137  *           u8*                        pMCSFilter //Pointer to MCS rate filter
1138  *  return:  Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter
1139  *  notice:
1140   * *****************************************************************************************************************/
1141 u8 HTGetHighestMCSRate(struct ieee80211_device* ieee, u8* pMCSRateSet, u8* pMCSFilter)
1142 {
1143         u8              i, j;
1144         u8              bitMap;
1145         u8              mcsRate = 0;
1146         u8              availableMcsRate[16];
1147         if (pMCSRateSet == NULL || pMCSFilter == NULL)
1148         {
1149                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "pMCSRateSet or pMCSFilter can't be null in HTGetHighestMCSRate()\n");
1150                 return false;
1151         }
1152         for(i=0; i<16; i++)
1153                 availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i];
1154
1155         for(i = 0; i < 16; i++)
1156         {
1157                 if(availableMcsRate[i] != 0)
1158                         break;
1159         }
1160         if(i == 16)
1161                 return false;
1162
1163         for(i = 0; i < 16; i++)
1164         {
1165                 if(availableMcsRate[i] != 0)
1166                 {
1167                         bitMap = availableMcsRate[i];
1168                         for(j = 0; j < 8; j++)
1169                         {
1170                                 if((bitMap%2) != 0)
1171                                 {
1172                                         if(HTMcsToDataRate(ieee, (8*i+j)) > HTMcsToDataRate(ieee, mcsRate))
1173                                                 mcsRate = (8*i+j);
1174                                 }
1175                                 bitMap = bitMap>>1;
1176                         }
1177                 }
1178         }
1179         return (mcsRate|0x80);
1180 }
1181
1182
1183
1184 /*
1185 **
1186 **1.Filter our operation rate set with AP's rate set
1187 **2.shall reference channel bandwidth, STBC, Antenna number
1188 **3.generate rate adative table for firmware
1189 **David 20060906
1190 **
1191 ** \pHTSupportedCap: the connected STA's supported rate Capability element
1192 */
1193 u8 HTFilterMCSRate( struct ieee80211_device* ieee, u8* pSupportMCS, u8* pOperateMCS)
1194 {
1195
1196         u8 i=0;
1197
1198         // filter out operational rate set not supported by AP, the lenth of it is 16
1199         for(i=0;i<=15;i++){
1200                 pOperateMCS[i] = ieee->Regdot11HTOperationalRateSet[i]&pSupportMCS[i];
1201         }
1202
1203
1204         // TODO: adjust our operational rate set  according to our channel bandwidth, STBC and Antenna number
1205
1206         // TODO: fill suggested rate adaptive rate index and give firmware info using Tx command packet
1207         // we also shall suggested the first start rate set according to our singal strength
1208         HT_PickMCSRate(ieee, pOperateMCS);
1209
1210         // For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
1211         if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
1212                 pOperateMCS[1] = 0;
1213
1214         //
1215         // For RTL819X, we support only MCS0~15.
1216         // And also, we do not know how to use MCS32 now.
1217         //
1218         for(i=2; i<=15; i++)
1219                 pOperateMCS[i] = 0;
1220
1221         return true;
1222 }
1223 void HTSetConnectBwMode(struct ieee80211_device* ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset);
1224 #if 0
1225 //I need move this function to other places, such as rx?
1226 void HTOnAssocRsp_wq(struct work_struct *work)
1227 {
1228         struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, ht_onAssRsp);
1229 #endif
1230 void HTOnAssocRsp(struct ieee80211_device *ieee)
1231 {
1232         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
1233         PHT_CAPABILITY_ELE              pPeerHTCap = NULL;
1234         PHT_INFORMATION_ELE             pPeerHTInfo = NULL;
1235         u16     nMaxAMSDUSize = 0;
1236         u8*     pMcsFilter = NULL;
1237
1238         static u8                               EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};               // For 11n EWC definition, 2007.07.17, by Emily
1239         static u8                               EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};      // For 11n EWC definition, 2007.07.17, by Emily
1240
1241         if( pHTInfo->bCurrentHTSupport == false )
1242         {
1243                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n");
1244                 return;
1245         }
1246         IEEE80211_DEBUG(IEEE80211_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n");
1247 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(HT_CAPABILITY_ELE));
1248 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTInfoBuf, sizeof(HT_INFORMATION_ELE));
1249
1250 //      HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq");
1251 //      HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq");
1252         //
1253         if(!memcmp(pHTInfo->PeerHTCapBuf,EWC11NHTCap, sizeof(EWC11NHTCap)))
1254                 pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]);
1255         else
1256                 pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf);
1257
1258         if(!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
1259                 pPeerHTInfo = (PHT_INFORMATION_ELE)(&pHTInfo->PeerHTInfoBuf[4]);
1260         else
1261                 pPeerHTInfo = (PHT_INFORMATION_ELE)(pHTInfo->PeerHTInfoBuf);
1262
1263
1264         ////////////////////////////////////////////////////////
1265         // Configurations:
1266         ////////////////////////////////////////////////////////
1267         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTCap, sizeof(HT_CAPABILITY_ELE));
1268 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTInfo, sizeof(HT_INFORMATION_ELE));
1269         // Config Supported Channel Width setting
1270         //
1271         HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));
1272
1273 //      if(pHTInfo->bCurBW40MHz == true)
1274                 pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false);
1275
1276         //
1277         // Update short GI/ long GI setting
1278         //
1279         // TODO:
1280         pHTInfo->bCurShortGI20MHz=
1281                 ((pHTInfo->bRegShortGI20MHz)?((pPeerHTCap->ShortGI20Mhz==1)?true:false):false);
1282         pHTInfo->bCurShortGI40MHz=
1283                 ((pHTInfo->bRegShortGI40MHz)?((pPeerHTCap->ShortGI40Mhz==1)?true:false):false);
1284
1285         //
1286         // Config TX STBC setting
1287         //
1288         // TODO:
1289
1290         //
1291         // Config DSSS/CCK  mode in 40MHz mode
1292         //
1293         // TODO:
1294         pHTInfo->bCurSuppCCK =
1295                 ((pHTInfo->bRegSuppCCK)?((pPeerHTCap->DssCCk==1)?true:false):false);
1296
1297
1298         //
1299         // Config and configure A-MSDU setting
1300         //
1301         pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
1302
1303         nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize==0)?3839:7935;
1304
1305         if(pHTInfo->nAMSDU_MaxSize > nMaxAMSDUSize )
1306                 pHTInfo->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize;
1307         else
1308                 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1309
1310         //
1311         // Config A-MPDU setting
1312         //
1313         pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
1314         if(ieee->is_ap_in_wep_tkip && ieee->is_ap_in_wep_tkip(ieee->dev))
1315         {
1316                 if( (pHTInfo->IOTPeer== HT_IOT_PEER_ATHEROS) ||
1317                                 (pHTInfo->IOTPeer == HT_IOT_PEER_UNKNOWN) )
1318                         pHTInfo->bCurrentAMPDUEnable = false;
1319         }
1320
1321         // <1> Decide AMPDU Factor
1322
1323         // By Emily
1324         if(!pHTInfo->bRegRT2RTAggregation)
1325         {
1326                 // Decide AMPDU Factor according to protocol handshake
1327                 if(pHTInfo->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor)
1328                         pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1329                 else
1330                         pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1331
1332         }else
1333         {
1334                 // Set MPDU density to 2 to Realtek AP, and set it to 0 for others
1335                 // Replace MPDU factor declared in original association response frame format. 2007.08.20 by Emily
1336 #if 0
1337                 osTmp= PacketGetElement( asocpdu, EID_Vendor, OUI_SUB_REALTEK_AGG, OUI_SUBTYPE_DONT_CARE);
1338                 if(osTmp.Length >= 5)   //00:e0:4c:02:00
1339 #endif
1340                 if (ieee->current_network.bssht.bdRT2RTAggregation)
1341                 {
1342                         if( ieee->pairwise_key_type != KEY_TYPE_NA)
1343                                 // Realtek may set 32k in security mode and 64k for others
1344                                 pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1345                         else
1346                                 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
1347                 }else
1348                 {
1349                         if(pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K)
1350                                 pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1351                         else
1352                                 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K;
1353                 }
1354         }
1355
1356         // <2> Set AMPDU Minimum MPDU Start Spacing
1357         // 802.11n 3.0 section 9.7d.3
1358 #if 1
1359         if(pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
1360                 pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1361         else
1362                 pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
1363         if(ieee->pairwise_key_type != KEY_TYPE_NA )
1364                 pHTInfo->CurrentMPDUDensity     = 7; // 8us
1365 #else
1366         if(pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
1367                 pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1368         else
1369                 pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
1370 #endif
1371         // Force TX AMSDU
1372
1373         // Lanhsin: mark for tmp to avoid deauth by ap from  s3
1374         //if(memcmp(pMgntInfo->Bssid, NETGEAR834Bv2_BROADCOM, 3)==0)
1375         if(pHTInfo->IOTAction & HT_IOT_ACT_TX_USE_AMSDU_8K)
1376                 {
1377
1378                         pHTInfo->bCurrentAMPDUEnable = false;
1379                         pHTInfo->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE;
1380                         pHTInfo->ForcedAMSDUMaxSize = 7935;
1381         }
1382
1383         // Rx Reorder Setting
1384         pHTInfo->bCurRxReorderEnable = pHTInfo->bRegRxReorderEnable;
1385
1386         //
1387         // Filter out unsupported HT rate for this AP
1388         // Update RATR table
1389         // This is only for 8190 ,8192 or later product which using firmware to handle rate adaptive mechanism.
1390         //
1391
1392         // Handle Ralink AP bad MCS rate set condition. Joseph.
1393         // This fix the bug of Ralink AP. This may be removed in the future.
1394         if(pPeerHTCap->MCS[0] == 0)
1395                 pPeerHTCap->MCS[0] = 0xff;
1396
1397         // Joseph test //LZM ADD 090318
1398         HTIOTActDetermineRaFunc(ieee, ((pPeerHTCap->MCS[1])!=0));
1399
1400         HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11HTOperationalRateSet);
1401
1402         //
1403         // Config MIMO Power Save setting
1404         //
1405         pHTInfo->PeerMimoPs = pPeerHTCap->MimoPwrSave;
1406         if(pHTInfo->PeerMimoPs == MIMO_PS_STATIC)
1407                 pMcsFilter = MCS_FILTER_1SS;
1408         else
1409                 pMcsFilter = MCS_FILTER_ALL;
1410         //WB add for MCS8 bug
1411 //      pMcsFilter = MCS_FILTER_1SS;
1412         ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, pMcsFilter);
1413         ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
1414
1415         //
1416         // Config current operation mode.
1417         //
1418         pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1419
1420
1421
1422 }
1423
1424 void HTSetConnectBwModeCallback(struct ieee80211_device* ieee);
1425 /********************************************************************************************************************
1426  *function:  initialize HT info(struct PRT_HIGH_THROUGHPUT)
1427  *   input:  struct ieee80211_device*   ieee
1428  *  output:  none
1429  *  return:  none
1430  *  notice: This function is called when *  (1) MPInitialization Phase *  (2) Receiving of Deauthentication from AP
1431 ********************************************************************************************************************/
1432 // TODO: Should this funciton be called when receiving of Disassociation?
1433 void HTInitializeHTInfo(struct ieee80211_device* ieee)
1434 {
1435         PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1436
1437         //
1438         // These parameters will be reset when receiving deauthentication packet
1439         //
1440         IEEE80211_DEBUG(IEEE80211_DL_HT, "===========>%s()\n", __FUNCTION__);
1441         pHTInfo->bCurrentHTSupport = false;
1442
1443         // 40MHz channel support
1444         pHTInfo->bCurBW40MHz = false;
1445         pHTInfo->bCurTxBW40MHz = false;
1446
1447         // Short GI support
1448         pHTInfo->bCurShortGI20MHz = false;
1449         pHTInfo->bCurShortGI40MHz = false;
1450         pHTInfo->bForcedShortGI = false;
1451
1452         // CCK rate support
1453         // This flag is set to true to support CCK rate by default.
1454         // It will be affected by "pHTInfo->bRegSuppCCK" and AP capabilities only when associate to
1455         // 11N BSS.
1456         pHTInfo->bCurSuppCCK = true;
1457
1458         // AMSDU related
1459         pHTInfo->bCurrent_AMSDU_Support = false;
1460         pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1461
1462         // AMPUD related
1463         pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1464         pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1465
1466
1467
1468         // Initialize all of the parameters related to 11n
1469         memset((void*)(&(pHTInfo->SelfHTCap)), 0, sizeof(pHTInfo->SelfHTCap));
1470         memset((void*)(&(pHTInfo->SelfHTInfo)), 0, sizeof(pHTInfo->SelfHTInfo));
1471         memset((void*)(&(pHTInfo->PeerHTCapBuf)), 0, sizeof(pHTInfo->PeerHTCapBuf));
1472         memset((void*)(&(pHTInfo->PeerHTInfoBuf)), 0, sizeof(pHTInfo->PeerHTInfoBuf));
1473
1474         pHTInfo->bSwBwInProgress = false;
1475         pHTInfo->ChnlOp = CHNLOP_NONE;
1476
1477         // Set default IEEE spec for Draft N
1478         pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE;
1479
1480         // Realtek proprietary aggregation mode
1481         pHTInfo->bCurrentRT2RTAggregation = false;
1482         pHTInfo->bCurrentRT2RTLongSlotTime = false;
1483         pHTInfo->RT2RT_HT_Mode = (RT_HT_CAPBILITY)0;
1484
1485         pHTInfo->IOTPeer = 0;
1486         pHTInfo->IOTAction = 0;
1487         pHTInfo->IOTRaFunc = 0;
1488
1489         //MCS rate initialized here
1490         {
1491                 u8* RegHTSuppRateSets = &(ieee->RegHTSuppRateSet[0]);
1492                 RegHTSuppRateSets[0] = 0xFF;    //support MCS 0~7
1493                 RegHTSuppRateSets[1] = 0xFF;    //support MCS 8~15
1494                 RegHTSuppRateSets[4] = 0x01;    //support MCS 32
1495         }
1496 }
1497 /********************************************************************************************************************
1498  *function:  initialize Bss HT structure(struct PBSS_HT)
1499  *   input:  PBSS_HT pBssHT //to be initialized
1500  *  output:  none
1501  *  return:  none
1502  *  notice: This function is called when initialize network structure
1503 ********************************************************************************************************************/
1504 void HTInitializeBssDesc(PBSS_HT pBssHT)
1505 {
1506
1507         pBssHT->bdSupportHT = false;
1508         memset(pBssHT->bdHTCapBuf, 0, sizeof(pBssHT->bdHTCapBuf));
1509         pBssHT->bdHTCapLen = 0;
1510         memset(pBssHT->bdHTInfoBuf, 0, sizeof(pBssHT->bdHTInfoBuf));
1511         pBssHT->bdHTInfoLen = 0;
1512
1513         pBssHT->bdHTSpecVer= HT_SPEC_VER_IEEE;
1514
1515         pBssHT->bdRT2RTAggregation = false;
1516         pBssHT->bdRT2RTLongSlotTime = false;
1517         pBssHT->RT2RT_HT_Mode = (RT_HT_CAPBILITY)0;
1518 }
1519 #if 0
1520 //below function has merged into ieee80211_network_init() in ieee80211_rx.c
1521 void
1522 HTParsingHTCapElement(
1523         IN      PADAPTER                Adapter,
1524         IN      OCTET_STRING    HTCapIE,
1525         OUT     PRT_WLAN_BSS    pBssDesc
1526 )
1527 {
1528         PMGNT_INFO                              pMgntInfo = &Adapter->MgntInfo;
1529
1530         if( HTCapIE.Length > sizeof(pBssDesc->BssHT.bdHTCapBuf) )
1531         {
1532                 RT_TRACE( COMP_HT, DBG_LOUD, ("HTParsingHTCapElement(): HT Capability Element length is too long!\n") );
1533                 return;
1534         }
1535
1536         // TODO: Check the correctness of HT Cap
1537         //Print each field in detail. Driver should not print out this message by default
1538         if(!pMgntInfo->mActingAsAp && !pMgntInfo->mAssoc)
1539                 HTDebugHTCapability(DBG_TRACE, Adapter, &HTCapIE, (pu8)"HTParsingHTCapElement()");
1540
1541         HTCapIE.Length = HTCapIE.Length > sizeof(pBssDesc->BssHT.bdHTCapBuf)?\
1542                 sizeof(pBssDesc->BssHT.bdHTCapBuf):HTCapIE.Length;      //prevent from overflow
1543
1544         CopyMem(pBssDesc->BssHT.bdHTCapBuf, HTCapIE.Octet, HTCapIE.Length);
1545         pBssDesc->BssHT.bdHTCapLen = HTCapIE.Length;
1546
1547 }
1548
1549
1550 void
1551 HTParsingHTInfoElement(
1552         PADAPTER                Adapter,
1553         OCTET_STRING    HTInfoIE,
1554         PRT_WLAN_BSS    pBssDesc
1555 )
1556 {
1557         PMGNT_INFO                              pMgntInfo = &Adapter->MgntInfo;
1558
1559         if( HTInfoIE.Length > sizeof(pBssDesc->BssHT.bdHTInfoBuf))
1560         {
1561                 RT_TRACE( COMP_HT, DBG_LOUD, ("HTParsingHTInfoElement(): HT Information Element length is too long!\n") );
1562                 return;
1563         }
1564
1565         // TODO: Check the correctness of HT Info
1566         //Print each field in detail. Driver should not print out this message by default
1567         if(!pMgntInfo->mActingAsAp && !pMgntInfo->mAssoc)
1568                 HTDebugHTInfo(DBG_TRACE, Adapter, &HTInfoIE, (pu8)"HTParsingHTInfoElement()");
1569
1570         HTInfoIE.Length = HTInfoIE.Length > sizeof(pBssDesc->BssHT.bdHTInfoBuf)?\
1571                 sizeof(pBssDesc->BssHT.bdHTInfoBuf):HTInfoIE.Length;    //prevent from overflow
1572
1573         CopyMem( pBssDesc->BssHT.bdHTInfoBuf, HTInfoIE.Octet, HTInfoIE.Length);
1574         pBssDesc->BssHT.bdHTInfoLen = HTInfoIE.Length;
1575 }
1576
1577 /*
1578   * Get HT related information from beacon and save it in BssDesc
1579   *
1580   * (1) Parse HTCap, and HTInfo, and record whether it is 11n AP
1581   * (2) If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1582   * (3) Check whether peer is Realtek AP (for Realtek proprietary aggregation mode).
1583   * Input:
1584   *             PADAPTER        Adapter
1585   *
1586   * Output:
1587   *             PRT_TCB         BssDesc
1588   *
1589 */
1590 void HTGetValueFromBeaconOrProbeRsp(
1591         PADAPTER                        Adapter,
1592         POCTET_STRING           pSRCmmpdu,
1593         PRT_WLAN_BSS            bssDesc
1594 )
1595 {
1596         PMGNT_INFO                              pMgntInfo = &Adapter->MgntInfo;
1597         PRT_HIGH_THROUGHPUT             pHTInfo = GET_HT_INFO(pMgntInfo);
1598         OCTET_STRING                            HTCapIE, HTInfoIE, HTRealtekAgg, mmpdu;
1599         OCTET_STRING                            BroadcomElement, CiscoElement;
1600
1601         mmpdu.Octet = pSRCmmpdu->Octet;
1602         mmpdu.Length = pSRCmmpdu->Length;
1603
1604         //2Note:
1605         //   Mark for IOT testing using  Linksys WRT350N, This AP does not contain WMM IE  when
1606         //   it is configured at pure-N mode.
1607         //      if(bssDesc->BssQos.bdQoSMode & QOS_WMM)
1608         //
1609
1610         HTInitializeBssDesc (&bssDesc->BssHT);
1611
1612         //2<1> Parse HTCap, and HTInfo
1613         // Get HT Capability IE: (1) Get IEEE Draft N IE or (2) Get EWC IE
1614         HTCapIE = PacketGetElement(mmpdu, EID_HTCapability, OUI_SUB_DONT_CARE, OUI_SUBTYPE_DONT_CARE);
1615         if(HTCapIE.Length == 0)
1616         {
1617                 HTCapIE = PacketGetElement(mmpdu, EID_Vendor, OUI_SUB_11N_EWC_HT_CAP, OUI_SUBTYPE_DONT_CARE);
1618                 if(HTCapIE.Length != 0)
1619                         bssDesc->BssHT.bdHTSpecVer= HT_SPEC_VER_EWC;
1620         }
1621         if(HTCapIE.Length != 0)
1622                 HTParsingHTCapElement(Adapter, HTCapIE, bssDesc);
1623
1624         // Get HT Information IE: (1) Get IEEE Draft N IE or (2) Get EWC IE
1625         HTInfoIE = PacketGetElement(mmpdu, EID_HTInfo, OUI_SUB_DONT_CARE, OUI_SUBTYPE_DONT_CARE);
1626         if(HTInfoIE.Length == 0)
1627         {
1628                 HTInfoIE = PacketGetElement(mmpdu, EID_Vendor, OUI_SUB_11N_EWC_HT_INFO, OUI_SUBTYPE_DONT_CARE);
1629                 if(HTInfoIE.Length != 0)
1630                                 bssDesc->BssHT.bdHTSpecVer  = HT_SPEC_VER_EWC;
1631         }
1632         if(HTInfoIE.Length != 0)
1633                 HTParsingHTInfoElement(Adapter, HTInfoIE, bssDesc);
1634
1635         //2<2>If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1636         if(HTCapIE.Length != 0)
1637         {
1638                 bssDesc->BssHT.bdSupportHT = true;
1639                 if(bssDesc->BssQos.bdQoSMode == QOS_DISABLE)
1640                         QosSetLegacyWMMParamWithHT(Adapter, bssDesc);
1641         }
1642         else
1643         {
1644                 bssDesc->BssHT.bdSupportHT = false;
1645         }
1646
1647         //2<3>Check whether the peer is Realtek AP/STA
1648         if(pHTInfo->bRegRT2RTAggregation)
1649         {
1650                 if(bssDesc->BssHT.bdSupportHT)
1651                 {
1652                         HTRealtekAgg = PacketGetElement(mmpdu, EID_Vendor, OUI_SUB_REALTEK_AGG, OUI_SUBTYPE_DONT_CARE);
1653                         if(HTRealtekAgg.Length >=5 )
1654                         {
1655                                 bssDesc->BssHT.bdRT2RTAggregation = true;
1656
1657                                 if((HTRealtekAgg.Octet[4]==1) && (HTRealtekAgg.Octet[5] & 0x02))
1658                                         bssDesc->BssHT.bdRT2RTLongSlotTime = true;
1659                         }
1660                 }
1661         }
1662
1663         //
1664         // 2008/01/25 MH Get Broadcom AP IE for manamgent frame CCK rate problem.
1665         // AP can not receive CCK managemtn from from 92E.
1666         //
1667
1668         // Initialize every new bss broadcom cap exist as false..
1669         bssDesc->bBroadcomCapExist= false;
1670
1671         if(HTCapIE.Length != 0 || HTInfoIE.Length != 0)
1672         {
1673                 u4Byte  Length = 0;
1674
1675                 FillOctetString(BroadcomElement, NULL, 0);
1676
1677                 BroadcomElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_BROADCOM_IE_1, OUI_SUBTYPE_DONT_CARE);
1678                 Length += BroadcomElement.Length;
1679                 BroadcomElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_BROADCOM_IE_2, OUI_SUBTYPE_DONT_CARE);
1680                 Length += BroadcomElement.Length;
1681                 BroadcomElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_BROADCOM_IE_3, OUI_SUBTYPE_DONT_CARE);
1682                 Length += BroadcomElement.Length;
1683
1684                 if(Length > 0)
1685                         bssDesc->bBroadcomCapExist = true;
1686         }
1687
1688
1689         // For Cisco IOT issue
1690         CiscoElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_CISCO_IE, OUI_SUBTYPE_DONT_CARE);
1691         if(CiscoElement.Length != 0){ // 3: 0x00, 0x40, 0x96 ....
1692                 bssDesc->bCiscoCapExist = true;
1693         }else{
1694                 bssDesc->bCiscoCapExist = false;
1695         }
1696 }
1697
1698
1699 #endif
1700 /********************************************************************************************************************
1701  *function:  initialize Bss HT structure(struct PBSS_HT)
1702  *   input:  struct ieee80211_device    *ieee
1703  *           struct ieee80211_network   *pNetwork //usually current network we are live in
1704  *  output:  none
1705  *  return:  none
1706  *  notice: This function should ONLY be called before association
1707 ********************************************************************************************************************/
1708 void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee,       struct ieee80211_network * pNetwork)
1709 {
1710         PRT_HIGH_THROUGHPUT             pHTInfo = ieee->pHTInfo;
1711 //      u16                                             nMaxAMSDUSize;
1712 //      PHT_CAPABILITY_ELE              pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1713 //      PHT_INFORMATION_ELE             pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1714 //      u8*     pMcsFilter;
1715         u8      bIOTAction = 0;
1716
1717         //
1718         //  Save Peer Setting before Association
1719         //
1720         IEEE80211_DEBUG(IEEE80211_DL_HT, "==============>%s()\n", __FUNCTION__);
1721         /*unmark bEnableHT flag here is the same reason why unmarked in function ieee80211_softmac_new_net. WB 2008.09.10*/
1722 //      if( pHTInfo->bEnableHT &&  pNetwork->bssht.bdSupportHT)
1723         if (pNetwork->bssht.bdSupportHT)
1724         {
1725                 pHTInfo->bCurrentHTSupport = true;
1726                 pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer;
1727
1728                 // Save HTCap and HTInfo information Element
1729                 if(pNetwork->bssht.bdHTCapLen > 0 &&    pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf))
1730                         memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen);
1731
1732                 if(pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf))
1733                         memcpy(pHTInfo->PeerHTInfoBuf, pNetwork->bssht.bdHTInfoBuf, pNetwork->bssht.bdHTInfoLen);
1734
1735                 // Check whether RT to RT aggregation mode is enabled
1736                 if(pHTInfo->bRegRT2RTAggregation)
1737                 {
1738                         pHTInfo->bCurrentRT2RTAggregation = pNetwork->bssht.bdRT2RTAggregation;
1739                         pHTInfo->bCurrentRT2RTLongSlotTime = pNetwork->bssht.bdRT2RTLongSlotTime;
1740                         pHTInfo->RT2RT_HT_Mode = pNetwork->bssht.RT2RT_HT_Mode;
1741                 }
1742                 else
1743                 {
1744                         pHTInfo->bCurrentRT2RTAggregation = false;
1745                         pHTInfo->bCurrentRT2RTLongSlotTime = false;
1746                         pHTInfo->RT2RT_HT_Mode = (RT_HT_CAPBILITY)0;
1747                 }
1748
1749                 // Determine the IOT Peer Vendor.
1750                 HTIOTPeerDetermine(ieee);
1751
1752                 // Decide IOT Action
1753                 // Must be called after the parameter of pHTInfo->bCurrentRT2RTAggregation is decided
1754                 pHTInfo->IOTAction = 0;
1755                 bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid);
1756                 if(bIOTAction)
1757                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS14;
1758
1759                 bIOTAction = HTIOTActIsDisableMCS15(ieee);
1760                 if(bIOTAction)
1761                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS15;
1762
1763                 bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee);
1764                 if(bIOTAction)
1765                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_ALL_2SS;
1766
1767
1768                 bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid);
1769                 if(bIOTAction)
1770                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_EDCA_TURBO;
1771
1772                 bIOTAction = HTIOTActIsMgntUseCCK6M(pNetwork);
1773                 if(bIOTAction)
1774                         pHTInfo->IOTAction |= HT_IOT_ACT_MGNT_USE_CCK_6M;
1775
1776                 bIOTAction = HTIOTActIsCCDFsync(pNetwork->bssid);
1777                 if(bIOTAction)
1778                         pHTInfo->IOTAction |= HT_IOT_ACT_CDD_FSYNC;
1779
1780                 bIOTAction = HTIOTActIsForcedCTS2Self(pNetwork);
1781                 if(bIOTAction)
1782                         pHTInfo->IOTAction |= HT_IOT_ACT_FORCED_CTS2SELF;
1783
1784                 //bIOTAction = HTIOTActIsForcedRTSCTS(ieee, pNetwork);
1785                 //if(bIOTAction)
1786                 //      pHTInfo->IOTAction |= HT_IOT_ACT_FORCED_RTS;
1787
1788 #if defined(RTL8192SU)
1789                 bIOTAction = HTIOCActRejcectADDBARequest(pNetwork);
1790                 if(bIOTAction)
1791                         pHTInfo->IOTAction |= HT_IOT_ACT_REJECT_ADDBA_REQ;
1792 #endif
1793
1794                 bIOTAction = HTIOCActAllowPeerAggOnePacket(ieee, pNetwork);
1795                 if(bIOTAction)
1796                         pHTInfo->IOTAction |= HT_IOT_ACT_ALLOW_PEER_AGG_ONE_PKT;
1797
1798                 bIOTAction = HTIOTActIsEDCABiasRx(ieee, pNetwork);
1799                 if(bIOTAction)
1800                         pHTInfo->IOTAction |= HT_IOT_ACT_EDCA_BIAS_ON_RX;
1801
1802 #if defined(RTL8192SU)
1803                 bIOTAction = HTIOTActDisableShortGI(ieee, pNetwork);
1804                 if(bIOTAction)
1805                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_SHORT_GI;
1806
1807                 bIOTAction = HTIOTActDisableHighPower(ieee, pNetwork);
1808                 if(bIOTAction)
1809                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_HIGH_POWER;
1810 #endif
1811
1812                 bIOTAction = HTIOTActIsForcedAMSDU8K(ieee, pNetwork);
1813                 if(bIOTAction)
1814                         pHTInfo->IOTAction |= HT_IOT_ACT_TX_USE_AMSDU_8K;
1815
1816 #if defined(RTL8192SU)
1817                 bIOTAction = HTIOTActIsTxNoAggregation(ieee, pNetwork);
1818                 if(bIOTAction)
1819                         pHTInfo->IOTAction |= HT_IOT_ACT_TX_NO_AGGREGATION;
1820
1821                 bIOTAction = HTIOTActIsDisableTx40MHz(ieee, pNetwork);
1822                 if(bIOTAction)
1823                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_TX_40_MHZ;
1824
1825                 bIOTAction = HTIOTActIsDisableTx2SS(ieee, pNetwork);
1826                 if(bIOTAction)
1827                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_TX_2SS;
1828 #endif
1829                 //must after HT_IOT_ACT_TX_NO_AGGREGATION
1830                 bIOTAction = HTIOTActIsForcedRTSCTS(ieee, pNetwork);
1831                 if(bIOTAction)
1832                         pHTInfo->IOTAction |= HT_IOT_ACT_FORCED_RTS;
1833
1834                 printk("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IOTAction = %8.8x\n", pHTInfo->IOTAction);
1835         }
1836         else
1837         {
1838                 pHTInfo->bCurrentHTSupport = false;
1839                 pHTInfo->bCurrentRT2RTAggregation = false;
1840                 pHTInfo->bCurrentRT2RTLongSlotTime = false;
1841                 pHTInfo->RT2RT_HT_Mode = (RT_HT_CAPBILITY)0;
1842
1843                 pHTInfo->IOTAction = 0;
1844                 pHTInfo->IOTRaFunc = 0;
1845         }
1846
1847 }
1848
1849 void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee,  struct ieee80211_network * pNetwork)
1850 {
1851         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
1852 //      PHT_CAPABILITY_ELE              pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1853         PHT_INFORMATION_ELE             pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1854
1855         if(pHTInfo->bCurrentHTSupport)
1856         {
1857                 //
1858                 // Config current operation mode.
1859                 //
1860                 if(pNetwork->bssht.bdHTInfoLen != 0)
1861                         pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1862
1863                 //
1864                 // <TODO: Config according to OBSS non-HT STA present!!>
1865                 //
1866         }
1867 }
1868
1869 void HTUseDefaultSetting(struct ieee80211_device* ieee)
1870 {
1871         PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1872 //      u8      regBwOpMode;
1873
1874         if(pHTInfo->bEnableHT)
1875         {
1876                 pHTInfo->bCurrentHTSupport = true;
1877
1878                 pHTInfo->bCurSuppCCK = pHTInfo->bRegSuppCCK;
1879
1880                 pHTInfo->bCurBW40MHz = pHTInfo->bRegBW40MHz;
1881
1882                 pHTInfo->bCurShortGI20MHz= pHTInfo->bRegShortGI20MHz;
1883
1884                 pHTInfo->bCurShortGI40MHz= pHTInfo->bRegShortGI40MHz;
1885
1886                 pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
1887
1888                 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1889
1890                 pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
1891
1892                 pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1893
1894                 pHTInfo->CurrentMPDUDensity = pHTInfo->CurrentMPDUDensity;
1895
1896                 // Set BWOpMode register
1897
1898                 //update RATR index0
1899                 HTFilterMCSRate(ieee, ieee->Regdot11HTOperationalRateSet, ieee->dot11HTOperationalRateSet);
1900         //function below is not implemented at all. WB
1901 #ifdef TODO
1902                 Adapter->HalFunc.InitHalRATRTableHandler( Adapter, &pMgntInfo->dot11OperationalRateSet, pMgntInfo->dot11HTOperationalRateSet);
1903 #endif
1904                 ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, MCS_FILTER_ALL);
1905                 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
1906
1907         }
1908         else
1909         {
1910                 pHTInfo->bCurrentHTSupport = false;
1911         }
1912         return;
1913 }
1914 /********************************************************************************************************************
1915  *function:  check whether HT control field exists
1916  *   input:  struct ieee80211_device    *ieee
1917  *           u8*                        pFrame //coming skb->data
1918  *  output:  none
1919  *  return:  return true if HT control field exists(false otherwise)
1920  *  notice:
1921 ********************************************************************************************************************/
1922 u8 HTCCheck(struct ieee80211_device* ieee, u8*  pFrame)
1923 {
1924         if(ieee->pHTInfo->bCurrentHTSupport)
1925         {
1926                 if( (IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1)
1927                 {
1928                         IEEE80211_DEBUG(IEEE80211_DL_HT, "HT CONTROL FILED EXIST!!\n");
1929                         return true;
1930                 }
1931         }
1932         return false;
1933 }
1934
1935 //
1936 // This function set bandwidth mode in protocol layer.
1937 //
1938 void HTSetConnectBwMode(struct ieee80211_device* ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset)
1939 {
1940         PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1941 //      u32 flags = 0;
1942
1943         if(pHTInfo->bRegBW40MHz == false)
1944                 return;
1945
1946
1947
1948         // To reduce dummy operation
1949 //      if((pHTInfo->bCurBW40MHz==false && Bandwidth==HT_CHANNEL_WIDTH_20) ||
1950 //         (pHTInfo->bCurBW40MHz==true && Bandwidth==HT_CHANNEL_WIDTH_20_40 && Offset==pHTInfo->CurSTAExtChnlOffset))
1951 //              return;
1952
1953 //      spin_lock_irqsave(&(ieee->bw_spinlock), flags);
1954         if(pHTInfo->bSwBwInProgress) {
1955 //              spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1956                 return;
1957         }
1958         //if in half N mode, set to 20M bandwidth please 09.08.2008 WB.
1959         if(Bandwidth==HT_CHANNEL_WIDTH_20_40 && (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)))
1960          {
1961                         // Handle Illegal extention channel offset!!
1962                 if(ieee->current_network.channel<2 && Offset==HT_EXTCHNL_OFFSET_LOWER)
1963                         Offset = HT_EXTCHNL_OFFSET_NO_EXT;
1964                 if(Offset==HT_EXTCHNL_OFFSET_UPPER || Offset==HT_EXTCHNL_OFFSET_LOWER) {
1965                         pHTInfo->bCurBW40MHz = true;
1966                         pHTInfo->CurSTAExtChnlOffset = Offset;
1967                 } else {
1968                         pHTInfo->bCurBW40MHz = false;
1969                         pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1970                 }
1971         } else {
1972                 pHTInfo->bCurBW40MHz = false;
1973                 pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1974         }
1975
1976         pHTInfo->bSwBwInProgress = true;
1977
1978         // TODO: 2007.7.13 by Emily Wait 2000ms  in order to garantee that switching
1979         //   bandwidth is executed after scan is finished. It is a temporal solution
1980         //   because software should ganrantee the last operation of switching bandwidth
1981         //   is executed properlly.
1982         HTSetConnectBwModeCallback(ieee);
1983
1984 //      spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1985 }
1986
1987 void HTSetConnectBwModeCallback(struct ieee80211_device* ieee)
1988 {
1989         PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1990
1991         IEEE80211_DEBUG(IEEE80211_DL_HT, "======>%s()\n", __FUNCTION__);
1992         if(pHTInfo->bCurBW40MHz)
1993         {
1994                 if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_UPPER)
1995                         ieee->set_chan(ieee->dev, ieee->current_network.channel+2);
1996                 else if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_LOWER)
1997                         ieee->set_chan(ieee->dev, ieee->current_network.channel-2);
1998                 else
1999                         ieee->set_chan(ieee->dev, ieee->current_network.channel);
2000
2001                 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, pHTInfo->CurSTAExtChnlOffset);
2002         } else {
2003                 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2004                 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2005         }
2006
2007         pHTInfo->bSwBwInProgress = false;
2008 }
2009
2010 EXPORT_SYMBOL(HTUpdateSelfAndPeerSetting);