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