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