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