• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  ******************************************************************************/
15 #define _RTW_WLAN_UTIL_C_
16 
17 #include <linux/ieee80211.h>
18 
19 #include <osdep_service.h>
20 #include <drv_types.h>
21 #include <wifi.h>
22 
23 static unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f};
24 static unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74};
25 
26 static unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18};
27 static unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7};
28 
29 static unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96};
30 static unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43};
31 static unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43};
32 static unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c};
33 static unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5};
34 static unsigned char EPIGRAM_OUI[] = {0x00, 0x90, 0x4c};
35 
36 unsigned char REALTEK_96B_IE[] = {0x00, 0xe0, 0x4c, 0x02, 0x01, 0x20};
37 
38 #define R2T_PHY_DELAY	(0)
39 
40 /* define WAIT_FOR_BCN_TO_M	(3000) */
41 #define WAIT_FOR_BCN_TO_MIN	(6000)
42 #define WAIT_FOR_BCN_TO_MAX	(20000)
43 
44 static u8 rtw_basic_rate_cck[4] = {
45 	IEEE80211_CCK_RATE_1MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB|IEEE80211_BASIC_RATE_MASK,
46 	IEEE80211_CCK_RATE_5MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB|IEEE80211_BASIC_RATE_MASK
47 };
48 
49 static u8 rtw_basic_rate_ofdm[3] = {
50 	IEEE80211_OFDM_RATE_6MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB|IEEE80211_BASIC_RATE_MASK,
51 	IEEE80211_OFDM_RATE_24MB|IEEE80211_BASIC_RATE_MASK
52 };
53 
54 static u8 rtw_basic_rate_mix[7] = {
55 	IEEE80211_CCK_RATE_1MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB|IEEE80211_BASIC_RATE_MASK,
56 	IEEE80211_CCK_RATE_5MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB|IEEE80211_BASIC_RATE_MASK,
57 	IEEE80211_OFDM_RATE_6MB|IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB|IEEE80211_BASIC_RATE_MASK,
58 	IEEE80211_OFDM_RATE_24MB|IEEE80211_BASIC_RATE_MASK
59 };
60 
cckrates_included(unsigned char * rate,int ratelen)61 int cckrates_included(unsigned char *rate, int ratelen)
62 {
63 	int	i;
64 
65 	for (i = 0; i < ratelen; i++) {
66 		if  ((((rate[i]) & 0x7f) == 2)	|| (((rate[i]) & 0x7f) == 4) ||
67 		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
68 			return true;
69 	}
70 	return false;
71 }
72 
cckratesonly_included(unsigned char * rate,int ratelen)73 int cckratesonly_included(unsigned char *rate, int ratelen)
74 {
75 	int	i;
76 
77 	for (i = 0; i < ratelen; i++) {
78 		if  ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
79 			   (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
80 			return false;
81 	}
82 
83 	return true;
84 }
85 
networktype_to_raid(unsigned char network_type)86 unsigned char networktype_to_raid(unsigned char network_type)
87 {
88 	switch (network_type) {
89 	case WIRELESS_11B:
90 		return RATR_INX_WIRELESS_B;
91 	case WIRELESS_11A:
92 	case WIRELESS_11G:
93 		return RATR_INX_WIRELESS_G;
94 	case WIRELESS_11BG:
95 		return RATR_INX_WIRELESS_GB;
96 	case WIRELESS_11_24N:
97 	case WIRELESS_11_5N:
98 		return RATR_INX_WIRELESS_N;
99 	case WIRELESS_11A_5N:
100 	case WIRELESS_11G_24N:
101 		return  RATR_INX_WIRELESS_NG;
102 	case WIRELESS_11BG_24N:
103 		return RATR_INX_WIRELESS_NGB;
104 	default:
105 		return RATR_INX_WIRELESS_GB;
106 	}
107 }
108 
judge_network_type(struct adapter * padapter,unsigned char * rate,int ratelen)109 u8 judge_network_type(struct adapter *padapter, unsigned char *rate, int ratelen)
110 {
111 	u8 network_type = 0;
112 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
113 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
114 
115 	if (pmlmeext->cur_channel > 14) {
116 		if (pmlmeinfo->HT_enable)
117 			network_type = WIRELESS_11_5N;
118 
119 		network_type |= WIRELESS_11A;
120 	} else {
121 		if (pmlmeinfo->HT_enable)
122 			network_type = WIRELESS_11_24N;
123 
124 		if ((cckratesonly_included(rate, ratelen)) == true)
125 			network_type |= WIRELESS_11B;
126 		else if ((cckrates_included(rate, ratelen)) == true)
127 			network_type |= WIRELESS_11BG;
128 		else
129 			network_type |= WIRELESS_11G;
130 	}
131 	return	network_type;
132 }
133 
ratetbl_val_2wifirate(unsigned char rate)134 static unsigned char ratetbl_val_2wifirate(unsigned char rate)
135 {
136 	switch (rate & 0x7f) {
137 	case 0:
138 		return IEEE80211_CCK_RATE_1MB;
139 	case 1:
140 		return IEEE80211_CCK_RATE_2MB;
141 	case 2:
142 		return IEEE80211_CCK_RATE_5MB;
143 	case 3:
144 		return IEEE80211_CCK_RATE_11MB;
145 	case 4:
146 		return IEEE80211_OFDM_RATE_6MB;
147 	case 5:
148 		return IEEE80211_OFDM_RATE_9MB;
149 	case 6:
150 		return IEEE80211_OFDM_RATE_12MB;
151 	case 7:
152 		return IEEE80211_OFDM_RATE_18MB;
153 	case 8:
154 		return IEEE80211_OFDM_RATE_24MB;
155 	case 9:
156 		return IEEE80211_OFDM_RATE_36MB;
157 	case 10:
158 		return IEEE80211_OFDM_RATE_48MB;
159 	case 11:
160 		return IEEE80211_OFDM_RATE_54MB;
161 	default:
162 		return 0;
163 	}
164 }
165 
is_basicrate(struct adapter * padapter,unsigned char rate)166 static int is_basicrate(struct adapter *padapter, unsigned char rate)
167 {
168 	int i;
169 	unsigned char val;
170 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
171 
172 	for (i = 0; i < NumRates; i++) {
173 		val = pmlmeext->basicrate[i];
174 
175 		if ((val != 0xff) && (val != 0xfe)) {
176 			if (rate == ratetbl_val_2wifirate(val))
177 				return true;
178 		}
179 	}
180 	return false;
181 }
182 
ratetbl2rateset(struct adapter * padapter,unsigned char * rateset)183 static unsigned int ratetbl2rateset(struct adapter *padapter, unsigned char *rateset)
184 {
185 	int i;
186 	unsigned char rate;
187 	unsigned int	len = 0;
188 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
189 
190 	for (i = 0; i < NumRates; i++) {
191 		rate = pmlmeext->datarate[i];
192 
193 		switch (rate) {
194 		case 0xff:
195 			return len;
196 		case 0xfe:
197 			continue;
198 		default:
199 			rate = ratetbl_val_2wifirate(rate);
200 
201 			if (is_basicrate(padapter, rate) == true)
202 				rate |= IEEE80211_BASIC_RATE_MASK;
203 
204 			rateset[len] = rate;
205 			len++;
206 			break;
207 		}
208 	}
209 	return len;
210 }
211 
get_rate_set(struct adapter * padapter,unsigned char * pbssrate,int * bssrate_len)212 void get_rate_set(struct adapter *padapter, unsigned char *pbssrate, int *bssrate_len)
213 {
214 	unsigned char supportedrates[NumRates];
215 
216 	memset(supportedrates, 0, NumRates);
217 	*bssrate_len = ratetbl2rateset(padapter, supportedrates);
218 	memcpy(pbssrate, supportedrates, *bssrate_len);
219 }
220 
UpdateBrateTbl(struct adapter * Adapter,u8 * mbrate)221 void UpdateBrateTbl(struct adapter *Adapter, u8 *mbrate)
222 {
223 	u8	i;
224 	u8	rate;
225 
226 	/*  1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory. */
227 	for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
228 		rate = mbrate[i] & 0x7f;
229 		switch (rate) {
230 		case IEEE80211_CCK_RATE_1MB:
231 		case IEEE80211_CCK_RATE_2MB:
232 		case IEEE80211_CCK_RATE_5MB:
233 		case IEEE80211_CCK_RATE_11MB:
234 		case IEEE80211_OFDM_RATE_6MB:
235 		case IEEE80211_OFDM_RATE_12MB:
236 		case IEEE80211_OFDM_RATE_24MB:
237 			mbrate[i] |= IEEE80211_BASIC_RATE_MASK;
238 			break;
239 		}
240 	}
241 }
242 
UpdateBrateTblForSoftAP(u8 * bssrateset,u32 bssratelen)243 void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen)
244 {
245 	u8	i;
246 	u8	rate;
247 
248 	for (i = 0; i < bssratelen; i++) {
249 		rate = bssrateset[i] & 0x7f;
250 		switch (rate) {
251 		case IEEE80211_CCK_RATE_1MB:
252 		case IEEE80211_CCK_RATE_2MB:
253 		case IEEE80211_CCK_RATE_5MB:
254 		case IEEE80211_CCK_RATE_11MB:
255 			bssrateset[i] |= IEEE80211_BASIC_RATE_MASK;
256 			break;
257 		}
258 	}
259 }
260 
Save_DM_Func_Flag(struct adapter * padapter)261 void Save_DM_Func_Flag(struct adapter *padapter)
262 {
263 	u8	saveflag = true;
264 
265 	rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&saveflag));
266 }
267 
Restore_DM_Func_Flag(struct adapter * padapter)268 void Restore_DM_Func_Flag(struct adapter *padapter)
269 {
270 	u8	saveflag = false;
271 
272 	rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&saveflag));
273 }
274 
Switch_DM_Func(struct adapter * padapter,u32 mode,u8 enable)275 void Switch_DM_Func(struct adapter *padapter, u32 mode, u8 enable)
276 {
277 	if (enable)
278 		rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_SET, (u8 *)(&mode));
279 	else
280 		rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode));
281 }
282 
Set_NETYPE0_MSR(struct adapter * padapter,u8 type)283 static void Set_NETYPE0_MSR(struct adapter *padapter, u8 type)
284 {
285 	rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
286 }
287 
Set_MSR(struct adapter * padapter,u8 type)288 void Set_MSR(struct adapter *padapter, u8 type)
289 {
290 	Set_NETYPE0_MSR(padapter, type);
291 }
292 
rtw_get_oper_ch(struct adapter * adapter)293 inline u8 rtw_get_oper_ch(struct adapter *adapter)
294 {
295 	return adapter->mlmeextpriv.oper_channel;
296 }
297 
rtw_set_oper_ch(struct adapter * adapter,u8 ch)298 inline void rtw_set_oper_ch(struct adapter *adapter, u8 ch)
299 {
300 	adapter->mlmeextpriv.oper_channel = ch;
301 }
302 
rtw_get_oper_bw(struct adapter * adapter)303 inline u8 rtw_get_oper_bw(struct adapter *adapter)
304 {
305 	return adapter->mlmeextpriv.oper_bwmode;
306 }
307 
rtw_set_oper_bw(struct adapter * adapter,u8 bw)308 inline void rtw_set_oper_bw(struct adapter *adapter, u8 bw)
309 {
310 	adapter->mlmeextpriv.oper_bwmode = bw;
311 }
312 
rtw_get_oper_choffset(struct adapter * adapter)313 inline u8 rtw_get_oper_choffset(struct adapter *adapter)
314 {
315 	return adapter->mlmeextpriv.oper_ch_offset;
316 }
317 
rtw_set_oper_choffset(struct adapter * adapter,u8 offset)318 inline void rtw_set_oper_choffset(struct adapter *adapter, u8 offset)
319 {
320 	adapter->mlmeextpriv.oper_ch_offset = offset;
321 }
322 
SelectChannel(struct adapter * padapter,unsigned char channel)323 void SelectChannel(struct adapter *padapter, unsigned char channel)
324 {
325 	/* saved channel info */
326 	rtw_set_oper_ch(padapter, channel);
327 	rtw_hal_set_chan(padapter, channel);
328 }
329 
SetBWMode(struct adapter * padapter,unsigned short bwmode,unsigned char channel_offset)330 void SetBWMode(struct adapter *padapter, unsigned short bwmode,
331 	       unsigned char channel_offset)
332 {
333 	/* saved bw info */
334 	rtw_set_oper_bw(padapter, bwmode);
335 	rtw_set_oper_choffset(padapter, channel_offset);
336 
337 	rtw_hal_set_bwmode(padapter, (enum ht_channel_width)bwmode, channel_offset);
338 }
339 
set_channel_bwmode(struct adapter * padapter,unsigned char channel,unsigned char channel_offset,unsigned short bwmode)340 void set_channel_bwmode(struct adapter *padapter, unsigned char channel, unsigned char channel_offset, unsigned short bwmode)
341 {
342 	u8 center_ch;
343 
344 	if ((bwmode == HT_CHANNEL_WIDTH_20) ||
345 	    (channel_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)) {
346 		/* SelectChannel(padapter, channel); */
347 		center_ch = channel;
348 	} else {
349 		/* switch to the proper channel */
350 		if (channel_offset == HAL_PRIME_CHNL_OFFSET_LOWER) {
351 			/* SelectChannel(padapter, channel + 2); */
352 			center_ch = channel + 2;
353 		} else {
354 			/* SelectChannel(padapter, channel - 2); */
355 			center_ch = channel - 2;
356 		}
357 	}
358 
359 	/* set Channel */
360 	/* saved channel/bw info */
361 	rtw_set_oper_ch(padapter, channel);
362 	rtw_set_oper_bw(padapter, bwmode);
363 	rtw_set_oper_choffset(padapter, channel_offset);
364 
365 	rtw_hal_set_chan(padapter, center_ch); /*  set center channel */
366 	SetBWMode(padapter, bwmode, channel_offset);
367 }
368 
get_bsstype(unsigned short capability)369 int get_bsstype(unsigned short capability)
370 {
371 	if (capability & BIT(0))
372 		return WIFI_FW_AP_STATE;
373 	else if (capability & BIT(1))
374 		return WIFI_FW_ADHOC_STATE;
375 	else
376 		return 0;
377 }
378 
get_beacon_interval(struct wlan_bssid_ex * bss)379 u16 get_beacon_interval(struct wlan_bssid_ex *bss)
380 {
381 	__le16 val;
382 	memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2);
383 
384 	return le16_to_cpu(val);
385 }
386 
is_client_associated_to_ap(struct adapter * padapter)387 int is_client_associated_to_ap(struct adapter *padapter)
388 {
389 	struct mlme_ext_priv	*pmlmeext;
390 	struct mlme_ext_info	*pmlmeinfo;
391 
392 	if (!padapter)
393 		return _FAIL;
394 
395 	pmlmeext = &padapter->mlmeextpriv;
396 	pmlmeinfo = &(pmlmeext->mlmext_info);
397 
398 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE))
399 		return true;
400 	else
401 		return _FAIL;
402 }
403 
is_client_associated_to_ibss(struct adapter * padapter)404 int is_client_associated_to_ibss(struct adapter *padapter)
405 {
406 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
407 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
408 
409 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE))
410 		return true;
411 	else
412 		return _FAIL;
413 }
414 
is_IBSS_empty(struct adapter * padapter)415 int is_IBSS_empty(struct adapter *padapter)
416 {
417 	unsigned int i;
418 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
419 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
420 
421 	for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
422 		if (pmlmeinfo->FW_sta_info[i].status == 1)
423 			return _FAIL;
424 	}
425 	return true;
426 }
427 
decide_wait_for_beacon_timeout(unsigned int bcn_interval)428 unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval)
429 {
430 	if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN)
431 		return WAIT_FOR_BCN_TO_MIN;
432 	else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX)
433 		return WAIT_FOR_BCN_TO_MAX;
434 	else
435 		return bcn_interval << 2;
436 }
437 
CAM_empty_entry(struct adapter * Adapter,u8 ucIndex)438 void CAM_empty_entry(struct adapter *Adapter, u8 ucIndex)
439 {
440 	rtw_hal_set_hwreg(Adapter, HW_VAR_CAM_EMPTY_ENTRY, (u8 *)(&ucIndex));
441 }
442 
invalidate_cam_all(struct adapter * padapter)443 void invalidate_cam_all(struct adapter *padapter)
444 {
445 	rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, NULL);
446 }
447 
write_cam(struct adapter * padapter,u8 entry,u16 ctrl,u8 * mac,u8 * key)448 void write_cam(struct adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key)
449 {
450 	unsigned int	i, val, addr;
451 	int j;
452 	u32	cam_val[2];
453 
454 	addr = entry << 3;
455 
456 	for (j = 5; j >= 0; j--) {
457 		switch (j) {
458 		case 0:
459 			val = ctrl | (mac[0] << 16) | (mac[1] << 24);
460 			break;
461 		case 1:
462 			val = mac[2] | (mac[3] << 8) | (mac[4] << 16) | (mac[5] << 24);
463 			break;
464 		default:
465 			i = (j - 2) << 2;
466 			val = key[i] | (key[i+1] << 8) | (key[i+2] << 16) | (key[i+3] << 24);
467 			break;
468 		}
469 
470 		cam_val[0] = val;
471 		cam_val[1] = addr + (unsigned int)j;
472 
473 		rtw_hal_set_hwreg(padapter, HW_VAR_CAM_WRITE, (u8 *)cam_val);
474 	}
475 }
476 
clear_cam_entry(struct adapter * padapter,u8 entry)477 void clear_cam_entry(struct adapter *padapter, u8 entry)
478 {
479 	unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
480 	unsigned char null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
481 				    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
482 
483 	write_cam(padapter, entry, 0, null_sta, null_key);
484 }
485 
allocate_fw_sta_entry(struct adapter * padapter)486 int allocate_fw_sta_entry(struct adapter *padapter)
487 {
488 	unsigned int mac_id;
489 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
490 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
491 
492 	for (mac_id = IBSS_START_MAC_ID; mac_id < NUM_STA; mac_id++) {
493 		if (pmlmeinfo->FW_sta_info[mac_id].status == 0) {
494 			pmlmeinfo->FW_sta_info[mac_id].status = 1;
495 			pmlmeinfo->FW_sta_info[mac_id].retry = 0;
496 			break;
497 		}
498 	}
499 
500 	return mac_id;
501 }
502 
flush_all_cam_entry(struct adapter * padapter)503 void flush_all_cam_entry(struct adapter *padapter)
504 {
505 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
506 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
507 
508 	rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, NULL);
509 
510 	memset((u8 *)(pmlmeinfo->FW_sta_info), 0, sizeof(pmlmeinfo->FW_sta_info));
511 }
512 
WMM_param_handler(struct adapter * padapter,struct ndis_802_11_var_ie * pIE)513 int WMM_param_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE)
514 {
515 	/* struct registry_priv	*pregpriv = &padapter->registrypriv; */
516 	struct mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
517 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
518 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
519 
520 	if (pmlmepriv->qospriv.qos_option == 0) {
521 		pmlmeinfo->WMM_enable = 0;
522 		return _FAIL;
523 	}
524 
525 	pmlmeinfo->WMM_enable = 1;
526 	memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
527 	return true;
528 }
529 
WMMOnAssocRsp(struct adapter * padapter)530 void WMMOnAssocRsp(struct adapter *padapter)
531 {
532 	u8	ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
533 	u8	acm_mask;
534 	u16	TXOP;
535 	u32	acParm, i;
536 	u32	edca[4], inx[4];
537 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
538 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
539 	struct xmit_priv		*pxmitpriv = &padapter->xmitpriv;
540 	struct registry_priv	*pregpriv = &padapter->registrypriv;
541 
542 	if (pmlmeinfo->WMM_enable == 0) {
543 		padapter->mlmepriv.acm_mask = 0;
544 		return;
545 	}
546 
547 	acm_mask = 0;
548 
549 	if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
550 		aSifsTime = 10;
551 	else
552 		aSifsTime = 16;
553 
554 	for (i = 0; i < 4; i++) {
555 		ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
556 		ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
557 
558 		/* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
559 		AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) * pmlmeinfo->slotTime + aSifsTime;
560 
561 		ECWMin = pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f;
562 		ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4;
563 		TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit);
564 
565 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
566 
567 		switch (ACI) {
568 		case 0x0:
569 			rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
570 			acm_mask |= (ACM ? BIT(1) : 0);
571 			edca[XMIT_BE_QUEUE] = acParm;
572 			break;
573 		case 0x1:
574 			rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
575 			edca[XMIT_BK_QUEUE] = acParm;
576 			break;
577 		case 0x2:
578 			rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
579 			acm_mask |= (ACM ? BIT(2) : 0);
580 			edca[XMIT_VI_QUEUE] = acParm;
581 			break;
582 		case 0x3:
583 			rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
584 			acm_mask |= (ACM ? BIT(3) : 0);
585 			edca[XMIT_VO_QUEUE] = acParm;
586 			break;
587 		}
588 
589 		DBG_88E("WMM(%x): %x, %x\n", ACI, ACM, acParm);
590 	}
591 
592 	if (padapter->registrypriv.acm_method == 1)
593 		rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
594 	else
595 		padapter->mlmepriv.acm_mask = acm_mask;
596 
597 	inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
598 
599 	if (pregpriv->wifi_spec == 1) {
600 		u32	j, change_inx = false;
601 
602 		/* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
603 		for (i = 0; i < 4; i++) {
604 			for (j = i+1; j < 4; j++) {
605 				/* compare CW and AIFS */
606 				if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF)) {
607 					change_inx = true;
608 				} else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
609 					/* compare TXOP */
610 					if ((edca[j] >> 16) > (edca[i] >> 16))
611 						change_inx = true;
612 				}
613 
614 				if (change_inx) {
615 					swap(edca[i], edca[j]);
616 					swap(inx[i], inx[j]);
617 					change_inx = false;
618 				}
619 			}
620 		}
621 	}
622 
623 	for (i = 0; i < 4; i++) {
624 		pxmitpriv->wmm_para_seq[i] = inx[i];
625 		DBG_88E("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
626 	}
627 }
628 
bwmode_update_check(struct adapter * padapter,struct ndis_802_11_var_ie * pIE)629 static void bwmode_update_check(struct adapter *padapter, struct ndis_802_11_var_ie *pIE)
630 {
631 	unsigned char	 new_bwmode;
632 	unsigned char  new_ch_offset;
633 	struct HT_info_element	 *pHT_info;
634 	struct mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
635 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
636 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
637 	struct registry_priv *pregistrypriv = &padapter->registrypriv;
638 	struct ht_priv			*phtpriv = &pmlmepriv->htpriv;
639 
640 	if (!pIE)
641 		return;
642 
643 	if (!phtpriv)
644 		return;
645 
646 	if (pIE->Length > sizeof(struct HT_info_element))
647 		return;
648 
649 	pHT_info = (struct HT_info_element *)pIE->data;
650 
651 	if ((pHT_info->infos[0] & BIT(2)) && pregistrypriv->cbw40_enable) {
652 		new_bwmode = HT_CHANNEL_WIDTH_40;
653 
654 		switch (pHT_info->infos[0] & 0x3) {
655 		case 1:
656 			new_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
657 			break;
658 		case 3:
659 			new_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
660 			break;
661 		default:
662 			new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
663 			break;
664 		}
665 	} else {
666 		new_bwmode = HT_CHANNEL_WIDTH_20;
667 		new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
668 	}
669 
670 	if ((new_bwmode != pmlmeext->cur_bwmode) ||
671 	    (new_ch_offset != pmlmeext->cur_ch_offset)) {
672 		pmlmeinfo->bwmode_updated = true;
673 
674 		pmlmeext->cur_bwmode = new_bwmode;
675 		pmlmeext->cur_ch_offset = new_ch_offset;
676 
677 		/* update HT info also */
678 		HT_info_handler(padapter, pIE);
679 	} else {
680 		pmlmeinfo->bwmode_updated = false;
681 	}
682 
683 	if (pmlmeinfo->bwmode_updated) {
684 		struct sta_info *psta;
685 		struct wlan_bssid_ex	*cur_network = &(pmlmeinfo->network);
686 		struct sta_priv	*pstapriv = &padapter->stapriv;
687 
688 		/* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
689 
690 		/* update ap's stainfo */
691 		psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
692 		if (psta) {
693 			struct ht_priv	*phtpriv_sta = &psta->htpriv;
694 
695 			if (phtpriv_sta->ht_option) {
696 				/*  bwmode */
697 				phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
698 				phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
699 			} else {
700 				phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
701 				phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
702 			}
703 		}
704 	}
705 }
706 
HT_caps_handler(struct adapter * padapter,struct ndis_802_11_var_ie * pIE)707 void HT_caps_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE)
708 {
709 	unsigned int	i;
710 	u8	rf_type;
711 	u8	max_AMPDU_len, min_MPDU_spacing;
712 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
713 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
714 	struct mlme_priv		*pmlmepriv = &padapter->mlmepriv;
715 	struct ht_priv			*phtpriv = &pmlmepriv->htpriv;
716 	u8 *HT_cap = (u8 *)(&pmlmeinfo->HT_caps);
717 
718 	if (pIE == NULL)
719 		return;
720 
721 	if (!phtpriv->ht_option)
722 		return;
723 
724 	pmlmeinfo->HT_caps_enable = 1;
725 
726 	for (i = 0; i < (pIE->Length); i++) {
727 		if (i != 2) {
728 			/*	Got the endian issue here. */
729 			HT_cap[i] &= (pIE->data[i]);
730 		} else {
731 			/* modify from  fw by Thomas 2010/11/17 */
732 			if ((pmlmeinfo->HT_caps.ampdu_params_info & 0x3) > (pIE->data[i] & 0x3))
733 				max_AMPDU_len = pIE->data[i] & 0x3;
734 			else
735 				max_AMPDU_len = pmlmeinfo->HT_caps.ampdu_params_info & 0x3;
736 
737 			if ((pmlmeinfo->HT_caps.ampdu_params_info & 0x1c) > (pIE->data[i] & 0x1c))
738 				min_MPDU_spacing = pmlmeinfo->HT_caps.ampdu_params_info & 0x1c;
739 			else
740 				min_MPDU_spacing = pIE->data[i] & 0x1c;
741 
742 			pmlmeinfo->HT_caps.ampdu_params_info = max_AMPDU_len | min_MPDU_spacing;
743 		}
744 	}
745 
746 	rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
747 
748 	/* update the MCS rates */
749 	for (i = 0; i < 16; i++) {
750 		if ((rf_type == RF_1T1R) || (rf_type == RF_1T2R))
751 			((u8 *)&pmlmeinfo->HT_caps.mcs)[i] &= MCS_rate_1R[i];
752 		else
753 			((u8 *)&pmlmeinfo->HT_caps.mcs)[i] &= MCS_rate_2R[i];
754 	}
755 }
756 
HT_info_handler(struct adapter * padapter,struct ndis_802_11_var_ie * pIE)757 void HT_info_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE)
758 {
759 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
760 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
761 	struct mlme_priv		*pmlmepriv = &padapter->mlmepriv;
762 	struct ht_priv			*phtpriv = &pmlmepriv->htpriv;
763 
764 	if (pIE == NULL)
765 		return;
766 
767 	if (!phtpriv->ht_option)
768 		return;
769 
770 	if (pIE->Length > sizeof(struct HT_info_element))
771 		return;
772 
773 	pmlmeinfo->HT_info_enable = 1;
774 	memcpy(&(pmlmeinfo->HT_info), pIE->data, pIE->Length);
775 }
776 
HTOnAssocRsp(struct adapter * padapter)777 void HTOnAssocRsp(struct adapter *padapter)
778 {
779 	unsigned char		max_AMPDU_len;
780 	unsigned char		min_MPDU_spacing;
781 	/* struct registry_priv	 *pregpriv = &padapter->registrypriv; */
782 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
783 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
784 
785 	DBG_88E("%s\n", __func__);
786 
787 	if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable)) {
788 		pmlmeinfo->HT_enable = 1;
789 	} else {
790 		pmlmeinfo->HT_enable = 0;
791 		return;
792 	}
793 
794 	/* handle A-MPDU parameter field */
795 	/*
796 		AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
797 		AMPDU_para [4:2]:Min MPDU Start Spacing
798 	*/
799 	max_AMPDU_len = pmlmeinfo->HT_caps.ampdu_params_info & 0x03;
800 
801 	min_MPDU_spacing = (pmlmeinfo->HT_caps.ampdu_params_info & 0x1c) >> 2;
802 
803 	rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
804 
805 	rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
806 }
807 
ERP_IE_handler(struct adapter * padapter,struct ndis_802_11_var_ie * pIE)808 void ERP_IE_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE)
809 {
810 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
811 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
812 
813 	if (pIE->Length > 1)
814 		return;
815 
816 	pmlmeinfo->ERP_enable = 1;
817 	memcpy(&(pmlmeinfo->ERP_IE), pIE->data, pIE->Length);
818 }
819 
VCS_update(struct adapter * padapter,struct sta_info * psta)820 void VCS_update(struct adapter *padapter, struct sta_info *psta)
821 {
822 	struct registry_priv	 *pregpriv = &padapter->registrypriv;
823 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
824 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
825 
826 	switch (pregpriv->vrtl_carrier_sense) { /* 0:off 1:on 2:auto */
827 	case 0: /* off */
828 		psta->rtsen = 0;
829 		psta->cts2self = 0;
830 		break;
831 	case 1: /* on */
832 		if (pregpriv->vcs_type == 1) { /* 1:RTS/CTS 2:CTS to self */
833 			psta->rtsen = 1;
834 			psta->cts2self = 0;
835 		} else {
836 			psta->rtsen = 0;
837 			psta->cts2self = 1;
838 		}
839 		break;
840 	case 2: /* auto */
841 	default:
842 		if ((pmlmeinfo->ERP_enable) && (pmlmeinfo->ERP_IE & BIT(1))) {
843 			if (pregpriv->vcs_type == 1) {
844 				psta->rtsen = 1;
845 				psta->cts2self = 0;
846 			} else {
847 				psta->rtsen = 0;
848 				psta->cts2self = 1;
849 			}
850 		} else {
851 			psta->rtsen = 0;
852 			psta->cts2self = 0;
853 		}
854 		break;
855 	}
856 }
857 
rtw_check_bcn_info(struct adapter * Adapter,u8 * pframe,u32 packet_len)858 int rtw_check_bcn_info(struct adapter  *Adapter, u8 *pframe, u32 packet_len)
859 {
860 	unsigned int		len;
861 	unsigned char		*p;
862 	unsigned short	val16, subtype;
863 	struct wlan_network *cur_network = &(Adapter->mlmepriv.cur_network);
864 	/* u8 wpa_ie[255], rsn_ie[255]; */
865 	u16 wpa_len = 0, rsn_len = 0;
866 	u8 encryp_protocol = 0;
867 	struct wlan_bssid_ex *bssid;
868 	int group_cipher = 0, pairwise_cipher = 0, is_8021x = 0;
869 	unsigned char *pbuf;
870 	u32 wpa_ielen = 0;
871 	u8 *pbssid = GetAddr3Ptr(pframe);
872 	struct HT_info_element *pht_info = NULL;
873 	u32 bcn_channel;
874 	unsigned short	ht_cap_info;
875 	unsigned char	ht_info_infos_0;
876 	int ssid_len;
877 
878 	if (is_client_associated_to_ap(Adapter) == false)
879 		return true;
880 
881 	len = packet_len - sizeof(struct ieee80211_hdr_3addr);
882 
883 	if (len > MAX_IE_SZ) {
884 		DBG_88E("%s IE too long for survey event\n", __func__);
885 		return _FAIL;
886 	}
887 
888 	if (!memcmp(cur_network->network.MacAddress, pbssid, 6) == false) {
889 		DBG_88E("Oops: rtw_check_network_encrypt linked but recv other bssid bcn\n%pM %pM\n",
890 			(pbssid), (cur_network->network.MacAddress));
891 		return true;
892 	}
893 
894 	bssid = kzalloc(sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
895 	if (!bssid)
896 		return _FAIL;
897 
898 	subtype = GetFrameSubType(pframe) >> 4;
899 
900 	if (subtype == WIFI_BEACON)
901 		bssid->Reserved[0] = 1;
902 
903 	bssid->Length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len;
904 
905 	/* below is to copy the information element */
906 	bssid->IELength = len;
907 	memcpy(bssid->IEs, (pframe + sizeof(struct ieee80211_hdr_3addr)), bssid->IELength);
908 
909 	/* check bw and channel offset */
910 	/* parsing HT_CAP_IE */
911 	p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
912 	if (p && len > 0) {
913 		struct ieee80211_ht_cap *ht_cap =
914 			(struct ieee80211_ht_cap *)(p + 2);
915 
916 		ht_cap_info = le16_to_cpu(ht_cap->cap_info);
917 	} else {
918 		ht_cap_info = 0;
919 	}
920 	/* parsing HT_INFO_IE */
921 	p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
922 	if (p && len > 0) {
923 			pht_info = (struct HT_info_element *)(p + 2);
924 			ht_info_infos_0 = pht_info->infos[0];
925 	} else {
926 			ht_info_infos_0 = 0;
927 	}
928 	if (ht_cap_info != cur_network->BcnInfo.ht_cap_info ||
929 	    ((ht_info_infos_0&0x03) != (cur_network->BcnInfo.ht_info_infos_0&0x03))) {
930 			DBG_88E("%s bcn now: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
931 				ht_cap_info, ht_info_infos_0);
932 			DBG_88E("%s bcn link: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
933 				cur_network->BcnInfo.ht_cap_info, cur_network->BcnInfo.ht_info_infos_0);
934 			DBG_88E("%s bw mode change, disconnect\n", __func__);
935 			/* bcn_info_update */
936 			cur_network->BcnInfo.ht_cap_info = ht_cap_info;
937 			cur_network->BcnInfo.ht_info_infos_0 = ht_info_infos_0;
938 			/* to do : need to check that whether modify related register of BB or not */
939 			/* goto _mismatch; */
940 	}
941 
942 	/* Checking for channel */
943 	p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _DSSET_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
944 	if (p) {
945 			bcn_channel = *(p + 2);
946 	} else {/* In 5G, some ap do not have DSSET IE checking HT info for channel */
947 			p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
948 			if (pht_info) {
949 					bcn_channel = pht_info->primary_channel;
950 			} else { /* we don't find channel IE, so don't check it */
951 					DBG_88E("Oops: %s we don't find channel IE, so don't check it\n", __func__);
952 					bcn_channel = Adapter->mlmeextpriv.cur_channel;
953 			}
954 	}
955 	if (bcn_channel != Adapter->mlmeextpriv.cur_channel) {
956 			DBG_88E("%s beacon channel:%d cur channel:%d disconnect\n", __func__,
957 				bcn_channel, Adapter->mlmeextpriv.cur_channel);
958 			goto _mismatch;
959 	}
960 
961 	/* checking SSID */
962 	ssid_len = 0;
963 	p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _SSID_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
964 	if (p) {
965 		ssid_len = *(p + 1);
966 		if (ssid_len > NDIS_802_11_LENGTH_SSID)
967 			ssid_len = 0;
968 	}
969 	memcpy(bssid->Ssid.Ssid, (p + 2), ssid_len);
970 	bssid->Ssid.SsidLength = ssid_len;
971 
972 	RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d "
973 				"cur_network->network.Ssid.Ssid:%s len:%d\n", __func__, bssid->Ssid.Ssid,
974 				bssid->Ssid.SsidLength, cur_network->network.Ssid.Ssid,
975 				cur_network->network.Ssid.SsidLength));
976 
977 	if (memcmp(bssid->Ssid.Ssid, cur_network->network.Ssid.Ssid, 32) ||
978 	    bssid->Ssid.SsidLength != cur_network->network.Ssid.SsidLength) {
979 		if (bssid->Ssid.Ssid[0] != '\0' && bssid->Ssid.SsidLength != 0) { /* not hidden ssid */
980 			DBG_88E("%s(), SSID is not match return FAIL\n", __func__);
981 			goto _mismatch;
982 		}
983 	}
984 
985 	/* check encryption info */
986 	val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid);
987 
988 	if (val16 & BIT(4))
989 		bssid->Privacy = 1;
990 	else
991 		bssid->Privacy = 0;
992 
993 	RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
994 		 ("%s(): cur_network->network.Privacy is %d, bssid.Privacy is %d\n",
995 		 __func__, cur_network->network.Privacy, bssid->Privacy));
996 	if (cur_network->network.Privacy != bssid->Privacy) {
997 		DBG_88E("%s(), privacy is not match return FAIL\n", __func__);
998 		goto _mismatch;
999 	}
1000 
1001 	rtw_get_sec_ie(bssid->IEs, bssid->IELength, NULL, &rsn_len, NULL, &wpa_len);
1002 
1003 	if (rsn_len > 0) {
1004 		encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1005 	} else if (wpa_len > 0) {
1006 		encryp_protocol = ENCRYP_PROTOCOL_WPA;
1007 	} else {
1008 		if (bssid->Privacy)
1009 			encryp_protocol = ENCRYP_PROTOCOL_WEP;
1010 	}
1011 
1012 	if (cur_network->BcnInfo.encryp_protocol != encryp_protocol) {
1013 		DBG_88E("%s(): encryption protocol is not match , return FAIL\n", __func__);
1014 		goto _mismatch;
1015 	}
1016 
1017 	if (encryp_protocol == ENCRYP_PROTOCOL_WPA || encryp_protocol == ENCRYP_PROTOCOL_WPA2) {
1018 		pbuf = rtw_get_wpa_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength-12);
1019 		if (pbuf && (wpa_ielen > 0)) {
1020 			if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is_8021x)) {
1021 				RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1022 					 ("%s pnetwork->pairwise_cipher: %d, group_cipher is %d, is_8021x is %d\n", __func__,
1023 					 pairwise_cipher, group_cipher, is_8021x));
1024 			}
1025 		} else {
1026 			pbuf = rtw_get_wpa2_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength-12);
1027 
1028 			if (pbuf && (wpa_ielen > 0)) {
1029 				if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is_8021x)) {
1030 					RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1031 						 ("%s pnetwork->pairwise_cipher: %d, pnetwork->group_cipher is %d, is_802x is %d\n",
1032 						  __func__, pairwise_cipher, group_cipher, is_8021x));
1033 				}
1034 			}
1035 		}
1036 
1037 		RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
1038 			 ("%s cur_network->group_cipher is %d: %d\n", __func__, cur_network->BcnInfo.group_cipher, group_cipher));
1039 		if (pairwise_cipher != cur_network->BcnInfo.pairwise_cipher || group_cipher != cur_network->BcnInfo.group_cipher) {
1040 			DBG_88E("%s pairwise_cipher(%x:%x) or group_cipher(%x:%x) is not match , return FAIL\n", __func__,
1041 				pairwise_cipher, cur_network->BcnInfo.pairwise_cipher,
1042 				group_cipher, cur_network->BcnInfo.group_cipher);
1043 			goto _mismatch;
1044 		}
1045 
1046 		if (is_8021x != cur_network->BcnInfo.is_8021x) {
1047 			DBG_88E("%s authentication is not match , return FAIL\n", __func__);
1048 			goto _mismatch;
1049 		}
1050 	}
1051 
1052 	kfree(bssid);
1053 	return _SUCCESS;
1054 
1055 _mismatch:
1056 	kfree(bssid);
1057 	return _FAIL;
1058 }
1059 
update_beacon_info(struct adapter * padapter,u8 * pframe,uint pkt_len,struct sta_info * psta)1060 void update_beacon_info(struct adapter *padapter, u8 *pframe, uint pkt_len, struct sta_info *psta)
1061 {
1062 	unsigned int i;
1063 	unsigned int len;
1064 	struct ndis_802_11_var_ie *pIE;
1065 
1066 	len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN);
1067 
1068 	for (i = 0; i < len;) {
1069 		pIE = (struct ndis_802_11_var_ie *)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i);
1070 
1071 		switch (pIE->ElementID) {
1072 		case _HT_EXTRA_INFO_IE_:	/* HT info */
1073 			/* HT_info_handler(padapter, pIE); */
1074 			bwmode_update_check(padapter, pIE);
1075 			break;
1076 		case _ERPINFO_IE_:
1077 			ERP_IE_handler(padapter, pIE);
1078 			VCS_update(padapter, psta);
1079 			break;
1080 		default:
1081 			break;
1082 		}
1083 
1084 		i += (pIE->Length + 2);
1085 	}
1086 }
1087 
is_ap_in_tkip(struct adapter * padapter)1088 unsigned int is_ap_in_tkip(struct adapter *padapter)
1089 {
1090 	u32 i;
1091 	struct ndis_802_11_var_ie *pIE;
1092 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1093 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1094 	struct wlan_bssid_ex		*cur_network = &(pmlmeinfo->network);
1095 
1096 	if (rtw_get_capability((struct wlan_bssid_ex *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
1097 		for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength;) {
1098 			pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.IEs + i);
1099 
1100 			switch (pIE->ElementID) {
1101 			case _VENDOR_SPECIFIC_IE_:
1102 				if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) && (!memcmp((pIE->data + 12), WPA_TKIP_CIPHER, 4)))
1103 					return true;
1104 				break;
1105 			case _RSN_IE_2_:
1106 				if (!memcmp((pIE->data + 8), RSN_TKIP_CIPHER, 4))
1107 					return true;
1108 			default:
1109 				break;
1110 			}
1111 
1112 			i += (pIE->Length + 2);
1113 		}
1114 		return false;
1115 	} else {
1116 		return false;
1117 	}
1118 }
1119 
should_forbid_n_rate(struct adapter * padapter)1120 unsigned int should_forbid_n_rate(struct adapter *padapter)
1121 {
1122 	u32 i;
1123 	struct ndis_802_11_var_ie *pIE;
1124 	struct mlme_priv	*pmlmepriv = &padapter->mlmepriv;
1125 	struct wlan_bssid_ex  *cur_network = &pmlmepriv->cur_network.network;
1126 
1127 	if (rtw_get_capability((struct wlan_bssid_ex *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
1128 		for (i = sizeof(struct ndis_802_11_fixed_ie); i < cur_network->IELength;) {
1129 			pIE = (struct ndis_802_11_var_ie *)(cur_network->IEs + i);
1130 
1131 			switch (pIE->ElementID) {
1132 			case _VENDOR_SPECIFIC_IE_:
1133 				if (!memcmp(pIE->data, RTW_WPA_OUI, 4) &&
1134 				    ((!memcmp((pIE->data + 12), WPA_CIPHER_SUITE_CCMP, 4)) ||
1135 				    (!memcmp((pIE->data + 16), WPA_CIPHER_SUITE_CCMP, 4))))
1136 					return false;
1137 				break;
1138 			case _RSN_IE_2_:
1139 				if  ((!memcmp((pIE->data + 8), RSN_CIPHER_SUITE_CCMP, 4))  ||
1140 				       (!memcmp((pIE->data + 12), RSN_CIPHER_SUITE_CCMP, 4)))
1141 					return false;
1142 			default:
1143 				break;
1144 			}
1145 
1146 			i += (pIE->Length + 2);
1147 		}
1148 
1149 		return true;
1150 	} else {
1151 		return false;
1152 	}
1153 }
1154 
is_ap_in_wep(struct adapter * padapter)1155 unsigned int is_ap_in_wep(struct adapter *padapter)
1156 {
1157 	u32 i;
1158 	struct ndis_802_11_var_ie *pIE;
1159 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1160 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1161 	struct wlan_bssid_ex		*cur_network = &(pmlmeinfo->network);
1162 
1163 	if (rtw_get_capability((struct wlan_bssid_ex *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
1164 		for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength;) {
1165 			pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.IEs + i);
1166 
1167 			switch (pIE->ElementID) {
1168 			case _VENDOR_SPECIFIC_IE_:
1169 				if (!memcmp(pIE->data, RTW_WPA_OUI, 4))
1170 					return false;
1171 				break;
1172 			case _RSN_IE_2_:
1173 				return false;
1174 			default:
1175 				break;
1176 			}
1177 			i += (pIE->Length + 2);
1178 		}
1179 		return true;
1180 	} else {
1181 		return false;
1182 	}
1183 }
1184 
wifirate2_ratetbl_inx(unsigned char rate)1185 static int wifirate2_ratetbl_inx(unsigned char rate)
1186 {
1187 	rate = rate & 0x7f;
1188 
1189 	switch (rate) {
1190 	case 54*2:
1191 		return 11;
1192 	case 48*2:
1193 		return 10;
1194 	case 36*2:
1195 		return 9;
1196 	case 24*2:
1197 		return 8;
1198 	case 18*2:
1199 		return 7;
1200 	case 12*2:
1201 		return 6;
1202 	case 9*2:
1203 		return 5;
1204 	case 6*2:
1205 		return 4;
1206 	case 11*2:
1207 		return 3;
1208 	case 11:
1209 		return 2;
1210 	case 2*2:
1211 		return 1;
1212 	case 1*2:
1213 		return 0;
1214 	default:
1215 		return 0;
1216 	}
1217 }
1218 
update_basic_rate(unsigned char * ptn,unsigned int ptn_sz)1219 unsigned int update_basic_rate(unsigned char *ptn, unsigned int ptn_sz)
1220 {
1221 	unsigned int i, num_of_rate;
1222 	unsigned int mask = 0;
1223 
1224 	num_of_rate = min_t(unsigned int, ptn_sz, NumRates);
1225 
1226 	for (i = 0; i < num_of_rate; i++) {
1227 		if ((*(ptn + i)) & 0x80)
1228 			mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
1229 	}
1230 	return mask;
1231 }
1232 
update_supported_rate(unsigned char * ptn,unsigned int ptn_sz)1233 unsigned int update_supported_rate(unsigned char *ptn, unsigned int ptn_sz)
1234 {
1235 	unsigned int i, num_of_rate;
1236 	unsigned int mask = 0;
1237 
1238 	num_of_rate = min_t(unsigned int, ptn_sz, NumRates);
1239 
1240 	for (i = 0; i < num_of_rate; i++)
1241 		mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
1242 	return mask;
1243 }
1244 
update_MSC_rate(struct ieee80211_ht_cap * pHT_caps)1245 unsigned int update_MSC_rate(struct ieee80211_ht_cap *pHT_caps)
1246 {
1247 	unsigned int mask = 0;
1248 
1249 	mask = (pHT_caps->mcs.rx_mask[0] << 12) |
1250 	       (pHT_caps->mcs.rx_mask[1] << 20);
1251 
1252 	return mask;
1253 }
1254 
support_short_GI(struct adapter * padapter,struct ieee80211_ht_cap * pHT_caps)1255 int support_short_GI(struct adapter *padapter, struct ieee80211_ht_cap *pHT_caps)
1256 {
1257 	unsigned char					bit_offset;
1258 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1259 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1260 
1261 	if (!(pmlmeinfo->HT_enable))
1262 		return _FAIL;
1263 
1264 	if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_RALINK)
1265 		return _FAIL;
1266 
1267 	bit_offset = (pmlmeext->cur_bwmode & HT_CHANNEL_WIDTH_40) ? 6 : 5;
1268 
1269 	if (__le16_to_cpu(pHT_caps->cap_info) & (0x1 << bit_offset))
1270 		return _SUCCESS;
1271 	else
1272 		return _FAIL;
1273 }
1274 
get_highest_rate_idx(u32 mask)1275 unsigned char get_highest_rate_idx(u32 mask)
1276 {
1277 	int i;
1278 	unsigned char rate_idx = 0;
1279 
1280 	for (i = 27; i >= 0; i--) {
1281 		if (mask & BIT(i)) {
1282 			rate_idx = i;
1283 			break;
1284 		}
1285 	}
1286 	return rate_idx;
1287 }
1288 
Update_RA_Entry(struct adapter * padapter,u32 mac_id)1289 void Update_RA_Entry(struct adapter *padapter, u32 mac_id)
1290 {
1291 	rtw_hal_update_ra_mask(padapter, mac_id, 0);
1292 }
1293 
enable_rate_adaptive(struct adapter * padapter,u32 mac_id)1294 static void enable_rate_adaptive(struct adapter *padapter, u32 mac_id)
1295 {
1296 	Update_RA_Entry(padapter, mac_id);
1297 }
1298 
set_sta_rate(struct adapter * padapter,struct sta_info * psta)1299 void set_sta_rate(struct adapter *padapter, struct sta_info *psta)
1300 {
1301 	/* rate adaptive */
1302 	enable_rate_adaptive(padapter, psta->mac_id);
1303 }
1304 
1305 /*  Update RRSR and Rate for USERATE */
update_tx_basic_rate(struct adapter * padapter,u8 wirelessmode)1306 void update_tx_basic_rate(struct adapter *padapter, u8 wirelessmode)
1307 {
1308 	unsigned char supported_rates[NDIS_802_11_LENGTH_RATES_EX];
1309 	memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
1310 
1311 	if ((wirelessmode & WIRELESS_11B) && (wirelessmode == WIRELESS_11B))
1312 		memcpy(supported_rates, rtw_basic_rate_cck, 4);
1313 	else if (wirelessmode & WIRELESS_11B)
1314 		memcpy(supported_rates, rtw_basic_rate_mix, 7);
1315 	else
1316 		memcpy(supported_rates, rtw_basic_rate_ofdm, 3);
1317 
1318 
1319 	if (wirelessmode & WIRELESS_11B)
1320 		update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
1321 	else
1322 		update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
1323 
1324 	rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, supported_rates);
1325 }
1326 
check_assoc_AP(u8 * pframe,uint len)1327 unsigned char check_assoc_AP(u8 *pframe, uint len)
1328 {
1329 	unsigned int i;
1330 	struct ndis_802_11_var_ie *pIE;
1331 	u8	epigram_vendor_flag;
1332 	u8	ralink_vendor_flag;
1333 	epigram_vendor_flag = 0;
1334 	ralink_vendor_flag = 0;
1335 
1336 	for (i = sizeof(struct ndis_802_11_fixed_ie); i < len;) {
1337 		pIE = (struct ndis_802_11_var_ie *)(pframe + i);
1338 
1339 		switch (pIE->ElementID) {
1340 		case _VENDOR_SPECIFIC_IE_:
1341 			if ((!memcmp(pIE->data, ARTHEROS_OUI1, 3)) ||
1342 			    (!memcmp(pIE->data, ARTHEROS_OUI2, 3))) {
1343 				DBG_88E("link to Artheros AP\n");
1344 				return HT_IOT_PEER_ATHEROS;
1345 			} else if ((!memcmp(pIE->data, BROADCOM_OUI1, 3)) ||
1346 				   (!memcmp(pIE->data, BROADCOM_OUI2, 3))) {
1347 				DBG_88E("link to Broadcom AP\n");
1348 				return HT_IOT_PEER_BROADCOM;
1349 			} else if (!memcmp(pIE->data, MARVELL_OUI, 3)) {
1350 				DBG_88E("link to Marvell AP\n");
1351 				return HT_IOT_PEER_MARVELL;
1352 			} else if (!memcmp(pIE->data, RALINK_OUI, 3)) {
1353 				if (!ralink_vendor_flag) {
1354 					ralink_vendor_flag = 1;
1355 				} else {
1356 					DBG_88E("link to Ralink AP\n");
1357 					return HT_IOT_PEER_RALINK;
1358 				}
1359 			} else if (!memcmp(pIE->data, CISCO_OUI, 3)) {
1360 				DBG_88E("link to Cisco AP\n");
1361 				return HT_IOT_PEER_CISCO;
1362 			} else if (!memcmp(pIE->data, REALTEK_OUI, 3)) {
1363 				DBG_88E("link to Realtek 96B\n");
1364 				return HT_IOT_PEER_REALTEK;
1365 			} else if (!memcmp(pIE->data, AIRGOCAP_OUI, 3)) {
1366 				DBG_88E("link to Airgo Cap\n");
1367 				return HT_IOT_PEER_AIRGO;
1368 			} else if (!memcmp(pIE->data, EPIGRAM_OUI, 3)) {
1369 				epigram_vendor_flag = 1;
1370 				if (ralink_vendor_flag) {
1371 					DBG_88E("link to Tenda W311R AP\n");
1372 					return HT_IOT_PEER_TENDA;
1373 				} else {
1374 					DBG_88E("Capture EPIGRAM_OUI\n");
1375 				}
1376 			} else {
1377 				break;
1378 			}
1379 
1380 		default:
1381 			break;
1382 		}
1383 		i += (pIE->Length + 2);
1384 	}
1385 
1386 	if (ralink_vendor_flag && !epigram_vendor_flag) {
1387 		DBG_88E("link to Ralink AP\n");
1388 		return HT_IOT_PEER_RALINK;
1389 	} else if (ralink_vendor_flag && epigram_vendor_flag) {
1390 		DBG_88E("link to Tenda W311R AP\n");
1391 		return HT_IOT_PEER_TENDA;
1392 	} else {
1393 		DBG_88E("link to new AP\n");
1394 		return HT_IOT_PEER_UNKNOWN;
1395 	}
1396 }
1397 
update_IOT_info(struct adapter * padapter)1398 void update_IOT_info(struct adapter *padapter)
1399 {
1400 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1401 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1402 
1403 	switch (pmlmeinfo->assoc_AP_vendor) {
1404 	case HT_IOT_PEER_MARVELL:
1405 		pmlmeinfo->turboMode_cts2self = 1;
1406 		pmlmeinfo->turboMode_rtsen = 0;
1407 		break;
1408 	case HT_IOT_PEER_RALINK:
1409 		pmlmeinfo->turboMode_cts2self = 0;
1410 		pmlmeinfo->turboMode_rtsen = 1;
1411 		/* disable high power */
1412 		Switch_DM_Func(padapter, (u32)(~DYNAMIC_BB_DYNAMIC_TXPWR),
1413 			       false);
1414 		break;
1415 	case HT_IOT_PEER_REALTEK:
1416 		/* rtw_write16(padapter, 0x4cc, 0xffff); */
1417 		/* rtw_write16(padapter, 0x546, 0x01c0); */
1418 		/* disable high power */
1419 		Switch_DM_Func(padapter, (u32)(~DYNAMIC_BB_DYNAMIC_TXPWR),
1420 			       false);
1421 		break;
1422 	default:
1423 		pmlmeinfo->turboMode_cts2self = 0;
1424 		pmlmeinfo->turboMode_rtsen = 1;
1425 		break;
1426 	}
1427 }
1428 
update_capinfo(struct adapter * Adapter,u16 updateCap)1429 void update_capinfo(struct adapter *Adapter, u16 updateCap)
1430 {
1431 	struct mlme_ext_priv	*pmlmeext = &Adapter->mlmeextpriv;
1432 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1433 	bool		ShortPreamble;
1434 
1435 	/*  Check preamble mode, 2005.01.06, by rcnjko. */
1436 	/*  Mark to update preamble value forever, 2008.03.18 by lanhsin */
1437 
1438 	if (updateCap & cShortPreamble) { /*  Short Preamble */
1439 		if (pmlmeinfo->preamble_mode != PREAMBLE_SHORT) { /*  PREAMBLE_LONG or PREAMBLE_AUTO */
1440 			ShortPreamble = true;
1441 			pmlmeinfo->preamble_mode = PREAMBLE_SHORT;
1442 			rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
1443 		}
1444 	} else { /*  Long Preamble */
1445 		if (pmlmeinfo->preamble_mode != PREAMBLE_LONG) {  /*  PREAMBLE_SHORT or PREAMBLE_AUTO */
1446 			ShortPreamble = false;
1447 			pmlmeinfo->preamble_mode = PREAMBLE_LONG;
1448 			rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
1449 		}
1450 	}
1451 
1452 	if (updateCap & cIBSS) {
1453 		/* Filen: See 802.11-2007 p.91 */
1454 		pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1455 	} else { /* Filen: See 802.11-2007 p.90 */
1456 		if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11_24N)) {
1457 			if (updateCap & cShortSlotTime) { /*  Short Slot Time */
1458 				if (pmlmeinfo->slotTime != SHORT_SLOT_TIME)
1459 					pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1460 			} else { /*  Long Slot Time */
1461 				if (pmlmeinfo->slotTime != NON_SHORT_SLOT_TIME)
1462 					pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1463 			}
1464 		} else if (pmlmeext->cur_wireless_mode & (WIRELESS_11A | WIRELESS_11_5N)) {
1465 			pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1466 		} else {
1467 			/* B Mode */
1468 			pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1469 		}
1470 	}
1471 
1472 	rtw_hal_set_hwreg(Adapter, HW_VAR_SLOT_TIME, &pmlmeinfo->slotTime);
1473 }
1474 
update_wireless_mode(struct adapter * padapter)1475 void update_wireless_mode(struct adapter *padapter)
1476 {
1477 	int ratelen, network_type = 0;
1478 	u32 SIFS_Timer;
1479 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1480 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1481 	struct wlan_bssid_ex	*cur_network = &(pmlmeinfo->network);
1482 	unsigned char		*rate = cur_network->SupportedRates;
1483 
1484 	ratelen = rtw_get_rateset_len(cur_network->SupportedRates);
1485 
1486 	if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
1487 		pmlmeinfo->HT_enable = 1;
1488 
1489 	if (pmlmeext->cur_channel > 14) {
1490 		if (pmlmeinfo->HT_enable)
1491 			network_type = WIRELESS_11_5N;
1492 
1493 		network_type |= WIRELESS_11A;
1494 	} else {
1495 		if (pmlmeinfo->HT_enable)
1496 			network_type = WIRELESS_11_24N;
1497 
1498 		if ((cckratesonly_included(rate, ratelen)) == true)
1499 			network_type |= WIRELESS_11B;
1500 		else if ((cckrates_included(rate, ratelen)) == true)
1501 			network_type |= WIRELESS_11BG;
1502 		else
1503 			network_type |= WIRELESS_11G;
1504 	}
1505 
1506 	pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode;
1507 
1508 	SIFS_Timer = 0x0a0a0808;/* 0x0808 -> for CCK, 0x0a0a -> for OFDM */
1509 				/* change this value if having IOT issues. */
1510 
1511 	rtw_hal_set_hwreg(padapter, HW_VAR_RESP_SIFS,  (u8 *)&SIFS_Timer);
1512 
1513 	if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1514 		update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
1515 	 else
1516 		update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
1517 }
1518 
update_bmc_sta_support_rate(struct adapter * padapter,u32 mac_id)1519 void update_bmc_sta_support_rate(struct adapter *padapter, u32 mac_id)
1520 {
1521 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
1522 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1523 
1524 	if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
1525 		/*  Only B, B/G, and B/G/N AP could use CCK rate */
1526 		memcpy((pmlmeinfo->FW_sta_info[mac_id].SupportedRates), rtw_basic_rate_cck, 4);
1527 	} else {
1528 		memcpy((pmlmeinfo->FW_sta_info[mac_id].SupportedRates), rtw_basic_rate_ofdm, 3);
1529 	}
1530 }
1531 
update_sta_support_rate(struct adapter * padapter,u8 * pvar_ie,uint var_ie_len,int cam_idx)1532 int update_sta_support_rate(struct adapter *padapter, u8 *pvar_ie, uint var_ie_len, int cam_idx)
1533 {
1534 	unsigned int	ie_len;
1535 	struct ndis_802_11_var_ie *pIE;
1536 	int	supportRateNum = 0;
1537 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
1538 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1539 
1540 	pIE = (struct ndis_802_11_var_ie *)rtw_get_ie(pvar_ie, _SUPPORTEDRATES_IE_, &ie_len, var_ie_len);
1541 	if (pIE == NULL)
1542 		return _FAIL;
1543 	if (ie_len > NDIS_802_11_LENGTH_RATES_EX)
1544 		return _FAIL;
1545 
1546 	memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates, pIE->data, ie_len);
1547 	supportRateNum = ie_len;
1548 
1549 	pIE = (struct ndis_802_11_var_ie *)rtw_get_ie(pvar_ie, _EXT_SUPPORTEDRATES_IE_, &ie_len, var_ie_len);
1550 	if (pIE) {
1551 		if (supportRateNum + ie_len > NDIS_802_11_LENGTH_RATES_EX)
1552 			return _FAIL;
1553 		memcpy((pmlmeinfo->FW_sta_info[cam_idx].SupportedRates + supportRateNum), pIE->data, ie_len);
1554 	}
1555 
1556 	return _SUCCESS;
1557 }
1558 
process_addba_req(struct adapter * padapter,u8 * paddba_req,u8 * addr)1559 void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr)
1560 {
1561 	struct sta_info *psta;
1562 	u16 tid;
1563 	u16 param;
1564 	struct recv_reorder_ctrl *preorder_ctrl;
1565 	struct sta_priv *pstapriv = &padapter->stapriv;
1566 	struct ADDBA_request	*preq = (struct ADDBA_request *)paddba_req;
1567 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1568 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1569 
1570 	psta = rtw_get_stainfo(pstapriv, addr);
1571 
1572 	if (psta) {
1573 		param = le16_to_cpu(preq->BA_para_set);
1574 		tid = (param>>2)&0x0f;
1575 		preorder_ctrl = &psta->recvreorder_ctrl[tid];
1576 		preorder_ctrl->indicate_seq = 0xffff;
1577 		preorder_ctrl->enable = (pmlmeinfo->accept_addba_req) ? true
1578 								      : false;
1579 	}
1580 }
1581 
update_TSF(struct mlme_ext_priv * pmlmeext,u8 * pframe,uint len)1582 void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
1583 {
1584 	u8 *pIE;
1585 	__le32 *pbuf;
1586 
1587 	pIE = pframe + sizeof(struct ieee80211_hdr_3addr);
1588 	pbuf = (__le32 *)pIE;
1589 
1590 	pmlmeext->TSFValue = le32_to_cpu(*(pbuf+1));
1591 
1592 	pmlmeext->TSFValue = pmlmeext->TSFValue << 32;
1593 
1594 	pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
1595 }
1596 
correct_TSF(struct adapter * padapter,struct mlme_ext_priv * pmlmeext)1597 void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext)
1598 {
1599 	rtw_hal_set_hwreg(padapter, HW_VAR_CORRECT_TSF, NULL);
1600 }
1601 
beacon_timing_control(struct adapter * padapter)1602 void beacon_timing_control(struct adapter *padapter)
1603 {
1604 	rtw_hal_bcn_related_reg_setting(padapter);
1605 }
1606