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  * *****************************************************************************************************************/
HTUpdateDefaultSetting(struct ieee80211_device * ieee)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  * *****************************************************************************************************************/
HTDebugHTCapability(u8 * CapIE,u8 * TitleString)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  * *****************************************************************************************************************/
HTDebugHTInfo(u8 * InfoIE,u8 * TitleString)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 */
IsHTHalfNmode40Bandwidth(struct ieee80211_device * ieee)222 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 
IsHTHalfNmodeSGI(struct ieee80211_device * ieee,bool is40MHz)241 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 
HTHalfMcsToDataRate(struct ieee80211_device * ieee,u8 nMcsRate)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 
HTMcsToDataRate(struct ieee80211_device * ieee,u8 nMcsRate)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  * *****************************************************************************************************************/
TxCountToDataRate(struct ieee80211_device * ieee,u8 nDataRate)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 
IsHTHalfNmodeAPs(struct ieee80211_device * ieee)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  * *****************************************************************************************************************/
HTIOTPeerDetermine(struct ieee80211_device * ieee)379 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   * *****************************************************************************************************************/
HTIOTActIsDisableMCS14(struct ieee80211_device * ieee,u8 * PeerMacAddr)416 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 */
HTIOTActIsDisableMCS15(struct ieee80211_device * ieee)435 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 */
HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device * ieee,u8 * PeerMacAddr)472 bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee, u8 *PeerMacAddr)
473 {
474 	bool retValue = false;
475 
476 #ifdef TODO
477 	// Apply for 819u only
478 #endif
479 	return retValue;
480 }
481 
482 /********************************************************************************************************************
483  *function:  Check whether driver should disable EDCA turbo mode
484  *   input:  struct ieee80211_device* 	ieee
485  *   	     u8* 			PeerMacAddr
486  *  output:  none
487  *  return:  return 1 if driver should disable EDCA turbo mode(otherwise return 0)
488   * *****************************************************************************************************************/
HTIOTActIsDisableEDCATurbo(struct ieee80211_device * ieee,u8 * PeerMacAddr)489 u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device* 	ieee, u8* PeerMacAddr)
490 {
491 	u8	retValue = false;	// default enable EDCA Turbo mode.
492 	// Set specific EDCA parameter for different AP in DM handler.
493 
494 	return retValue;
495 }
496 
497 /********************************************************************************************************************
498  *function:  Check whether we need to use OFDM to sned MGNT frame for broadcom AP
499  *   input:  struct ieee80211_network *network   //current network we live
500  *  output:  none
501  *  return:  return 1 if true
502   * *****************************************************************************************************************/
HTIOTActIsMgntUseCCK6M(struct ieee80211_network * network)503 u8 HTIOTActIsMgntUseCCK6M(struct ieee80211_network *network)
504 {
505 	u8	retValue = 0;
506 
507 	// 2008/01/25 MH Judeg if we need to use OFDM to sned MGNT frame for broadcom AP.
508 	// 2008/01/28 MH We must prevent that we select null bssid to link.
509 
510 	if(network->broadcom_cap_exist)
511 	{
512 		retValue = 1;
513 	}
514 
515 	return retValue;
516 }
517 
HTIOTActIsCCDFsync(u8 * PeerMacAddr)518 u8 HTIOTActIsCCDFsync(u8* PeerMacAddr)
519 {
520 	u8	retValue = 0;
521 	if(	(memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0) ||
522 		(memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0) ||
523 		(memcmp(PeerMacAddr, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) ==0))
524 	{
525 		retValue = 1;
526 	}
527 
528 	return retValue;
529 }
530 
HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo)531 void HTResetIOTSetting(
532 	PRT_HIGH_THROUGHPUT		pHTInfo
533 )
534 {
535 	pHTInfo->IOTAction = 0;
536 	pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
537 }
538 
539 
540 /********************************************************************************************************************
541  *function:  Construct Capablility Element in Beacon... if HTEnable is turned on
542  *   input:  struct ieee80211_device* 	ieee
543  *   	     u8* 			posHTCap //pointer to store Capability Ele
544  *   	     u8*			len //store length of CE
545  *   	     u8				IsEncrypt //whether encrypt, needed further
546  *  output:  none
547  *  return:  none
548  *  notice:  posHTCap can't be null and should be initialized before.
549   * *****************************************************************************************************************/
HTConstructCapabilityElement(struct ieee80211_device * ieee,u8 * posHTCap,u8 * len,u8 IsEncrypt)550 void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u8* len, u8 IsEncrypt)
551 {
552 	PRT_HIGH_THROUGHPUT	pHT = ieee->pHTInfo;
553 	PHT_CAPABILITY_ELE 	pCapELE = NULL;
554 	//u8 bIsDeclareMCS13;
555 
556 	if ((posHTCap == NULL) || (pHT == NULL))
557 	{
558 		IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTCap or pHTInfo can't be null in HTConstructCapabilityElement()\n");
559 		return;
560 	}
561 	memset(posHTCap, 0, *len);
562 	if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
563 	{
564 		u8	EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};	// For 11n EWC definition, 2007.07.17, by Emily
565 		memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap));
566 		pCapELE = (PHT_CAPABILITY_ELE)&(posHTCap[4]);
567 	}else
568 	{
569 		pCapELE = (PHT_CAPABILITY_ELE)posHTCap;
570 	}
571 
572 
573 	//HT capability info
574 	pCapELE->AdvCoding 		= 0; // This feature is not supported now!!
575 	if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
576 	{
577 		pCapELE->ChlWidth = 0;
578 	}
579 	else
580 	{
581 		pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0);
582 	}
583 
584 //	pCapELE->ChlWidth 		= (pHT->bRegBW40MHz?1:0);
585 	pCapELE->MimoPwrSave 		= pHT->SelfMimoPs;
586 	pCapELE->GreenField		= 0; // This feature is not supported now!!
587 	pCapELE->ShortGI20Mhz		= 1; // We can receive Short GI!!
588 	pCapELE->ShortGI40Mhz		= 1; // We can receive Short GI!!
589 	//DbgPrint("TX HT cap/info ele BW=%d SG20=%d SG40=%d\n\r",
590 		//pCapELE->ChlWidth, pCapELE->ShortGI20Mhz, pCapELE->ShortGI40Mhz);
591 	pCapELE->TxSTBC 		= 1;
592 	pCapELE->RxSTBC 		= 0;
593 	pCapELE->DelayBA		= 0;	// Do not support now!!
594 	pCapELE->MaxAMSDUSize	= (MAX_RECEIVE_BUFFER_SIZE>=7935)?1:0;
595 	pCapELE->DssCCk 		= ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0);
596 	pCapELE->PSMP			= 0; // Do not support now!!
597 	pCapELE->LSigTxopProtect	= 0; // Do not support now!!
598 
599 
600 	//MAC HT parameters info
601 	// TODO: Nedd to take care of this part
602 	IEEE80211_DEBUG(IEEE80211_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk);
603 
604 	if( IsEncrypt)
605 	{
606 		pCapELE->MPDUDensity 	= 7; // 8us
607 		pCapELE->MaxRxAMPDUFactor 	= 2; // 2 is for 32 K and 3 is 64K
608 	}
609 	else
610 	{
611 		pCapELE->MaxRxAMPDUFactor 	= 3; // 2 is for 32 K and 3 is 64K
612 		pCapELE->MPDUDensity 	= 0; // no density
613 	}
614 
615 	//Supported MCS set
616 	memcpy(pCapELE->MCS, ieee->Regdot11HTOperationalRateSet, 16);
617 	if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS15)
618 		pCapELE->MCS[1] &= 0x7f;
619 
620 	if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS14)
621 		pCapELE->MCS[1] &= 0xbf;
622 
623 	if(pHT->IOTAction & HT_IOT_ACT_DISABLE_ALL_2SS)
624 		pCapELE->MCS[1] &= 0x00;
625 
626 	// 2008.06.12
627 	// For RTL819X, if pairwisekey = wep/tkip, ap is ralink, we support only MCS0~7.
628 	if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
629 	{
630 		int i;
631 		for(i = 1; i< 16; i++)
632 			pCapELE->MCS[i] = 0;
633 	}
634 
635 	//Extended HT Capability Info
636 	memset(&pCapELE->ExtHTCapInfo, 0, 2);
637 
638 
639 	//TXBF Capabilities
640 	memset(pCapELE->TxBFCap, 0, 4);
641 
642 	//Antenna Selection Capabilities
643 	pCapELE->ASCap = 0;
644 //add 2 to give space for element ID and len when construct frames
645 	if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
646 		*len = 30 + 2;
647 	else
648 		*len = 26 + 2;
649 
650 
651 
652 //	IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTCap, *len -2);
653 
654 	//Print each field in detail. Driver should not print out this message by default
655 //	HTDebugHTCapability(posHTCap, (u8*)"HTConstructCapability()");
656 	return;
657 
658 }
659 /********************************************************************************************************************
660  *function:  Construct  Information Element in Beacon... if HTEnable is turned on
661  *   input:  struct ieee80211_device* 	ieee
662  *   	     u8* 			posHTCap //pointer to store Information Ele
663  *   	     u8*			len   //store len of
664  *   	     u8				IsEncrypt //whether encrypt, needed further
665  *  output:  none
666  *  return:  none
667  *  notice:  posHTCap can't be null and be initialized before. only AP and IBSS sta should do this
668   * *****************************************************************************************************************/
HTConstructInfoElement(struct ieee80211_device * ieee,u8 * posHTInfo,u8 * len,u8 IsEncrypt)669 void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* len, u8 IsEncrypt)
670 {
671 	PRT_HIGH_THROUGHPUT	pHT = ieee->pHTInfo;
672 	PHT_INFORMATION_ELE		pHTInfoEle = (PHT_INFORMATION_ELE)posHTInfo;
673 	if ((posHTInfo == NULL) || (pHTInfoEle == NULL))
674 	{
675 		IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTInfo or pHTInfoEle can't be null in HTConstructInfoElement()\n");
676 		return;
677 	}
678 
679 	memset(posHTInfo, 0, *len);
680 	if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported
681 	{
682 		pHTInfoEle->ControlChl 			= ieee->current_network.channel;
683 		pHTInfoEle->ExtChlOffset 			= ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT:
684 											(ieee->current_network.channel<=6)?
685 												HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER);
686 		pHTInfoEle->RecommemdedTxWidth	= pHT->bRegBW40MHz;
687 		pHTInfoEle->RIFS 					= 0;
688 		pHTInfoEle->PSMPAccessOnly		= 0;
689 		pHTInfoEle->SrvIntGranularity		= 0;
690 		pHTInfoEle->OptMode				= pHT->CurrentOpMode;
691 		pHTInfoEle->NonGFDevPresent		= 0;
692 		pHTInfoEle->DualBeacon			= 0;
693 		pHTInfoEle->SecondaryBeacon		= 0;
694 		pHTInfoEle->LSigTxopProtectFull		= 0;
695 		pHTInfoEle->PcoActive				= 0;
696 		pHTInfoEle->PcoPhase				= 0;
697 
698 		memset(pHTInfoEle->BasicMSC, 0, 16);
699 
700 
701 		*len = 22 + 2; //same above
702 
703 	}
704 	else
705 	{
706 		//STA should not generate High Throughput Information Element
707 		*len = 0;
708 	}
709 	//IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTInfo, *len - 2);
710 	//HTDebugHTInfo(posHTInfo, "HTConstructInforElement");
711 	return;
712 }
713 
714 /*
715   *  According to experiment, Realtek AP to STA (based on rtl8190) may achieve best performance
716   *  if both STA and AP set limitation of aggregation size to 32K, that is, set AMPDU density to 2
717   *  (Ref: IEEE 11n specification). However, if Realtek STA associates to other AP, STA should set
718   *  limitation of aggregation size to 8K, otherwise, performance of traffic stream from STA to AP
719   *  will be much less than the traffic stream from AP to STA if both of the stream runs concurrently
720   *  at the same time.
721   *
722   *  Frame Format
723   *  Element ID		Length		OUI			Type1		Reserved
724   *  1 byte			1 byte		3 bytes		1 byte		1 byte
725   *
726   *  OUI 		= 0x00, 0xe0, 0x4c,
727   *  Type 	= 0x02
728   *  Reserved 	= 0x00
729   *
730   *  2007.8.21 by Emily
731 */
732 /********************************************************************************************************************
733  *function:  Construct  Information Element in Beacon... in RT2RT condition
734  *   input:  struct ieee80211_device* 	ieee
735  *   	     u8* 			posRT2RTAgg //pointer to store Information Ele
736  *   	     u8*			len   //store len
737  *  output:  none
738  *  return:  none
739  *  notice:
740   * *****************************************************************************************************************/
HTConstructRT2RTAggElement(struct ieee80211_device * ieee,u8 * posRT2RTAgg,u8 * len)741 void HTConstructRT2RTAggElement(struct ieee80211_device* ieee, u8* posRT2RTAgg, u8* len)
742 {
743 	if (posRT2RTAgg == NULL) {
744 		IEEE80211_DEBUG(IEEE80211_DL_ERR, "posRT2RTAgg can't be null in HTConstructRT2RTAggElement()\n");
745 		return;
746 	}
747 	memset(posRT2RTAgg, 0, *len);
748 	*posRT2RTAgg++ = 0x00;
749 	*posRT2RTAgg++ = 0xe0;
750 	*posRT2RTAgg++ = 0x4c;
751 	*posRT2RTAgg++ = 0x02;
752 	*posRT2RTAgg++ = 0x01;
753 	*posRT2RTAgg = 0x10;//*posRT2RTAgg = 0x02;
754 
755 	if(ieee->bSupportRemoteWakeUp) {
756 		*posRT2RTAgg |= 0x08;//RT_HT_CAP_USE_WOW;
757 	}
758 
759 	*len = 6 + 2;
760 	return;
761 #ifdef TODO
762 #if (HAL_CODE_BASE == RTL8192 && DEV_BUS_TYPE == USB_INTERFACE)
763 	/*
764 	//Emily. If it is required to Ask Realtek AP to send AMPDU during AES mode, enable this
765 	   section of code.
766 	if(IS_UNDER_11N_AES_MODE(Adapter))
767 	{
768 		posRT2RTAgg->Octet[5] |=RT_HT_CAP_USE_AMPDU;
769 	}else
770 	{
771 		posRT2RTAgg->Octet[5] &= 0xfb;
772 	}
773 	*/
774 
775 #else
776 	// Do Nothing
777 #endif
778 
779 	posRT2RTAgg->Length = 6;
780 #endif
781 
782 
783 
784 
785 }
786 
787 
788 /********************************************************************************************************************
789  *function:  Pick the right Rate Adaptive table to use
790  *   input:  struct ieee80211_device* 	ieee
791  *   	     u8* 			pOperateMCS //A pointer to MCS rate bitmap
792  *  return:  always we return true
793  *  notice:
794   * *****************************************************************************************************************/
HT_PickMCSRate(struct ieee80211_device * ieee,u8 * pOperateMCS)795 u8 HT_PickMCSRate(struct ieee80211_device* ieee, u8* pOperateMCS)
796 {
797 	u8					i;
798 	if (pOperateMCS == NULL)
799 	{
800 		IEEE80211_DEBUG(IEEE80211_DL_ERR, "pOperateMCS can't be null in HT_PickMCSRate()\n");
801 		return false;
802 	}
803 
804 	switch(ieee->mode)
805 	{
806 	case IEEE_A:
807 	case IEEE_B:
808 	case IEEE_G:
809 			//legacy rate routine handled at selectedrate
810 
811 			//no MCS rate
812 			for(i=0;i<=15;i++){
813 				pOperateMCS[i] = 0;
814 			}
815 			break;
816 
817 	case IEEE_N_24G:	//assume CCK rate ok
818 	case IEEE_N_5G:
819 			// Legacy part we only use 6, 5.5,2,1 for N_24G and 6 for N_5G.
820 			// Legacy part shall be handled at SelectRateSet().
821 
822 			//HT part
823 			// TODO: may be different if we have different number of antenna
824 			pOperateMCS[0] &=RATE_ADPT_1SS_MASK;	//support MCS 0~7
825 			pOperateMCS[1] &=RATE_ADPT_2SS_MASK;
826 			pOperateMCS[3] &=RATE_ADPT_MCS32_MASK;
827 			break;
828 
829 	//should never reach here
830 	default:
831 
832 			break;
833 
834 	}
835 
836 	return true;
837 }
838 
839 /*
840 *	Description:
841 *		This function will get the highest speed rate in input MCS set.
842 *
843 *	/param 	Adapter			Pionter to Adapter entity
844 *			pMCSRateSet		Pointer to MCS rate bitmap
845 *			pMCSFilter		Pointer to MCS rate filter
846 *
847 *	/return	Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter.
848 *
849 */
850 /********************************************************************************************************************
851  *function:  This function will get the highest speed rate in input MCS set.
852  *   input:  struct ieee80211_device* 	ieee
853  *   	     u8* 			pMCSRateSet //Pointer to MCS rate bitmap
854  *   	     u8*			pMCSFilter //Pointer to MCS rate filter
855  *  return:  Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter
856  *  notice:
857   * *****************************************************************************************************************/
HTGetHighestMCSRate(struct ieee80211_device * ieee,u8 * pMCSRateSet,u8 * pMCSFilter)858 u8 HTGetHighestMCSRate(struct ieee80211_device* ieee, u8* pMCSRateSet, u8* pMCSFilter)
859 {
860 	u8		i, j;
861 	u8		bitMap;
862 	u8		mcsRate = 0;
863 	u8		availableMcsRate[16];
864 	if (pMCSRateSet == NULL || pMCSFilter == NULL)
865 	{
866 		IEEE80211_DEBUG(IEEE80211_DL_ERR, "pMCSRateSet or pMCSFilter can't be null in HTGetHighestMCSRate()\n");
867 		return false;
868 	}
869 	for(i=0; i<16; i++)
870 		availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i];
871 
872 	for(i = 0; i < 16; i++)
873 	{
874 		if(availableMcsRate[i] != 0)
875 			break;
876 	}
877 	if(i == 16)
878 		return false;
879 
880 	for(i = 0; i < 16; i++)
881 	{
882 		if(availableMcsRate[i] != 0)
883 		{
884 			bitMap = availableMcsRate[i];
885 			for(j = 0; j < 8; j++)
886 			{
887 				if((bitMap%2) != 0)
888 				{
889 					if(HTMcsToDataRate(ieee, (8*i+j)) > HTMcsToDataRate(ieee, mcsRate))
890 						mcsRate = (8*i+j);
891 				}
892 				bitMap = bitMap>>1;
893 			}
894 		}
895 	}
896 	return (mcsRate|0x80);
897 }
898 
899 
900 
901 /*
902 **
903 **1.Filter our operation rate set with AP's rate set
904 **2.shall reference channel bandwidth, STBC, Antenna number
905 **3.generate rate adative table for firmware
906 **David 20060906
907 **
908 ** \pHTSupportedCap: the connected STA's supported rate Capability element
909 */
HTFilterMCSRate(struct ieee80211_device * ieee,u8 * pSupportMCS,u8 * pOperateMCS)910 u8 HTFilterMCSRate( struct ieee80211_device* ieee, u8* pSupportMCS, u8* pOperateMCS)
911 {
912 
913 	u8 i=0;
914 
915 	// filter out operational rate set not supported by AP, the lenth of it is 16
916 	for(i=0;i<=15;i++){
917 		pOperateMCS[i] = ieee->Regdot11HTOperationalRateSet[i]&pSupportMCS[i];
918 	}
919 
920 
921 	// TODO: adjust our operational rate set  according to our channel bandwidth, STBC and Antenna number
922 
923 	// TODO: fill suggested rate adaptive rate index and give firmware info using Tx command packet
924 	// we also shall suggested the first start rate set according to our singal strength
925 	HT_PickMCSRate(ieee, pOperateMCS);
926 
927 	// For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
928 	if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
929 		pOperateMCS[1] = 0;
930 
931 	//
932 	// For RTL819X, we support only MCS0~15.
933 	// And also, we do not know how to use MCS32 now.
934 	//
935 	for(i=2; i<=15; i++)
936 		pOperateMCS[i] = 0;
937 
938 	return true;
939 }
940 void HTSetConnectBwMode(struct ieee80211_device* ieee, HT_CHANNEL_WIDTH	Bandwidth, HT_EXTCHNL_OFFSET	Offset);
HTOnAssocRsp(struct ieee80211_device * ieee)941 void HTOnAssocRsp(struct ieee80211_device *ieee)
942 {
943 	PRT_HIGH_THROUGHPUT	pHTInfo = ieee->pHTInfo;
944 	PHT_CAPABILITY_ELE		pPeerHTCap = NULL;
945 	PHT_INFORMATION_ELE		pPeerHTInfo = NULL;
946 	u16	nMaxAMSDUSize = 0;
947 	u8*	pMcsFilter = NULL;
948 
949 	static u8				EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};		// For 11n EWC definition, 2007.07.17, by Emily
950 	static u8				EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};	// For 11n EWC definition, 2007.07.17, by Emily
951 
952 	if( pHTInfo->bCurrentHTSupport == false )
953 	{
954 		IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n");
955 		return;
956 	}
957 	IEEE80211_DEBUG(IEEE80211_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n");
958 //	IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(HT_CAPABILITY_ELE));
959 //	IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTInfoBuf, sizeof(HT_INFORMATION_ELE));
960 
961 //	HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq");
962 //	HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq");
963 	//
964 	if(!memcmp(pHTInfo->PeerHTCapBuf,EWC11NHTCap, sizeof(EWC11NHTCap)))
965 		pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]);
966 	else
967 		pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf);
968 
969 	if(!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
970 		pPeerHTInfo = (PHT_INFORMATION_ELE)(&pHTInfo->PeerHTInfoBuf[4]);
971 	else
972 		pPeerHTInfo = (PHT_INFORMATION_ELE)(pHTInfo->PeerHTInfoBuf);
973 
974 
975 	////////////////////////////////////////////////////////
976 	// Configurations:
977 	////////////////////////////////////////////////////////
978 	IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTCap, sizeof(HT_CAPABILITY_ELE));
979 //	IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTInfo, sizeof(HT_INFORMATION_ELE));
980 	// Config Supported Channel Width setting
981 	//
982 	HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));
983 
984 //	if(pHTInfo->bCurBW40MHz == true)
985 		pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false);
986 
987 	//
988 	// Update short GI/ long GI setting
989 	//
990 	// TODO:
991 	pHTInfo->bCurShortGI20MHz=
992 		((pHTInfo->bRegShortGI20MHz)?((pPeerHTCap->ShortGI20Mhz==1)?true:false):false);
993 	pHTInfo->bCurShortGI40MHz=
994 		((pHTInfo->bRegShortGI40MHz)?((pPeerHTCap->ShortGI40Mhz==1)?true:false):false);
995 
996 	//
997 	// Config TX STBC setting
998 	//
999 	// TODO:
1000 
1001 	//
1002 	// Config DSSS/CCK  mode in 40MHz mode
1003 	//
1004 	// TODO:
1005 	pHTInfo->bCurSuppCCK =
1006 		((pHTInfo->bRegSuppCCK)?((pPeerHTCap->DssCCk==1)?true:false):false);
1007 
1008 
1009 	//
1010 	// Config and configure A-MSDU setting
1011 	//
1012 	pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
1013 
1014 	nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize==0)?3839:7935;
1015 
1016 	if(pHTInfo->nAMSDU_MaxSize > nMaxAMSDUSize )
1017 		pHTInfo->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize;
1018 	else
1019 		pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1020 
1021 
1022 	//
1023 	// Config A-MPDU setting
1024 	//
1025 	pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
1026 
1027 	// <1> Decide AMPDU Factor
1028 
1029 	// By Emily
1030 	if(!pHTInfo->bRegRT2RTAggregation)
1031 	{
1032 		// Decide AMPDU Factor according to protocol handshake
1033 		if(pHTInfo->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor)
1034 			pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1035 		else
1036 			pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1037 
1038 	}else
1039 	{
1040 		// Set MPDU density to 2 to Realtek AP, and set it to 0 for others
1041 		// Replace MPDU factor declared in original association response frame format. 2007.08.20 by Emily
1042 		if (ieee->current_network.bssht.bdRT2RTAggregation)
1043 		{
1044 			if( ieee->pairwise_key_type != KEY_TYPE_NA)
1045 				// Realtek may set 32k in security mode and 64k for others
1046 				pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1047 			else
1048 				pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
1049 		}else
1050 		{
1051 			if(pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K)
1052 				pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1053 			else
1054 				pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K;
1055 		}
1056 	}
1057 
1058 	// <2> Set AMPDU Minimum MPDU Start Spacing
1059 	// 802.11n 3.0 section 9.7d.3
1060 	if(pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
1061 		pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1062 	else
1063 		pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
1064 	if(ieee->pairwise_key_type != KEY_TYPE_NA )
1065 		pHTInfo->CurrentMPDUDensity 	= 7; // 8us
1066 	// Force TX AMSDU
1067 
1068 	// Lanhsin: mark for tmp to avoid deauth by ap from  s3
1069 	//if(memcmp(pMgntInfo->Bssid, NETGEAR834Bv2_BROADCOM, 3)==0)
1070 	if(0)
1071 		{
1072 
1073 			pHTInfo->bCurrentAMPDUEnable = false;
1074 			pHTInfo->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE;
1075 			pHTInfo->ForcedAMSDUMaxSize = 7935;
1076 
1077 		pHTInfo->IOTAction |=  HT_IOT_ACT_TX_USE_AMSDU_8K;
1078 	}
1079 
1080 	// Rx Reorder Setting
1081 	pHTInfo->bCurRxReorderEnable = pHTInfo->bRegRxReorderEnable;
1082 
1083 	//
1084 	// Filter out unsupported HT rate for this AP
1085 	// Update RATR table
1086 	// This is only for 8190 ,8192 or later product which using firmware to handle rate adaptive mechanism.
1087 	//
1088 
1089 	// Handle Ralink AP bad MCS rate set condition. Joseph.
1090 	// This fix the bug of Ralink AP. This may be removed in the future.
1091 	if(pPeerHTCap->MCS[0] == 0)
1092 		pPeerHTCap->MCS[0] = 0xff;
1093 
1094 	HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11HTOperationalRateSet);
1095 
1096 	//
1097 	// Config MIMO Power Save setting
1098 	//
1099 	pHTInfo->PeerMimoPs = pPeerHTCap->MimoPwrSave;
1100 	if(pHTInfo->PeerMimoPs == MIMO_PS_STATIC)
1101 		pMcsFilter = MCS_FILTER_1SS;
1102 	else
1103 		pMcsFilter = MCS_FILTER_ALL;
1104 	//WB add for MCS8 bug
1105 //	pMcsFilter = MCS_FILTER_1SS;
1106 	ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, pMcsFilter);
1107 	ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
1108 
1109 	//
1110 	// Config current operation mode.
1111 	//
1112 	pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1113 
1114 
1115 
1116 }
1117 
1118 void HTSetConnectBwModeCallback(struct ieee80211_device* ieee);
1119 /********************************************************************************************************************
1120  *function:  initialize HT info(struct PRT_HIGH_THROUGHPUT)
1121  *   input:  struct ieee80211_device* 	ieee
1122  *  output:  none
1123  *  return:  none
1124  *  notice: This function is called when *  (1) MPInitialization Phase *  (2) Receiving of Deauthentication from AP
1125 ********************************************************************************************************************/
1126 // TODO: Should this funciton be called when receiving of Disassociation?
HTInitializeHTInfo(struct ieee80211_device * ieee)1127 void HTInitializeHTInfo(struct ieee80211_device* ieee)
1128 {
1129 	PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1130 
1131 	//
1132 	// These parameters will be reset when receiving deauthentication packet
1133 	//
1134 	IEEE80211_DEBUG(IEEE80211_DL_HT, "===========>%s()\n", __FUNCTION__);
1135 	pHTInfo->bCurrentHTSupport = false;
1136 
1137 	// 40MHz channel support
1138 	pHTInfo->bCurBW40MHz = false;
1139 	pHTInfo->bCurTxBW40MHz = false;
1140 
1141 	// Short GI support
1142 	pHTInfo->bCurShortGI20MHz = false;
1143 	pHTInfo->bCurShortGI40MHz = false;
1144 	pHTInfo->bForcedShortGI = false;
1145 
1146 	// CCK rate support
1147 	// This flag is set to true to support CCK rate by default.
1148 	// It will be affected by "pHTInfo->bRegSuppCCK" and AP capabilities only when associate to
1149 	// 11N BSS.
1150 	pHTInfo->bCurSuppCCK = true;
1151 
1152 	// AMSDU related
1153 	pHTInfo->bCurrent_AMSDU_Support = false;
1154 	pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1155 
1156 	// AMPUD related
1157 	pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1158 	pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1159 
1160 
1161 
1162 	// Initialize all of the parameters related to 11n
1163 	memset((void*)(&(pHTInfo->SelfHTCap)), 0, sizeof(pHTInfo->SelfHTCap));
1164 	memset((void*)(&(pHTInfo->SelfHTInfo)), 0, sizeof(pHTInfo->SelfHTInfo));
1165 	memset((void*)(&(pHTInfo->PeerHTCapBuf)), 0, sizeof(pHTInfo->PeerHTCapBuf));
1166 	memset((void*)(&(pHTInfo->PeerHTInfoBuf)), 0, sizeof(pHTInfo->PeerHTInfoBuf));
1167 
1168 	pHTInfo->bSwBwInProgress = false;
1169 	pHTInfo->ChnlOp = CHNLOP_NONE;
1170 
1171 	// Set default IEEE spec for Draft N
1172 	pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE;
1173 
1174 	// Realtek proprietary aggregation mode
1175 	pHTInfo->bCurrentRT2RTAggregation = false;
1176 	pHTInfo->bCurrentRT2RTLongSlotTime = false;
1177 	pHTInfo->IOTPeer = 0;
1178 	pHTInfo->IOTAction = 0;
1179 
1180 	//MCS rate initialized here
1181 	{
1182 		u8* RegHTSuppRateSets = &(ieee->RegHTSuppRateSet[0]);
1183 		RegHTSuppRateSets[0] = 0xFF;	//support MCS 0~7
1184 		RegHTSuppRateSets[1] = 0xFF;	//support MCS 8~15
1185 		RegHTSuppRateSets[4] = 0x01;	//support MCS 32
1186 	}
1187 }
1188 /********************************************************************************************************************
1189  *function:  initialize Bss HT structure(struct PBSS_HT)
1190  *   input:  PBSS_HT pBssHT //to be initialized
1191  *  output:  none
1192  *  return:  none
1193  *  notice: This function is called when initialize network structure
1194 ********************************************************************************************************************/
HTInitializeBssDesc(PBSS_HT pBssHT)1195 void HTInitializeBssDesc(PBSS_HT pBssHT)
1196 {
1197 
1198 	pBssHT->bdSupportHT = false;
1199 	memset(pBssHT->bdHTCapBuf, 0, sizeof(pBssHT->bdHTCapBuf));
1200 	pBssHT->bdHTCapLen = 0;
1201 	memset(pBssHT->bdHTInfoBuf, 0, sizeof(pBssHT->bdHTInfoBuf));
1202 	pBssHT->bdHTInfoLen = 0;
1203 
1204 	pBssHT->bdHTSpecVer= HT_SPEC_VER_IEEE;
1205 
1206 	pBssHT->bdRT2RTAggregation = false;
1207 	pBssHT->bdRT2RTLongSlotTime = false;
1208 }
1209 /********************************************************************************************************************
1210  *function:  initialize Bss HT structure(struct PBSS_HT)
1211  *   input:  struct ieee80211_device 	*ieee
1212  *   	     struct ieee80211_network 	*pNetwork //usually current network we are live in
1213  *  output:  none
1214  *  return:  none
1215  *  notice: This function should ONLY be called before association
1216 ********************************************************************************************************************/
HTResetSelfAndSavePeerSetting(struct ieee80211_device * ieee,struct ieee80211_network * pNetwork)1217 void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, 	struct ieee80211_network * pNetwork)
1218 {
1219 	PRT_HIGH_THROUGHPUT		pHTInfo = ieee->pHTInfo;
1220 //	u16						nMaxAMSDUSize;
1221 //	PHT_CAPABILITY_ELE		pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1222 //	PHT_INFORMATION_ELE		pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1223 //	u8*	pMcsFilter;
1224 	u8	bIOTAction = 0;
1225 
1226 	//
1227 	//  Save Peer Setting before Association
1228 	//
1229 	IEEE80211_DEBUG(IEEE80211_DL_HT, "==============>%s()\n", __FUNCTION__);
1230 	/*unmark bEnableHT flag here is the same reason why unmarked in function ieee80211_softmac_new_net. WB 2008.09.10*/
1231 //	if( pHTInfo->bEnableHT &&  pNetwork->bssht.bdSupportHT)
1232 	if (pNetwork->bssht.bdSupportHT)
1233 	{
1234 		pHTInfo->bCurrentHTSupport = true;
1235 		pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer;
1236 
1237 		// Save HTCap and HTInfo information Element
1238 		if(pNetwork->bssht.bdHTCapLen > 0 && 	pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf))
1239 			memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen);
1240 
1241 		if(pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf))
1242 			memcpy(pHTInfo->PeerHTInfoBuf, pNetwork->bssht.bdHTInfoBuf, pNetwork->bssht.bdHTInfoLen);
1243 
1244 		// Check whether RT to RT aggregation mode is enabled
1245 		if(pHTInfo->bRegRT2RTAggregation)
1246 		{
1247 			pHTInfo->bCurrentRT2RTAggregation = pNetwork->bssht.bdRT2RTAggregation;
1248 			pHTInfo->bCurrentRT2RTLongSlotTime = pNetwork->bssht.bdRT2RTLongSlotTime;
1249 		}
1250 		else
1251 		{
1252 			pHTInfo->bCurrentRT2RTAggregation = false;
1253 			pHTInfo->bCurrentRT2RTLongSlotTime = false;
1254 		}
1255 
1256 		// Determine the IOT Peer Vendor.
1257 		HTIOTPeerDetermine(ieee);
1258 
1259 		// Decide IOT Action
1260 		// Must be called after the parameter of pHTInfo->bCurrentRT2RTAggregation is decided
1261 		pHTInfo->IOTAction = 0;
1262 		bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid);
1263 		if(bIOTAction)
1264 			pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS14;
1265 
1266 		bIOTAction = HTIOTActIsDisableMCS15(ieee);
1267 		if(bIOTAction)
1268 			pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS15;
1269 
1270 		bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee, pNetwork->bssid);
1271 		if(bIOTAction)
1272 			pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_ALL_2SS;
1273 
1274 
1275 		bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid);
1276 		if(bIOTAction)
1277 			pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_EDCA_TURBO;
1278 
1279 		bIOTAction = HTIOTActIsMgntUseCCK6M(pNetwork);
1280 		if(bIOTAction)
1281 			pHTInfo->IOTAction |= HT_IOT_ACT_MGNT_USE_CCK_6M;
1282 
1283 		bIOTAction = HTIOTActIsCCDFsync(pNetwork->bssid);
1284 		if(bIOTAction)
1285 			pHTInfo->IOTAction |= HT_IOT_ACT_CDD_FSYNC;
1286 
1287 
1288 	}
1289 	else
1290 	{
1291 		pHTInfo->bCurrentHTSupport = false;
1292 		pHTInfo->bCurrentRT2RTAggregation = false;
1293 		pHTInfo->bCurrentRT2RTLongSlotTime = false;
1294 
1295 		pHTInfo->IOTAction = 0;
1296 	}
1297 
1298 }
1299 
HTUpdateSelfAndPeerSetting(struct ieee80211_device * ieee,struct ieee80211_network * pNetwork)1300 void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee, 	struct ieee80211_network * pNetwork)
1301 {
1302 	PRT_HIGH_THROUGHPUT	pHTInfo = ieee->pHTInfo;
1303 //	PHT_CAPABILITY_ELE		pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1304 	PHT_INFORMATION_ELE		pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1305 
1306 	if(pHTInfo->bCurrentHTSupport)
1307 	{
1308 		//
1309 		// Config current operation mode.
1310 		//
1311 		if(pNetwork->bssht.bdHTInfoLen != 0)
1312 			pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1313 
1314 		//
1315 		// <TODO: Config according to OBSS non-HT STA present!!>
1316 		//
1317 	}
1318 }
1319 
HTUseDefaultSetting(struct ieee80211_device * ieee)1320 void HTUseDefaultSetting(struct ieee80211_device* ieee)
1321 {
1322 	PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1323 //	u8	regBwOpMode;
1324 
1325 	if(pHTInfo->bEnableHT)
1326 	{
1327 		pHTInfo->bCurrentHTSupport = true;
1328 
1329 		pHTInfo->bCurSuppCCK = pHTInfo->bRegSuppCCK;
1330 
1331 		pHTInfo->bCurBW40MHz = pHTInfo->bRegBW40MHz;
1332 
1333 		pHTInfo->bCurShortGI20MHz= pHTInfo->bRegShortGI20MHz;
1334 
1335 		pHTInfo->bCurShortGI40MHz= pHTInfo->bRegShortGI40MHz;
1336 
1337 		pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
1338 
1339 		pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1340 
1341 		pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
1342 
1343 		pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1344 
1345 		pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1346 
1347 		// Set BWOpMode register
1348 
1349 		//update RATR index0
1350 		HTFilterMCSRate(ieee, ieee->Regdot11HTOperationalRateSet, ieee->dot11HTOperationalRateSet);
1351 	//function below is not implemented at all. WB
1352 #ifdef TODO
1353 		Adapter->HalFunc.InitHalRATRTableHandler( Adapter, &pMgntInfo->dot11OperationalRateSet, pMgntInfo->dot11HTOperationalRateSet);
1354 #endif
1355 		ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, MCS_FILTER_ALL);
1356 		ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
1357 
1358 	}
1359 	else
1360 	{
1361 		pHTInfo->bCurrentHTSupport = false;
1362 	}
1363 	return;
1364 }
1365 /********************************************************************************************************************
1366  *function:  check whether HT control field exists
1367  *   input:  struct ieee80211_device 	*ieee
1368  *   	     u8*			pFrame //coming skb->data
1369  *  output:  none
1370  *  return:  return true if HT control field exists(false otherwise)
1371  *  notice:
1372 ********************************************************************************************************************/
HTCCheck(struct ieee80211_device * ieee,u8 * pFrame)1373 u8 HTCCheck(struct ieee80211_device* ieee, u8*	pFrame)
1374 {
1375 	if(ieee->pHTInfo->bCurrentHTSupport)
1376 	{
1377 		if( (IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1)
1378 		{
1379 			IEEE80211_DEBUG(IEEE80211_DL_HT, "HT CONTROL FILED EXIST!!\n");
1380 			return true;
1381 		}
1382 	}
1383 	return false;
1384 }
1385 
1386 //
1387 // This function set bandwidth mode in protocol layer.
1388 //
HTSetConnectBwMode(struct ieee80211_device * ieee,HT_CHANNEL_WIDTH Bandwidth,HT_EXTCHNL_OFFSET Offset)1389 void HTSetConnectBwMode(struct ieee80211_device* ieee, HT_CHANNEL_WIDTH	Bandwidth, HT_EXTCHNL_OFFSET	Offset)
1390 {
1391 	PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1392 //	u32 flags = 0;
1393 
1394 	if(pHTInfo->bRegBW40MHz == false)
1395 		return;
1396 
1397 
1398 
1399 	// To reduce dummy operation
1400 //	if((pHTInfo->bCurBW40MHz==false && Bandwidth==HT_CHANNEL_WIDTH_20) ||
1401 //	   (pHTInfo->bCurBW40MHz==true && Bandwidth==HT_CHANNEL_WIDTH_20_40 && Offset==pHTInfo->CurSTAExtChnlOffset))
1402 //		return;
1403 
1404 //	spin_lock_irqsave(&(ieee->bw_spinlock), flags);
1405 	if(pHTInfo->bSwBwInProgress) {
1406 //		spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1407 		return;
1408 	}
1409 	//if in half N mode, set to 20M bandwidth please 09.08.2008 WB.
1410 	if(Bandwidth==HT_CHANNEL_WIDTH_20_40 && (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)))
1411 	 {
1412 			// Handle Illegal extension channel offset!!
1413 		if(ieee->current_network.channel<2 && Offset==HT_EXTCHNL_OFFSET_LOWER)
1414 			Offset = HT_EXTCHNL_OFFSET_NO_EXT;
1415 		if(Offset==HT_EXTCHNL_OFFSET_UPPER || Offset==HT_EXTCHNL_OFFSET_LOWER) {
1416 			pHTInfo->bCurBW40MHz = true;
1417 			pHTInfo->CurSTAExtChnlOffset = Offset;
1418 		} else {
1419 			pHTInfo->bCurBW40MHz = false;
1420 			pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1421 		}
1422 	} else {
1423 		pHTInfo->bCurBW40MHz = false;
1424 		pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1425 	}
1426 
1427 	pHTInfo->bSwBwInProgress = true;
1428 
1429 	// TODO: 2007.7.13 by Emily Wait 2000ms  in order to guarantee that switching
1430 	//   bandwidth is executed after scan is finished. It is a temporal solution
1431 	//   because software should ganrantee the last operation of switching bandwidth
1432 	//   is executed properlly.
1433 	HTSetConnectBwModeCallback(ieee);
1434 
1435 //	spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1436 }
1437 
HTSetConnectBwModeCallback(struct ieee80211_device * ieee)1438 void HTSetConnectBwModeCallback(struct ieee80211_device* ieee)
1439 {
1440 	PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1441 
1442 	IEEE80211_DEBUG(IEEE80211_DL_HT, "======>%s()\n", __FUNCTION__);
1443 
1444 	if(pHTInfo->bCurBW40MHz)
1445 	{
1446 		if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_UPPER)
1447 			ieee->set_chan(ieee->dev, ieee->current_network.channel+2);
1448 		else if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_LOWER)
1449 			ieee->set_chan(ieee->dev, ieee->current_network.channel-2);
1450 		else
1451 			ieee->set_chan(ieee->dev, ieee->current_network.channel);
1452 
1453 		ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, pHTInfo->CurSTAExtChnlOffset);
1454 	} else {
1455 		ieee->set_chan(ieee->dev, ieee->current_network.channel);
1456 		ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1457 	}
1458 
1459 	pHTInfo->bSwBwInProgress = false;
1460 }
1461 
1462 EXPORT_SYMBOL(HTUpdateSelfAndPeerSetting);
1463