Merge tag 'metag-for-v3.15' of git://git.kernel.org/pub/scm/linux/kernel/git/jhogan...
[cascardo/linux.git] / drivers / staging / rtl8192u / 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
44 // 2008/04/01 MH For Cisco G mode RX TP We need to change FW duration. Should we put the
45 // code in other place??
46 //static u8 WIFI_CISCO_G_AP[3] = {0x00, 0x40, 0x96};
47 /********************************************************************************************************************
48  *function:  This function update default settings in pHTInfo structure
49  *   input:  PRT_HIGH_THROUGHPUT        pHTInfo
50  *  output:  none
51  *  return:  none
52  *  notice:  These value need be modified if any changes.
53  * *****************************************************************************************************************/
54 void HTUpdateDefaultSetting(struct ieee80211_device *ieee)
55 {
56         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
57         //const typeof( ((struct ieee80211_device *)0)->pHTInfo ) *__mptr = &pHTInfo;
58
59         //printk("pHTinfo:%p, &pHTinfo:%p, mptr:%p,  offsetof:%x\n", pHTInfo, &pHTInfo, __mptr, offsetof(struct ieee80211_device, pHTInfo));
60         //printk("===>ieee:%p,\n", ieee);
61         // ShortGI support
62         pHTInfo->bRegShortGI20MHz= 1;
63         pHTInfo->bRegShortGI40MHz= 1;
64
65         // 40MHz channel support
66         pHTInfo->bRegBW40MHz = 1;
67
68         // CCK rate support in 40MHz channel
69         if(pHTInfo->bRegBW40MHz)
70                 pHTInfo->bRegSuppCCK = 1;
71         else
72                 pHTInfo->bRegSuppCCK = true;
73
74         // AMSDU related
75         pHTInfo->nAMSDU_MaxSize = 7935UL;
76         pHTInfo->bAMSDU_Support = 0;
77
78         // AMPDU related
79         pHTInfo->bAMPDUEnable = 1;
80         pHTInfo->AMPDU_Factor = 2; //// 0: 2n13(8K), 1:2n14(16K), 2:2n15(32K), 3:2n16(64k)
81         pHTInfo->MPDU_Density = 0;// 0: No restriction, 1: 1/8usec, 2: 1/4usec, 3: 1/2usec, 4: 1usec, 5: 2usec, 6: 4usec, 7:8usec
82
83         // MIMO Power Save
84         pHTInfo->SelfMimoPs = 3;// 0: Static Mimo Ps, 1: Dynamic Mimo Ps, 3: No Limitation, 2: Reserved(Set to 3 automatically.)
85         if(pHTInfo->SelfMimoPs == 2)
86                 pHTInfo->SelfMimoPs = 3;
87         // 8190 only. Assign rate operation mode to firmware
88         ieee->bTxDisableRateFallBack = 0;
89         ieee->bTxUseDriverAssingedRate = 0;
90
91 #ifdef  TO_DO_LIST
92         // 8190 only. Assign duration operation mode to firmware
93         pMgntInfo->bTxEnableFwCalcDur = (BOOLEAN)pNdisCommon->bRegTxEnableFwCalcDur;
94 #endif
95         // 8190 only, Realtek proprietary aggregation mode
96         // Set MPDUDensity=2,   1: Set MPDUDensity=2(32k)  for Realtek AP and set MPDUDensity=0(8k) for others
97         pHTInfo->bRegRT2RTAggregation = 1;//0: Set MPDUDensity=2,   1: Set MPDUDensity=2(32k)  for Realtek AP and set MPDUDensity=0(8k) for others
98
99         // For Rx Reorder Control
100         pHTInfo->bRegRxReorderEnable = 1;
101         pHTInfo->RxReorderWinSize = 64;
102         pHTInfo->RxReorderPendingTime = 30;
103
104 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
105         pHTInfo->UsbTxAggrNum = 4;
106 #endif
107 #ifdef USB_RX_AGGREGATION_SUPPORT
108         pHTInfo->UsbRxFwAggrEn = 1;
109         pHTInfo->UsbRxFwAggrPageNum = 24;
110         pHTInfo->UsbRxFwAggrPacketNum = 8;
111         pHTInfo->UsbRxFwAggrTimeout = 16; ////usb rx FW aggregation timeout threshold.It's in units of 64us
112 #endif
113
114
115 }
116 /********************************************************************************************************************
117  *function:  This function print out each field on HT capability IE mainly from (Beacon/ProbeRsp/AssocReq)
118  *   input:  u8*        CapIE       //Capability IE to be printed out
119  *           u8*        TitleString //mainly print out caller function
120  *  output:  none
121  *  return:  none
122  *  notice:  Driver should not print out this message by default.
123  * *****************************************************************************************************************/
124 void HTDebugHTCapability(u8 *CapIE, u8 *TitleString )
125 {
126
127         static u8       EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};       // For 11n EWC definition, 2007.07.17, by Emily
128         PHT_CAPABILITY_ELE              pCapELE;
129
130         if(!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap)))
131         {
132                 //EWC IE
133                 IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __FUNCTION__);
134                 pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[4]);
135         }else
136                 pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[0]);
137
138         IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Capability>. Called by %s\n", TitleString );
139
140         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupported Channel Width = %s\n", (pCapELE->ChlWidth)?"20MHz": "20/40MHz");
141         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport Short GI for 20M = %s\n", (pCapELE->ShortGI20Mhz)?"YES": "NO");
142         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport Short GI for 40M = %s\n", (pCapELE->ShortGI40Mhz)?"YES": "NO");
143         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport TX STBC = %s\n", (pCapELE->TxSTBC)?"YES": "NO");
144         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMax AMSDU Size = %s\n", (pCapELE->MaxAMSDUSize)?"3839": "7935");
145         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport CCK in 20/40 mode = %s\n", (pCapELE->DssCCk)?"YES": "NO");
146         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMax AMPDU Factor = %d\n", pCapELE->MaxRxAMPDUFactor);
147         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMPDU Density = %d\n", pCapELE->MPDUDensity);
148         IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMCS Rate Set = [%x][%x][%x][%x][%x]\n", pCapELE->MCS[0],\
149                                 pCapELE->MCS[1], pCapELE->MCS[2], pCapELE->MCS[3], pCapELE->MCS[4]);
150         return;
151
152 }
153 /********************************************************************************************************************
154  *function:  This function print out each field on HT Information IE mainly from (Beacon/ProbeRsp)
155  *   input:  u8*        InfoIE       //Capability IE to be printed out
156  *           u8*        TitleString //mainly print out caller function
157  *  output:  none
158  *  return:  none
159  *  notice:  Driver should not print out this message by default.
160  * *****************************************************************************************************************/
161 void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString)
162 {
163
164         static u8       EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};      // For 11n EWC definition, 2007.07.17, by Emily
165         PHT_INFORMATION_ELE             pHTInfoEle;
166
167         if(!memcmp(InfoIE, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
168         {
169                 // Not EWC IE
170                 IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __FUNCTION__);
171                 pHTInfoEle = (PHT_INFORMATION_ELE)(&InfoIE[4]);
172         }else
173                 pHTInfoEle = (PHT_INFORMATION_ELE)(&InfoIE[0]);
174
175
176         IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Information Element>. Called by %s\n", TitleString);
177
178         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tPrimary channel = %d\n", pHTInfoEle->ControlChl);
179         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tSenondary channel =");
180         switch (pHTInfoEle->ExtChlOffset)
181         {
182                 case 0:
183                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Not Present\n");
184                         break;
185                 case 1:
186                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Upper channel\n");
187                         break;
188                 case 2:
189                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Reserved. Eooro!!!\n");
190                         break;
191                 case 3:
192                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Lower Channel\n");
193                         break;
194         }
195         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tRecommended channel width = %s\n", (pHTInfoEle->RecommemdedTxWidth)?"20Mhz": "40Mhz");
196
197         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tOperation mode for protection = ");
198         switch (pHTInfoEle->OptMode)
199         {
200                 case 0:
201                         IEEE80211_DEBUG(IEEE80211_DL_HT, "No Protection\n");
202                         break;
203                 case 1:
204                         IEEE80211_DEBUG(IEEE80211_DL_HT, "HT non-member protection mode\n");
205                         break;
206                 case 2:
207                         IEEE80211_DEBUG(IEEE80211_DL_HT, "Suggest to open protection\n");
208                         break;
209                 case 3:
210                         IEEE80211_DEBUG(IEEE80211_DL_HT, "HT mixed mode\n");
211                         break;
212         }
213
214         IEEE80211_DEBUG(IEEE80211_DL_HT, "\tBasic MCS Rate Set = [%x][%x][%x][%x][%x]\n", pHTInfoEle->BasicMSC[0],\
215                                 pHTInfoEle->BasicMSC[1], pHTInfoEle->BasicMSC[2], pHTInfoEle->BasicMSC[3], pHTInfoEle->BasicMSC[4]);
216         return;
217 }
218
219 /*
220 *       Return:         true if station in half n mode and AP supports 40 bw
221 */
222 static bool IsHTHalfNmode40Bandwidth(struct ieee80211_device *ieee)
223 {
224         bool                    retValue = false;
225         PRT_HIGH_THROUGHPUT      pHTInfo = ieee->pHTInfo;
226
227         if(pHTInfo->bCurrentHTSupport == false )        // wireless is n mode
228                 retValue = false;
229         else if(pHTInfo->bRegBW40MHz == false)  // station supports 40 bw
230                 retValue = false;
231         else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))      // station in half n mode
232                 retValue = false;
233         else if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw
234                 retValue = true;
235         else
236                 retValue = false;
237
238         return retValue;
239 }
240
241 static bool IsHTHalfNmodeSGI(struct ieee80211_device *ieee, bool is40MHz)
242 {
243         bool                    retValue = false;
244         PRT_HIGH_THROUGHPUT      pHTInfo = ieee->pHTInfo;
245
246         if(pHTInfo->bCurrentHTSupport == false )        // wireless is n mode
247                 retValue = false;
248         else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))      // station in half n mode
249                 retValue = false;
250         else if(is40MHz) // ap support 40 bw
251         {
252                 if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI40Mhz) // ap support 40 bw short GI
253                         retValue = true;
254                 else
255                         retValue = false;
256         }
257         else
258         {
259                 if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI20Mhz) // ap support 40 bw short GI
260                         retValue = true;
261                 else
262                         retValue = false;
263         }
264
265         return retValue;
266 }
267
268 u16 HTHalfMcsToDataRate(struct ieee80211_device *ieee,  u8      nMcsRate)
269 {
270
271         u8      is40MHz;
272         u8      isShortGI;
273
274         is40MHz  =  (IsHTHalfNmode40Bandwidth(ieee))?1:0;
275         isShortGI = (IsHTHalfNmodeSGI(ieee, is40MHz))? 1:0;
276
277         return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate&0x7f)];
278 }
279
280
281 u16 HTMcsToDataRate( struct ieee80211_device *ieee, u8 nMcsRate)
282 {
283         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
284
285         u8      is40MHz = (pHTInfo->bCurBW40MHz)?1:0;
286         u8      isShortGI = (pHTInfo->bCurBW40MHz)?
287                                                 ((pHTInfo->bCurShortGI40MHz)?1:0):
288                                                 ((pHTInfo->bCurShortGI20MHz)?1:0);
289         return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate&0x7f)];
290 }
291
292 /********************************************************************************************************************
293  *function:  This function returns current datarate.
294  *   input:  struct ieee80211_device*   ieee
295  *           u8                         nDataRate
296  *  output:  none
297  *  return:  tx rate
298  *  notice:  quite unsure about how to use this function //wb
299  * *****************************************************************************************************************/
300 u16  TxCountToDataRate( struct ieee80211_device *ieee, u8 nDataRate)
301 {
302         //PRT_HIGH_THROUGHPUT   pHTInfo = ieee->pHTInfo;
303         u16             CCKOFDMRate[12] = {0x02 , 0x04 , 0x0b , 0x16 , 0x0c , 0x12 , 0x18 , 0x24 , 0x30 , 0x48 , 0x60 , 0x6c};
304         u8      is40MHz = 0;
305         u8      isShortGI = 0;
306
307         if(nDataRate < 12)
308         {
309                 return CCKOFDMRate[nDataRate];
310         }
311         else
312         {
313                 if (nDataRate >= 0x10 && nDataRate <= 0x1f)//if(nDataRate > 11 && nDataRate < 28 )
314                 {
315                         is40MHz = 0;
316                         isShortGI = 0;
317
318                       // nDataRate = nDataRate - 12;
319                 }
320                 else if(nDataRate >=0x20  && nDataRate <= 0x2f ) //(27, 44)
321                 {
322                         is40MHz = 1;
323                         isShortGI = 0;
324
325                         //nDataRate = nDataRate - 28;
326                 }
327                 else if(nDataRate >= 0x30  && nDataRate <= 0x3f )  //(43, 60)
328                 {
329                         is40MHz = 0;
330                         isShortGI = 1;
331
332                         //nDataRate = nDataRate - 44;
333                 }
334                 else if(nDataRate >= 0x40  && nDataRate <= 0x4f ) //(59, 76)
335                 {
336                         is40MHz = 1;
337                         isShortGI = 1;
338
339                         //nDataRate = nDataRate - 60;
340                 }
341                 return MCS_DATA_RATE[is40MHz][isShortGI][nDataRate&0xf];
342         }
343 }
344
345
346
347 bool IsHTHalfNmodeAPs(struct ieee80211_device *ieee)
348 {
349         bool                    retValue = false;
350         struct ieee80211_network *net = &ieee->current_network;
351         if((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3)==0) ||
352                      (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3)==0) ||
353                      (memcmp(net->bssid, PCI_RALINK, 3)==0) ||
354                      (memcmp(net->bssid, EDIMAX_RALINK, 3)==0) ||
355                      (memcmp(net->bssid, AIRLINK_RALINK, 3)==0) ||
356                      (net->ralink_cap_exist))
357                 retValue = true;
358         else if((memcmp(net->bssid, UNKNOWN_BORADCOM, 3)==0) ||
359                     (memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
360                     (memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
361                     (memcmp(net->bssid, NETGEAR834Bv2_BROADCOM, 3)==0) ||
362                     (net->broadcom_cap_exist))
363                   retValue = true;
364         else if(net->bssht.bdRT2RTAggregation)
365                 retValue = true;
366         else
367                 retValue = false;
368
369         return retValue;
370 }
371
372 /********************************************************************************************************************
373  *function:  This function returns peer IOT.
374  *   input:  struct ieee80211_device*   ieee
375  *  output:  none
376  *  return:
377  *  notice:
378  * *****************************************************************************************************************/
379 static void HTIOTPeerDetermine(struct ieee80211_device *ieee)
380 {
381         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
382         struct ieee80211_network *net = &ieee->current_network;
383         if(net->bssht.bdRT2RTAggregation)
384                 pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK;
385         else if(net->broadcom_cap_exist)
386                 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
387         else if((memcmp(net->bssid, UNKNOWN_BORADCOM, 3)==0) ||
388                         (memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
389                         (memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
390                         (memcmp(net->bssid, NETGEAR834Bv2_BROADCOM, 3)==0) )
391                 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
392         else if((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3)==0) ||
393                         (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3)==0) ||
394                         (memcmp(net->bssid, PCI_RALINK, 3)==0) ||
395                         (memcmp(net->bssid, EDIMAX_RALINK, 3)==0) ||
396                         (memcmp(net->bssid, AIRLINK_RALINK, 3)==0) ||
397                          net->ralink_cap_exist)
398                 pHTInfo->IOTPeer = HT_IOT_PEER_RALINK;
399         else if(net->atheros_cap_exist)
400                 pHTInfo->IOTPeer = HT_IOT_PEER_ATHEROS;
401         else if(memcmp(net->bssid, CISCO_BROADCOM, 3)==0)
402                 pHTInfo->IOTPeer = HT_IOT_PEER_CISCO;
403         else
404                 pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
405
406         IEEE80211_DEBUG(IEEE80211_DL_IOT, "Joseph debug!! IOTPEER: %x\n", pHTInfo->IOTPeer);
407 }
408 /********************************************************************************************************************
409  *function:  Check whether driver should declare received rate up to MCS13 only since some chipset is not good
410  *           at receiving MCS14~15 frame from some AP.
411  *   input:  struct ieee80211_device*   ieee
412  *           u8 *                       PeerMacAddr
413  *  output:  none
414  *  return:  return 1 if driver should declare MCS13 only(otherwise return 0)
415   * *****************************************************************************************************************/
416 static u8 HTIOTActIsDisableMCS14(struct ieee80211_device *ieee, u8 *PeerMacAddr)
417 {
418         u8 ret = 0;
419         return ret;
420  }
421
422
423 /**
424 * Function:     HTIOTActIsDisableMCS15
425 *
426 * Overview:     Check whether driver should declare capability of receiving MCS15
427 *
428 * Input:
429 *                       PADAPTER                Adapter,
430 *
431 * Output:               None
432 * Return:       true if driver should disable MCS15
433 * 2008.04.15    Emily
434 */
435 static bool HTIOTActIsDisableMCS15(struct ieee80211_device *ieee)
436 {
437         bool retValue = false;
438
439 #ifdef TODO
440         // Apply for 819u only
441 #if (HAL_CODE_BASE==RTL8192)
442
443 #if (DEV_BUS_TYPE == USB_INTERFACE)
444         // Alway disable MCS15 by Jerry Chang's request.by Emily, 2008.04.15
445         retValue = true;
446 #elif (DEV_BUS_TYPE == PCI_INTERFACE)
447         // Enable MCS15 if the peer is Cisco AP. by Emily, 2008.05.12
448 //      if(pBssDesc->bCiscoCapExist)
449 //              retValue = false;
450 //      else
451                 retValue = false;
452 #endif
453 #endif
454 #endif
455         // Jerry Chang suggest that 8190 1x2 does not need to disable MCS15
456
457         return retValue;
458 }
459
460 /**
461 * Function:     HTIOTActIsDisableMCSTwoSpatialStream
462 *
463 * Overview:     Check whether driver should declare capability of receiving All 2 ss packets
464 *
465 * Input:
466 *                       PADAPTER                Adapter,
467 *
468 * Output:               None
469 * Return:       true if driver should disable all two spatial stream packet
470 * 2008.04.21    Emily
471 */
472 static bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device *ieee,
473                                                  u8 *PeerMacAddr)
474 {
475         bool retValue = false;
476
477 #ifdef TODO
478         // Apply for 819u only
479 #endif
480         return retValue;
481 }
482
483 /********************************************************************************************************************
484  *function:  Check whether driver should disable EDCA turbo mode
485  *   input:  struct ieee80211_device*   ieee
486  *           u8*                        PeerMacAddr
487  *  output:  none
488  *  return:  return 1 if driver should disable EDCA turbo mode(otherwise return 0)
489   * *****************************************************************************************************************/
490 static u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device *ieee,
491                                      u8 *PeerMacAddr)
492 {
493         u8      retValue = false;       // default enable EDCA Turbo mode.
494         // Set specific EDCA parameter for different AP in DM handler.
495
496         return retValue;
497 }
498
499 /********************************************************************************************************************
500  *function:  Check whether we need to use OFDM to sned MGNT frame for broadcom AP
501  *   input:  struct ieee80211_network *network   //current network we live
502  *  output:  none
503  *  return:  return 1 if true
504   * *****************************************************************************************************************/
505 static u8 HTIOTActIsMgntUseCCK6M(struct ieee80211_network *network)
506 {
507         u8      retValue = 0;
508
509         // 2008/01/25 MH Judeg if we need to use OFDM to sned MGNT frame for broadcom AP.
510         // 2008/01/28 MH We must prevent that we select null bssid to link.
511
512         if(network->broadcom_cap_exist)
513         {
514                 retValue = 1;
515         }
516
517         return retValue;
518 }
519
520 static u8 HTIOTActIsCCDFsync(u8 *PeerMacAddr)
521 {
522         u8      retValue = 0;
523         if(     (memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0) ||
524                 (memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0) ||
525                 (memcmp(PeerMacAddr, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) ==0))
526         {
527                 retValue = 1;
528         }
529
530         return retValue;
531 }
532
533 void HTResetIOTSetting(
534         PRT_HIGH_THROUGHPUT             pHTInfo
535 )
536 {
537         pHTInfo->IOTAction = 0;
538         pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
539 }
540
541
542 /********************************************************************************************************************
543  *function:  Construct Capablility Element in Beacon... if HTEnable is turned on
544  *   input:  struct ieee80211_device*   ieee
545  *           u8*                        posHTCap //pointer to store Capability Ele
546  *           u8*                        len //store length of CE
547  *           u8                         IsEncrypt //whether encrypt, needed further
548  *  output:  none
549  *  return:  none
550  *  notice:  posHTCap can't be null and should be initialized before.
551   * *****************************************************************************************************************/
552 void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u8 *len, u8 IsEncrypt)
553 {
554         PRT_HIGH_THROUGHPUT     pHT = ieee->pHTInfo;
555         PHT_CAPABILITY_ELE      pCapELE = NULL;
556         //u8 bIsDeclareMCS13;
557
558         if ((posHTCap == NULL) || (pHT == NULL))
559         {
560                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTCap or pHTInfo can't be null in HTConstructCapabilityElement()\n");
561                 return;
562         }
563         memset(posHTCap, 0, *len);
564         if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
565         {
566                 u8      EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};       // For 11n EWC definition, 2007.07.17, by Emily
567                 memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap));
568                 pCapELE = (PHT_CAPABILITY_ELE)&(posHTCap[4]);
569         }else
570         {
571                 pCapELE = (PHT_CAPABILITY_ELE)posHTCap;
572         }
573
574
575         //HT capability info
576         pCapELE->AdvCoding              = 0; // This feature is not supported now!!
577         if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
578         {
579                 pCapELE->ChlWidth = 0;
580         }
581         else
582         {
583                 pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0);
584         }
585
586 //      pCapELE->ChlWidth               = (pHT->bRegBW40MHz?1:0);
587         pCapELE->MimoPwrSave            = pHT->SelfMimoPs;
588         pCapELE->GreenField             = 0; // This feature is not supported now!!
589         pCapELE->ShortGI20Mhz           = 1; // We can receive Short GI!!
590         pCapELE->ShortGI40Mhz           = 1; // We can receive Short GI!!
591         //DbgPrint("TX HT cap/info ele BW=%d SG20=%d SG40=%d\n\r",
592                 //pCapELE->ChlWidth, pCapELE->ShortGI20Mhz, pCapELE->ShortGI40Mhz);
593         pCapELE->TxSTBC                 = 1;
594         pCapELE->RxSTBC                 = 0;
595         pCapELE->DelayBA                = 0;    // Do not support now!!
596         pCapELE->MaxAMSDUSize   = (MAX_RECEIVE_BUFFER_SIZE>=7935)?1:0;
597         pCapELE->DssCCk                 = ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0);
598         pCapELE->PSMP                   = 0; // Do not support now!!
599         pCapELE->LSigTxopProtect        = 0; // Do not support now!!
600
601
602         //MAC HT parameters info
603         // TODO: Nedd to take care of this part
604         IEEE80211_DEBUG(IEEE80211_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk);
605
606         if( IsEncrypt)
607         {
608                 pCapELE->MPDUDensity    = 7; // 8us
609                 pCapELE->MaxRxAMPDUFactor       = 2; // 2 is for 32 K and 3 is 64K
610         }
611         else
612         {
613                 pCapELE->MaxRxAMPDUFactor       = 3; // 2 is for 32 K and 3 is 64K
614                 pCapELE->MPDUDensity    = 0; // no density
615         }
616
617         //Supported MCS set
618         memcpy(pCapELE->MCS, ieee->Regdot11HTOperationalRateSet, 16);
619         if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS15)
620                 pCapELE->MCS[1] &= 0x7f;
621
622         if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS14)
623                 pCapELE->MCS[1] &= 0xbf;
624
625         if(pHT->IOTAction & HT_IOT_ACT_DISABLE_ALL_2SS)
626                 pCapELE->MCS[1] &= 0x00;
627
628         // 2008.06.12
629         // For RTL819X, if pairwisekey = wep/tkip, ap is ralink, we support only MCS0~7.
630         if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
631         {
632                 int i;
633                 for(i = 1; i< 16; i++)
634                         pCapELE->MCS[i] = 0;
635         }
636
637         //Extended HT Capability Info
638         memset(&pCapELE->ExtHTCapInfo, 0, 2);
639
640
641         //TXBF Capabilities
642         memset(pCapELE->TxBFCap, 0, 4);
643
644         //Antenna Selection Capabilities
645         pCapELE->ASCap = 0;
646 //add 2 to give space for element ID and len when construct frames
647         if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
648                 *len = 30 + 2;
649         else
650                 *len = 26 + 2;
651
652
653
654 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTCap, *len -2);
655
656         //Print each field in detail. Driver should not print out this message by default
657 //      HTDebugHTCapability(posHTCap, (u8*)"HTConstructCapability()");
658         return;
659
660 }
661 /********************************************************************************************************************
662  *function:  Construct  Information Element in Beacon... if HTEnable is turned on
663  *   input:  struct ieee80211_device*   ieee
664  *           u8*                        posHTCap //pointer to store Information Ele
665  *           u8*                        len   //store len of
666  *           u8                         IsEncrypt //whether encrypt, needed further
667  *  output:  none
668  *  return:  none
669  *  notice:  posHTCap can't be null and be initialized before. only AP and IBSS sta should do this
670   * *****************************************************************************************************************/
671 void HTConstructInfoElement(struct ieee80211_device *ieee, u8 *posHTInfo, u8 *len, u8 IsEncrypt)
672 {
673         PRT_HIGH_THROUGHPUT     pHT = ieee->pHTInfo;
674         PHT_INFORMATION_ELE             pHTInfoEle = (PHT_INFORMATION_ELE)posHTInfo;
675         if ((posHTInfo == NULL) || (pHTInfoEle == NULL))
676         {
677                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTInfo or pHTInfoEle can't be null in HTConstructInfoElement()\n");
678                 return;
679         }
680
681         memset(posHTInfo, 0, *len);
682         if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported
683         {
684                 pHTInfoEle->ControlChl                  = ieee->current_network.channel;
685                 pHTInfoEle->ExtChlOffset                        = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT:
686                                                                                         (ieee->current_network.channel<=6)?
687                                                                                                 HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER);
688                 pHTInfoEle->RecommemdedTxWidth  = pHT->bRegBW40MHz;
689                 pHTInfoEle->RIFS                                        = 0;
690                 pHTInfoEle->PSMPAccessOnly              = 0;
691                 pHTInfoEle->SrvIntGranularity           = 0;
692                 pHTInfoEle->OptMode                             = pHT->CurrentOpMode;
693                 pHTInfoEle->NonGFDevPresent             = 0;
694                 pHTInfoEle->DualBeacon                  = 0;
695                 pHTInfoEle->SecondaryBeacon             = 0;
696                 pHTInfoEle->LSigTxopProtectFull         = 0;
697                 pHTInfoEle->PcoActive                           = 0;
698                 pHTInfoEle->PcoPhase                            = 0;
699
700                 memset(pHTInfoEle->BasicMSC, 0, 16);
701
702
703                 *len = 22 + 2; //same above
704
705         }
706         else
707         {
708                 //STA should not generate High Throughput Information Element
709                 *len = 0;
710         }
711         //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTInfo, *len - 2);
712         //HTDebugHTInfo(posHTInfo, "HTConstructInforElement");
713         return;
714 }
715
716 /*
717   *  According to experiment, Realtek AP to STA (based on rtl8190) may achieve best performance
718   *  if both STA and AP set limitation of aggregation size to 32K, that is, set AMPDU density to 2
719   *  (Ref: IEEE 11n specification). However, if Realtek STA associates to other AP, STA should set
720   *  limitation of aggregation size to 8K, otherwise, performance of traffic stream from STA to AP
721   *  will be much less than the traffic stream from AP to STA if both of the stream runs concurrently
722   *  at the same time.
723   *
724   *  Frame Format
725   *  Element ID         Length          OUI                     Type1           Reserved
726   *  1 byte                     1 byte          3 bytes         1 byte          1 byte
727   *
728   *  OUI                = 0x00, 0xe0, 0x4c,
729   *  Type       = 0x02
730   *  Reserved   = 0x00
731   *
732   *  2007.8.21 by Emily
733 */
734 /********************************************************************************************************************
735  *function:  Construct  Information Element in Beacon... in RT2RT condition
736  *   input:  struct ieee80211_device*   ieee
737  *           u8*                        posRT2RTAgg //pointer to store Information Ele
738  *           u8*                        len   //store len
739  *  output:  none
740  *  return:  none
741  *  notice:
742   * *****************************************************************************************************************/
743 void HTConstructRT2RTAggElement(struct ieee80211_device *ieee, u8 *posRT2RTAgg, u8 *len)
744 {
745         if (posRT2RTAgg == NULL) {
746                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "posRT2RTAgg can't be null in HTConstructRT2RTAggElement()\n");
747                 return;
748         }
749         memset(posRT2RTAgg, 0, *len);
750         *posRT2RTAgg++ = 0x00;
751         *posRT2RTAgg++ = 0xe0;
752         *posRT2RTAgg++ = 0x4c;
753         *posRT2RTAgg++ = 0x02;
754         *posRT2RTAgg++ = 0x01;
755         *posRT2RTAgg = 0x10;//*posRT2RTAgg = 0x02;
756
757         if(ieee->bSupportRemoteWakeUp) {
758                 *posRT2RTAgg |= 0x08;//RT_HT_CAP_USE_WOW;
759         }
760
761         *len = 6 + 2;
762         return;
763 #ifdef TODO
764 #if (HAL_CODE_BASE == RTL8192 && DEV_BUS_TYPE == USB_INTERFACE)
765         /*
766         //Emily. If it is required to Ask Realtek AP to send AMPDU during AES mode, enable this
767            section of code.
768         if(IS_UNDER_11N_AES_MODE(Adapter))
769         {
770                 posRT2RTAgg->Octet[5] |=RT_HT_CAP_USE_AMPDU;
771         }else
772         {
773                 posRT2RTAgg->Octet[5] &= 0xfb;
774         }
775         */
776
777 #else
778         // Do Nothing
779 #endif
780
781         posRT2RTAgg->Length = 6;
782 #endif
783
784
785
786
787 }
788
789
790 /********************************************************************************************************************
791  *function:  Pick the right Rate Adaptive table to use
792  *   input:  struct ieee80211_device*   ieee
793  *           u8*                        pOperateMCS //A pointer to MCS rate bitmap
794  *  return:  always we return true
795  *  notice:
796   * *****************************************************************************************************************/
797 static u8 HT_PickMCSRate(struct ieee80211_device *ieee, u8 *pOperateMCS)
798 {
799         u8                                      i;
800         if (pOperateMCS == NULL)
801         {
802                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "pOperateMCS can't be null in HT_PickMCSRate()\n");
803                 return false;
804         }
805
806         switch (ieee->mode)
807         {
808         case IEEE_A:
809         case IEEE_B:
810         case IEEE_G:
811                         //legacy rate routine handled at selectedrate
812
813                         //no MCS rate
814                         for(i=0;i<=15;i++){
815                                 pOperateMCS[i] = 0;
816                         }
817                         break;
818
819         case IEEE_N_24G:        //assume CCK rate ok
820         case IEEE_N_5G:
821                         // Legacy part we only use 6, 5.5,2,1 for N_24G and 6 for N_5G.
822                         // Legacy part shall be handled at SelectRateSet().
823
824                         //HT part
825                         // TODO: may be different if we have different number of antenna
826                         pOperateMCS[0] &=RATE_ADPT_1SS_MASK;    //support MCS 0~7
827                         pOperateMCS[1] &=RATE_ADPT_2SS_MASK;
828                         pOperateMCS[3] &=RATE_ADPT_MCS32_MASK;
829                         break;
830
831         //should never reach here
832         default:
833
834                         break;
835
836         }
837
838         return true;
839 }
840
841 /*
842 *       Description:
843 *               This function will get the highest speed rate in input MCS set.
844 *
845 *       /param  Adapter                 Pionter to Adapter entity
846 *                       pMCSRateSet             Pointer to MCS rate bitmap
847 *                       pMCSFilter              Pointer to MCS rate filter
848 *
849 *       /return Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter.
850 *
851 */
852 /********************************************************************************************************************
853  *function:  This function will get the highest speed rate in input MCS set.
854  *   input:  struct ieee80211_device*   ieee
855  *           u8*                        pMCSRateSet //Pointer to MCS rate bitmap
856  *           u8*                        pMCSFilter //Pointer to MCS rate filter
857  *  return:  Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter
858  *  notice:
859   * *****************************************************************************************************************/
860 u8 HTGetHighestMCSRate(struct ieee80211_device *ieee, u8 *pMCSRateSet, u8 *pMCSFilter)
861 {
862         u8              i, j;
863         u8              bitMap;
864         u8              mcsRate = 0;
865         u8              availableMcsRate[16];
866         if (pMCSRateSet == NULL || pMCSFilter == NULL)
867         {
868                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "pMCSRateSet or pMCSFilter can't be null in HTGetHighestMCSRate()\n");
869                 return false;
870         }
871         for(i=0; i<16; i++)
872                 availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i];
873
874         for(i = 0; i < 16; i++)
875         {
876                 if(availableMcsRate[i] != 0)
877                         break;
878         }
879         if(i == 16)
880                 return false;
881
882         for(i = 0; i < 16; i++)
883         {
884                 if(availableMcsRate[i] != 0)
885                 {
886                         bitMap = availableMcsRate[i];
887                         for(j = 0; j < 8; j++)
888                         {
889                                 if((bitMap%2) != 0)
890                                 {
891                                         if(HTMcsToDataRate(ieee, (8*i+j)) > HTMcsToDataRate(ieee, mcsRate))
892                                                 mcsRate = (8*i+j);
893                                 }
894                                 bitMap = bitMap>>1;
895                         }
896                 }
897         }
898         return (mcsRate|0x80);
899 }
900
901
902
903 /*
904 **
905 **1.Filter our operation rate set with AP's rate set
906 **2.shall reference channel bandwidth, STBC, Antenna number
907 **3.generate rate adative table for firmware
908 **David 20060906
909 **
910 ** \pHTSupportedCap: the connected STA's supported rate Capability element
911 */
912 static u8 HTFilterMCSRate(struct ieee80211_device *ieee, u8 *pSupportMCS,
913                           u8 *pOperateMCS)
914 {
915
916         u8 i=0;
917
918         // filter out operational rate set not supported by AP, the length of it is 16
919         for(i=0;i<=15;i++){
920                 pOperateMCS[i] = ieee->Regdot11HTOperationalRateSet[i]&pSupportMCS[i];
921         }
922
923
924         // TODO: adjust our operational rate set  according to our channel bandwidth, STBC and Antenna number
925
926         // TODO: fill suggested rate adaptive rate index and give firmware info using Tx command packet
927         // we also shall suggested the first start rate set according to our singal strength
928         HT_PickMCSRate(ieee, pOperateMCS);
929
930         // For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
931         if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
932                 pOperateMCS[1] = 0;
933
934         //
935         // For RTL819X, we support only MCS0~15.
936         // And also, we do not know how to use MCS32 now.
937         //
938         for(i=2; i<=15; i++)
939                 pOperateMCS[i] = 0;
940
941         return true;
942 }
943 void HTSetConnectBwMode(struct ieee80211_device *ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset);
944 void HTOnAssocRsp(struct ieee80211_device *ieee)
945 {
946         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
947         PHT_CAPABILITY_ELE              pPeerHTCap = NULL;
948         PHT_INFORMATION_ELE             pPeerHTInfo = NULL;
949         u16     nMaxAMSDUSize = 0;
950         u8      *pMcsFilter = NULL;
951
952         static u8                               EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};               // For 11n EWC definition, 2007.07.17, by Emily
953         static u8                               EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};      // For 11n EWC definition, 2007.07.17, by Emily
954
955         if( pHTInfo->bCurrentHTSupport == false )
956         {
957                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n");
958                 return;
959         }
960         IEEE80211_DEBUG(IEEE80211_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n");
961 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(HT_CAPABILITY_ELE));
962 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTInfoBuf, sizeof(HT_INFORMATION_ELE));
963
964 //      HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq");
965 //      HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq");
966         //
967         if(!memcmp(pHTInfo->PeerHTCapBuf,EWC11NHTCap, sizeof(EWC11NHTCap)))
968                 pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]);
969         else
970                 pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf);
971
972         if(!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
973                 pPeerHTInfo = (PHT_INFORMATION_ELE)(&pHTInfo->PeerHTInfoBuf[4]);
974         else
975                 pPeerHTInfo = (PHT_INFORMATION_ELE)(pHTInfo->PeerHTInfoBuf);
976
977
978         ////////////////////////////////////////////////////////
979         // Configurations:
980         ////////////////////////////////////////////////////////
981         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTCap, sizeof(HT_CAPABILITY_ELE));
982 //      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTInfo, sizeof(HT_INFORMATION_ELE));
983         // Config Supported Channel Width setting
984         //
985         HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));
986
987 //      if(pHTInfo->bCurBW40MHz == true)
988                 pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false);
989
990         //
991         // Update short GI/ long GI setting
992         //
993         // TODO:
994         pHTInfo->bCurShortGI20MHz=
995                 ((pHTInfo->bRegShortGI20MHz)?((pPeerHTCap->ShortGI20Mhz==1)?true:false):false);
996         pHTInfo->bCurShortGI40MHz=
997                 ((pHTInfo->bRegShortGI40MHz)?((pPeerHTCap->ShortGI40Mhz==1)?true:false):false);
998
999         //
1000         // Config TX STBC setting
1001         //
1002         // TODO:
1003
1004         //
1005         // Config DSSS/CCK  mode in 40MHz mode
1006         //
1007         // TODO:
1008         pHTInfo->bCurSuppCCK =
1009                 ((pHTInfo->bRegSuppCCK)?((pPeerHTCap->DssCCk==1)?true:false):false);
1010
1011
1012         //
1013         // Config and configure A-MSDU setting
1014         //
1015         pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
1016
1017         nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize==0)?3839:7935;
1018
1019         if(pHTInfo->nAMSDU_MaxSize > nMaxAMSDUSize )
1020                 pHTInfo->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize;
1021         else
1022                 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1023
1024
1025         //
1026         // Config A-MPDU setting
1027         //
1028         pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
1029
1030         // <1> Decide AMPDU Factor
1031
1032         // By Emily
1033         if(!pHTInfo->bRegRT2RTAggregation)
1034         {
1035                 // Decide AMPDU Factor according to protocol handshake
1036                 if(pHTInfo->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor)
1037                         pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1038                 else
1039                         pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1040
1041         }else
1042         {
1043                 // Set MPDU density to 2 to Realtek AP, and set it to 0 for others
1044                 // Replace MPDU factor declared in original association response frame format. 2007.08.20 by Emily
1045                 if (ieee->current_network.bssht.bdRT2RTAggregation)
1046                 {
1047                         if( ieee->pairwise_key_type != KEY_TYPE_NA)
1048                                 // Realtek may set 32k in security mode and 64k for others
1049                                 pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1050                         else
1051                                 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
1052                 }else
1053                 {
1054                         if(pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K)
1055                                 pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1056                         else
1057                                 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K;
1058                 }
1059         }
1060
1061         // <2> Set AMPDU Minimum MPDU Start Spacing
1062         // 802.11n 3.0 section 9.7d.3
1063         if(pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
1064                 pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1065         else
1066                 pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
1067         if(ieee->pairwise_key_type != KEY_TYPE_NA )
1068                 pHTInfo->CurrentMPDUDensity     = 7; // 8us
1069         // Force TX AMSDU
1070
1071         // Lanhsin: mark for tmp to avoid deauth by ap from  s3
1072         //if(memcmp(pMgntInfo->Bssid, NETGEAR834Bv2_BROADCOM, 3)==0)
1073         if(0)
1074                 {
1075
1076                         pHTInfo->bCurrentAMPDUEnable = false;
1077                         pHTInfo->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE;
1078                         pHTInfo->ForcedAMSDUMaxSize = 7935;
1079
1080                 pHTInfo->IOTAction |=  HT_IOT_ACT_TX_USE_AMSDU_8K;
1081         }
1082
1083         // Rx Reorder Setting
1084         pHTInfo->bCurRxReorderEnable = pHTInfo->bRegRxReorderEnable;
1085
1086         //
1087         // Filter out unsupported HT rate for this AP
1088         // Update RATR table
1089         // This is only for 8190 ,8192 or later product which using firmware to handle rate adaptive mechanism.
1090         //
1091
1092         // Handle Ralink AP bad MCS rate set condition. Joseph.
1093         // This fix the bug of Ralink AP. This may be removed in the future.
1094         if(pPeerHTCap->MCS[0] == 0)
1095                 pPeerHTCap->MCS[0] = 0xff;
1096
1097         HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11HTOperationalRateSet);
1098
1099         //
1100         // Config MIMO Power Save setting
1101         //
1102         pHTInfo->PeerMimoPs = pPeerHTCap->MimoPwrSave;
1103         if(pHTInfo->PeerMimoPs == MIMO_PS_STATIC)
1104                 pMcsFilter = MCS_FILTER_1SS;
1105         else
1106                 pMcsFilter = MCS_FILTER_ALL;
1107         //WB add for MCS8 bug
1108 //      pMcsFilter = MCS_FILTER_1SS;
1109         ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, pMcsFilter);
1110         ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
1111
1112         //
1113         // Config current operation mode.
1114         //
1115         pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1116
1117
1118
1119 }
1120
1121 void HTSetConnectBwModeCallback(struct ieee80211_device *ieee);
1122 /********************************************************************************************************************
1123  *function:  initialize HT info(struct PRT_HIGH_THROUGHPUT)
1124  *   input:  struct ieee80211_device*   ieee
1125  *  output:  none
1126  *  return:  none
1127  *  notice: This function is called when *  (1) MPInitialization Phase *  (2) Receiving of Deauthentication from AP
1128 ********************************************************************************************************************/
1129 // TODO: Should this funciton be called when receiving of Disassociation?
1130 void HTInitializeHTInfo(struct ieee80211_device *ieee)
1131 {
1132         PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1133
1134         //
1135         // These parameters will be reset when receiving deauthentication packet
1136         //
1137         IEEE80211_DEBUG(IEEE80211_DL_HT, "===========>%s()\n", __FUNCTION__);
1138         pHTInfo->bCurrentHTSupport = false;
1139
1140         // 40MHz channel support
1141         pHTInfo->bCurBW40MHz = false;
1142         pHTInfo->bCurTxBW40MHz = false;
1143
1144         // Short GI support
1145         pHTInfo->bCurShortGI20MHz = false;
1146         pHTInfo->bCurShortGI40MHz = false;
1147         pHTInfo->bForcedShortGI = false;
1148
1149         // CCK rate support
1150         // This flag is set to true to support CCK rate by default.
1151         // It will be affected by "pHTInfo->bRegSuppCCK" and AP capabilities only when associate to
1152         // 11N BSS.
1153         pHTInfo->bCurSuppCCK = true;
1154
1155         // AMSDU related
1156         pHTInfo->bCurrent_AMSDU_Support = false;
1157         pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1158
1159         // AMPUD related
1160         pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1161         pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1162
1163
1164
1165         // Initialize all of the parameters related to 11n
1166         memset((void *)(&(pHTInfo->SelfHTCap)), 0, sizeof(pHTInfo->SelfHTCap));
1167         memset((void *)(&(pHTInfo->SelfHTInfo)), 0, sizeof(pHTInfo->SelfHTInfo));
1168         memset((void *)(&(pHTInfo->PeerHTCapBuf)), 0, sizeof(pHTInfo->PeerHTCapBuf));
1169         memset((void *)(&(pHTInfo->PeerHTInfoBuf)), 0, sizeof(pHTInfo->PeerHTInfoBuf));
1170
1171         pHTInfo->bSwBwInProgress = false;
1172         pHTInfo->ChnlOp = CHNLOP_NONE;
1173
1174         // Set default IEEE spec for Draft N
1175         pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE;
1176
1177         // Realtek proprietary aggregation mode
1178         pHTInfo->bCurrentRT2RTAggregation = false;
1179         pHTInfo->bCurrentRT2RTLongSlotTime = false;
1180         pHTInfo->IOTPeer = 0;
1181         pHTInfo->IOTAction = 0;
1182
1183         //MCS rate initialized here
1184         {
1185                 u8 *RegHTSuppRateSets = &(ieee->RegHTSuppRateSet[0]);
1186                 RegHTSuppRateSets[0] = 0xFF;    //support MCS 0~7
1187                 RegHTSuppRateSets[1] = 0xFF;    //support MCS 8~15
1188                 RegHTSuppRateSets[4] = 0x01;    //support MCS 32
1189         }
1190 }
1191 /********************************************************************************************************************
1192  *function:  initialize Bss HT structure(struct PBSS_HT)
1193  *   input:  PBSS_HT pBssHT //to be initialized
1194  *  output:  none
1195  *  return:  none
1196  *  notice: This function is called when initialize network structure
1197 ********************************************************************************************************************/
1198 void HTInitializeBssDesc(PBSS_HT pBssHT)
1199 {
1200
1201         pBssHT->bdSupportHT = false;
1202         memset(pBssHT->bdHTCapBuf, 0, sizeof(pBssHT->bdHTCapBuf));
1203         pBssHT->bdHTCapLen = 0;
1204         memset(pBssHT->bdHTInfoBuf, 0, sizeof(pBssHT->bdHTInfoBuf));
1205         pBssHT->bdHTInfoLen = 0;
1206
1207         pBssHT->bdHTSpecVer= HT_SPEC_VER_IEEE;
1208
1209         pBssHT->bdRT2RTAggregation = false;
1210         pBssHT->bdRT2RTLongSlotTime = false;
1211 }
1212 /********************************************************************************************************************
1213  *function:  initialize Bss HT structure(struct PBSS_HT)
1214  *   input:  struct ieee80211_device    *ieee
1215  *           struct ieee80211_network   *pNetwork //usually current network we are live in
1216  *  output:  none
1217  *  return:  none
1218  *  notice: This function should ONLY be called before association
1219 ********************************************************************************************************************/
1220 void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee,       struct ieee80211_network *pNetwork)
1221 {
1222         PRT_HIGH_THROUGHPUT             pHTInfo = ieee->pHTInfo;
1223 //      u16                                             nMaxAMSDUSize;
1224 //      PHT_CAPABILITY_ELE              pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1225 //      PHT_INFORMATION_ELE             pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1226 //      u8*     pMcsFilter;
1227         u8      bIOTAction = 0;
1228
1229         //
1230         //  Save Peer Setting before Association
1231         //
1232         IEEE80211_DEBUG(IEEE80211_DL_HT, "==============>%s()\n", __FUNCTION__);
1233         /*unmark bEnableHT flag here is the same reason why unmarked in function ieee80211_softmac_new_net. WB 2008.09.10*/
1234 //      if( pHTInfo->bEnableHT &&  pNetwork->bssht.bdSupportHT)
1235         if (pNetwork->bssht.bdSupportHT)
1236         {
1237                 pHTInfo->bCurrentHTSupport = true;
1238                 pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer;
1239
1240                 // Save HTCap and HTInfo information Element
1241                 if(pNetwork->bssht.bdHTCapLen > 0 &&    pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf))
1242                         memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen);
1243
1244                 if(pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf))
1245                         memcpy(pHTInfo->PeerHTInfoBuf, pNetwork->bssht.bdHTInfoBuf, pNetwork->bssht.bdHTInfoLen);
1246
1247                 // Check whether RT to RT aggregation mode is enabled
1248                 if(pHTInfo->bRegRT2RTAggregation)
1249                 {
1250                         pHTInfo->bCurrentRT2RTAggregation = pNetwork->bssht.bdRT2RTAggregation;
1251                         pHTInfo->bCurrentRT2RTLongSlotTime = pNetwork->bssht.bdRT2RTLongSlotTime;
1252                 }
1253                 else
1254                 {
1255                         pHTInfo->bCurrentRT2RTAggregation = false;
1256                         pHTInfo->bCurrentRT2RTLongSlotTime = false;
1257                 }
1258
1259                 // Determine the IOT Peer Vendor.
1260                 HTIOTPeerDetermine(ieee);
1261
1262                 // Decide IOT Action
1263                 // Must be called after the parameter of pHTInfo->bCurrentRT2RTAggregation is decided
1264                 pHTInfo->IOTAction = 0;
1265                 bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid);
1266                 if(bIOTAction)
1267                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS14;
1268
1269                 bIOTAction = HTIOTActIsDisableMCS15(ieee);
1270                 if(bIOTAction)
1271                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS15;
1272
1273                 bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee, pNetwork->bssid);
1274                 if(bIOTAction)
1275                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_ALL_2SS;
1276
1277
1278                 bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid);
1279                 if(bIOTAction)
1280                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_EDCA_TURBO;
1281
1282                 bIOTAction = HTIOTActIsMgntUseCCK6M(pNetwork);
1283                 if(bIOTAction)
1284                         pHTInfo->IOTAction |= HT_IOT_ACT_MGNT_USE_CCK_6M;
1285
1286                 bIOTAction = HTIOTActIsCCDFsync(pNetwork->bssid);
1287                 if(bIOTAction)
1288                         pHTInfo->IOTAction |= HT_IOT_ACT_CDD_FSYNC;
1289
1290
1291         }
1292         else
1293         {
1294                 pHTInfo->bCurrentHTSupport = false;
1295                 pHTInfo->bCurrentRT2RTAggregation = false;
1296                 pHTInfo->bCurrentRT2RTLongSlotTime = false;
1297
1298                 pHTInfo->IOTAction = 0;
1299         }
1300
1301 }
1302
1303 void HTUpdateSelfAndPeerSetting(struct ieee80211_device *ieee,  struct ieee80211_network *pNetwork)
1304 {
1305         PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
1306 //      PHT_CAPABILITY_ELE              pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1307         PHT_INFORMATION_ELE             pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1308
1309         if(pHTInfo->bCurrentHTSupport)
1310         {
1311                 //
1312                 // Config current operation mode.
1313                 //
1314                 if(pNetwork->bssht.bdHTInfoLen != 0)
1315                         pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1316
1317                 //
1318                 // <TODO: Config according to OBSS non-HT STA present!!>
1319                 //
1320         }
1321 }
1322
1323 /********************************************************************************************************************
1324  *function:  check whether HT control field exists
1325  *   input:  struct ieee80211_device    *ieee
1326  *           u8*                        pFrame //coming skb->data
1327  *  output:  none
1328  *  return:  return true if HT control field exists(false otherwise)
1329  *  notice:
1330 ********************************************************************************************************************/
1331 u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame)
1332 {
1333         if(ieee->pHTInfo->bCurrentHTSupport)
1334         {
1335                 if( (IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1)
1336                 {
1337                         IEEE80211_DEBUG(IEEE80211_DL_HT, "HT CONTROL FILED EXIST!!\n");
1338                         return true;
1339                 }
1340         }
1341         return false;
1342 }
1343
1344 //
1345 // This function set bandwidth mode in protocol layer.
1346 //
1347 void HTSetConnectBwMode(struct ieee80211_device *ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset)
1348 {
1349         PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1350 //      u32 flags = 0;
1351
1352         if(pHTInfo->bRegBW40MHz == false)
1353                 return;
1354
1355
1356
1357         // To reduce dummy operation
1358 //      if((pHTInfo->bCurBW40MHz==false && Bandwidth==HT_CHANNEL_WIDTH_20) ||
1359 //         (pHTInfo->bCurBW40MHz==true && Bandwidth==HT_CHANNEL_WIDTH_20_40 && Offset==pHTInfo->CurSTAExtChnlOffset))
1360 //              return;
1361
1362 //      spin_lock_irqsave(&(ieee->bw_spinlock), flags);
1363         if(pHTInfo->bSwBwInProgress) {
1364 //              spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1365                 return;
1366         }
1367         //if in half N mode, set to 20M bandwidth please 09.08.2008 WB.
1368         if(Bandwidth==HT_CHANNEL_WIDTH_20_40 && (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)))
1369          {
1370                         // Handle Illegal extension channel offset!!
1371                 if(ieee->current_network.channel<2 && Offset==HT_EXTCHNL_OFFSET_LOWER)
1372                         Offset = HT_EXTCHNL_OFFSET_NO_EXT;
1373                 if(Offset==HT_EXTCHNL_OFFSET_UPPER || Offset==HT_EXTCHNL_OFFSET_LOWER) {
1374                         pHTInfo->bCurBW40MHz = true;
1375                         pHTInfo->CurSTAExtChnlOffset = Offset;
1376                 } else {
1377                         pHTInfo->bCurBW40MHz = false;
1378                         pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1379                 }
1380         } else {
1381                 pHTInfo->bCurBW40MHz = false;
1382                 pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1383         }
1384
1385         pHTInfo->bSwBwInProgress = true;
1386
1387         // TODO: 2007.7.13 by Emily Wait 2000ms  in order to guarantee that switching
1388         //   bandwidth is executed after scan is finished. It is a temporal solution
1389         //   because software should ganrantee the last operation of switching bandwidth
1390         //   is executed properlly.
1391         HTSetConnectBwModeCallback(ieee);
1392
1393 //      spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1394 }
1395
1396 void HTSetConnectBwModeCallback(struct ieee80211_device *ieee)
1397 {
1398         PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1399
1400         IEEE80211_DEBUG(IEEE80211_DL_HT, "======>%s()\n", __FUNCTION__);
1401
1402         if(pHTInfo->bCurBW40MHz)
1403         {
1404                 if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_UPPER)
1405                         ieee->set_chan(ieee->dev, ieee->current_network.channel+2);
1406                 else if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_LOWER)
1407                         ieee->set_chan(ieee->dev, ieee->current_network.channel-2);
1408                 else
1409                         ieee->set_chan(ieee->dev, ieee->current_network.channel);
1410
1411                 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, pHTInfo->CurSTAExtChnlOffset);
1412         } else {
1413                 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1414                 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1415         }
1416
1417         pHTInfo->bSwBwInProgress = false;
1418 }
1419
1420 EXPORT_SYMBOL(HTUpdateSelfAndPeerSetting);