1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #define _RTW_WLAN_UTIL_C_
8
9 #include <drv_types.h>
10 #include <rtw_debug.h>
11 #include <hal_com_h2c.h>
12
13 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
14 #include <linux/inetdevice.h>
15 #endif
16
17 static unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f};
18 static unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74};
19
20 static unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18};
21 static unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7};
22 static unsigned char BROADCOM_OUI3[] = {0x00, 0x05, 0xb5};
23
24 static unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96};
25 static unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43};
26 static unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43};
27 static unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c};
28 static unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5};
29 static unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
30 static unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
31
32 extern unsigned char RTW_WPA_OUI[];
33 extern unsigned char WPA_TKIP_CIPHER[4];
34
35 #define R2T_PHY_DELAY (0)
36
37 /* define WAIT_FOR_BCN_TO_MIN (3000) */
38 #define WAIT_FOR_BCN_TO_MIN (6000)
39 #define WAIT_FOR_BCN_TO_MAX (20000)
40
41 #define DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS 1000
42 #define DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD 3
43
44 static u8 rtw_basic_rate_cck[4] = {
45 IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK,
46 IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
47 IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK,
48 IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK
49 };
50
51 static u8 rtw_basic_rate_ofdm[3] = {
52 IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK,
53 IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
54 IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
55 };
56
cckrates_included(unsigned char * rate,int ratelen)57 int cckrates_included(unsigned char *rate, int ratelen)
58 {
59 int i;
60
61 for (i = 0; i < ratelen; i++) {
62 if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
63 (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
64 return true;
65 }
66
67 return false;
68 }
69
cckratesonly_included(unsigned char * rate,int ratelen)70 int cckratesonly_included(unsigned char *rate, int ratelen)
71 {
72 int i;
73
74 for (i = 0; i < ratelen; i++) {
75 if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
76 (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
77 return false;
78 }
79
80 return true;
81 }
82
networktype_to_raid_ex(struct adapter * adapter,struct sta_info * psta)83 u8 networktype_to_raid_ex(struct adapter *adapter, struct sta_info *psta)
84 {
85 u8 raid, cur_rf_type, rf_type = RF_1T1R;
86
87 rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&cur_rf_type));
88
89 if (cur_rf_type == RF_1T1R) {
90 rf_type = RF_1T1R;
91 } else if (IsSupportedVHT(psta->wireless_mode)) {
92 if (psta->ra_mask & 0xffc00000)
93 rf_type = RF_2T2R;
94 } else if (IsSupportedHT(psta->wireless_mode)) {
95 if (psta->ra_mask & 0xfff00000)
96 rf_type = RF_2T2R;
97 }
98
99 switch (psta->wireless_mode) {
100 case WIRELESS_11B:
101 raid = RATEID_IDX_B;
102 break;
103 case WIRELESS_11A:
104 case WIRELESS_11G:
105 raid = RATEID_IDX_G;
106 break;
107 case WIRELESS_11BG:
108 raid = RATEID_IDX_BG;
109 break;
110 case WIRELESS_11_24N:
111 case WIRELESS_11_5N:
112 case WIRELESS_11A_5N:
113 case WIRELESS_11G_24N:
114 if (rf_type == RF_2T2R)
115 raid = RATEID_IDX_GN_N2SS;
116 else
117 raid = RATEID_IDX_GN_N1SS;
118 break;
119 case WIRELESS_11B_24N:
120 case WIRELESS_11BG_24N:
121 if (psta->bw_mode == CHANNEL_WIDTH_20) {
122 if (rf_type == RF_2T2R)
123 raid = RATEID_IDX_BGN_20M_2SS_BN;
124 else
125 raid = RATEID_IDX_BGN_20M_1SS_BN;
126 } else {
127 if (rf_type == RF_2T2R)
128 raid = RATEID_IDX_BGN_40M_2SS;
129 else
130 raid = RATEID_IDX_BGN_40M_1SS;
131 }
132 break;
133 default:
134 raid = RATEID_IDX_BGN_40M_2SS;
135 break;
136 }
137 return raid;
138 }
139
140 unsigned char ratetbl_val_2wifirate(unsigned char rate);
ratetbl_val_2wifirate(unsigned char rate)141 unsigned char ratetbl_val_2wifirate(unsigned char rate)
142 {
143 switch (rate & 0x7f) {
144 case 0:
145 return IEEE80211_CCK_RATE_1MB;
146 case 1:
147 return IEEE80211_CCK_RATE_2MB;
148 case 2:
149 return IEEE80211_CCK_RATE_5MB;
150 case 3:
151 return IEEE80211_CCK_RATE_11MB;
152 case 4:
153 return IEEE80211_OFDM_RATE_6MB;
154 case 5:
155 return IEEE80211_OFDM_RATE_9MB;
156 case 6:
157 return IEEE80211_OFDM_RATE_12MB;
158 case 7:
159 return IEEE80211_OFDM_RATE_18MB;
160 case 8:
161 return IEEE80211_OFDM_RATE_24MB;
162 case 9:
163 return IEEE80211_OFDM_RATE_36MB;
164 case 10:
165 return IEEE80211_OFDM_RATE_48MB;
166 case 11:
167 return IEEE80211_OFDM_RATE_54MB;
168 default:
169 return 0;
170 }
171 }
172
173 int is_basicrate(struct adapter *padapter, unsigned char rate);
is_basicrate(struct adapter * padapter,unsigned char rate)174 int is_basicrate(struct adapter *padapter, unsigned char rate)
175 {
176 int i;
177 unsigned char val;
178 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
179
180 for (i = 0; i < NumRates; i++) {
181 val = pmlmeext->basicrate[i];
182
183 if ((val != 0xff) && (val != 0xfe))
184 if (rate == ratetbl_val_2wifirate(val))
185 return true;
186 }
187
188 return false;
189 }
190
191 unsigned int ratetbl2rateset(struct adapter *padapter, unsigned char *rateset);
ratetbl2rateset(struct adapter * padapter,unsigned char * rateset)192 unsigned int ratetbl2rateset(struct adapter *padapter, unsigned char *rateset)
193 {
194 int i;
195 unsigned char rate;
196 unsigned int len = 0;
197 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
198
199 for (i = 0; i < NumRates; i++) {
200 rate = pmlmeext->datarate[i];
201
202 switch (rate) {
203 case 0xff:
204 return len;
205
206 case 0xfe:
207 continue;
208
209 default:
210 rate = ratetbl_val_2wifirate(rate);
211
212 if (is_basicrate(padapter, rate) == true)
213 rate |= IEEE80211_BASIC_RATE_MASK;
214
215 rateset[len] = rate;
216 len++;
217 break;
218 }
219 }
220 return len;
221 }
222
get_rate_set(struct adapter * padapter,unsigned char * pbssrate,int * bssrate_len)223 void get_rate_set(struct adapter *padapter, unsigned char *pbssrate, int *bssrate_len)
224 {
225 unsigned char supportedrates[NumRates];
226
227 memset(supportedrates, 0, NumRates);
228 *bssrate_len = ratetbl2rateset(padapter, supportedrates);
229 memcpy(pbssrate, supportedrates, *bssrate_len);
230 }
231
set_mcs_rate_by_mask(u8 * mcs_set,u32 mask)232 void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask)
233 {
234 u8 mcs_rate_1r = (u8)(mask&0xff);
235 u8 mcs_rate_2r = (u8)((mask>>8)&0xff);
236 u8 mcs_rate_3r = (u8)((mask>>16)&0xff);
237 u8 mcs_rate_4r = (u8)((mask>>24)&0xff);
238
239 mcs_set[0] &= mcs_rate_1r;
240 mcs_set[1] &= mcs_rate_2r;
241 mcs_set[2] &= mcs_rate_3r;
242 mcs_set[3] &= mcs_rate_4r;
243 }
244
UpdateBrateTbl(struct adapter * Adapter,u8 * mBratesOS)245 void UpdateBrateTbl(struct adapter *Adapter, u8 *mBratesOS)
246 {
247 u8 i;
248 u8 rate;
249
250 /* 1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory. */
251 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
252 rate = mBratesOS[i] & 0x7f;
253 switch (rate) {
254 case IEEE80211_CCK_RATE_1MB:
255 case IEEE80211_CCK_RATE_2MB:
256 case IEEE80211_CCK_RATE_5MB:
257 case IEEE80211_CCK_RATE_11MB:
258 case IEEE80211_OFDM_RATE_6MB:
259 case IEEE80211_OFDM_RATE_12MB:
260 case IEEE80211_OFDM_RATE_24MB:
261 mBratesOS[i] |= IEEE80211_BASIC_RATE_MASK;
262 break;
263 }
264 }
265 }
266
UpdateBrateTblForSoftAP(u8 * bssrateset,u32 bssratelen)267 void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen)
268 {
269 u8 i;
270 u8 rate;
271
272 for (i = 0; i < bssratelen; i++) {
273 rate = bssrateset[i] & 0x7f;
274 switch (rate) {
275 case IEEE80211_CCK_RATE_1MB:
276 case IEEE80211_CCK_RATE_2MB:
277 case IEEE80211_CCK_RATE_5MB:
278 case IEEE80211_CCK_RATE_11MB:
279 bssrateset[i] |= IEEE80211_BASIC_RATE_MASK;
280 break;
281 }
282 }
283 }
284
Save_DM_Func_Flag(struct adapter * padapter)285 void Save_DM_Func_Flag(struct adapter *padapter)
286 {
287 u8 bSaveFlag = true;
288 rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag));
289 }
290
Restore_DM_Func_Flag(struct adapter * padapter)291 void Restore_DM_Func_Flag(struct adapter *padapter)
292 {
293 u8 bSaveFlag = false;
294 rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_OP, (u8 *)(&bSaveFlag));
295 }
296
Switch_DM_Func(struct adapter * padapter,u32 mode,u8 enable)297 void Switch_DM_Func(struct adapter *padapter, u32 mode, u8 enable)
298 {
299 if (enable == true)
300 rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_SET, (u8 *)(&mode));
301 else
302 rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode));
303 }
304
Set_NETYPE0_MSR(struct adapter * padapter,u8 type)305 static void Set_NETYPE0_MSR(struct adapter *padapter, u8 type)
306 {
307 rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
308 }
309
Set_MSR(struct adapter * padapter,u8 type)310 void Set_MSR(struct adapter *padapter, u8 type)
311 {
312 Set_NETYPE0_MSR(padapter, type);
313 }
314
rtw_get_oper_ch(struct adapter * adapter)315 inline u8 rtw_get_oper_ch(struct adapter *adapter)
316 {
317 return adapter_to_dvobj(adapter)->oper_channel;
318 }
319
rtw_set_oper_ch(struct adapter * adapter,u8 ch)320 inline void rtw_set_oper_ch(struct adapter *adapter, u8 ch)
321 {
322 #ifdef DBG_CH_SWITCH
323 const int len = 128;
324 char msg[128] = {0};
325 int cnt = 0;
326 int i = 0;
327 #endif /* DBG_CH_SWITCH */
328 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
329
330 if (dvobj->oper_channel != ch) {
331 dvobj->on_oper_ch_time = jiffies;
332
333 #ifdef DBG_CH_SWITCH
334 cnt += snprintf(msg+cnt, len-cnt, "switch to ch %3u", ch);
335
336 for (i = 0; i < dvobj->iface_nums; i++) {
337 struct adapter *iface = dvobj->padapters[i];
338 cnt += snprintf(msg+cnt, len-cnt, " ["ADPT_FMT":", ADPT_ARG(iface));
339 if (iface->mlmeextpriv.cur_channel == ch)
340 cnt += snprintf(msg+cnt, len-cnt, "C");
341 else
342 cnt += snprintf(msg+cnt, len-cnt, "_");
343 if (iface->wdinfo.listen_channel == ch && !rtw_p2p_chk_state(&iface->wdinfo, P2P_STATE_NONE))
344 cnt += snprintf(msg+cnt, len-cnt, "L");
345 else
346 cnt += snprintf(msg+cnt, len-cnt, "_");
347 cnt += snprintf(msg+cnt, len-cnt, "]");
348 }
349
350 DBG_871X(FUNC_ADPT_FMT" %s\n", FUNC_ADPT_ARG(adapter), msg);
351 #endif /* DBG_CH_SWITCH */
352 }
353
354 dvobj->oper_channel = ch;
355 }
356
rtw_get_oper_bw(struct adapter * adapter)357 inline u8 rtw_get_oper_bw(struct adapter *adapter)
358 {
359 return adapter_to_dvobj(adapter)->oper_bwmode;
360 }
361
rtw_set_oper_bw(struct adapter * adapter,u8 bw)362 inline void rtw_set_oper_bw(struct adapter *adapter, u8 bw)
363 {
364 adapter_to_dvobj(adapter)->oper_bwmode = bw;
365 }
366
rtw_get_oper_choffset(struct adapter * adapter)367 inline u8 rtw_get_oper_choffset(struct adapter *adapter)
368 {
369 return adapter_to_dvobj(adapter)->oper_ch_offset;
370 }
371
rtw_set_oper_choffset(struct adapter * adapter,u8 offset)372 inline void rtw_set_oper_choffset(struct adapter *adapter, u8 offset)
373 {
374 adapter_to_dvobj(adapter)->oper_ch_offset = offset;
375 }
376
rtw_get_center_ch(u8 channel,u8 chnl_bw,u8 chnl_offset)377 u8 rtw_get_center_ch(u8 channel, u8 chnl_bw, u8 chnl_offset)
378 {
379 u8 center_ch = channel;
380
381 if (chnl_bw == CHANNEL_WIDTH_80) {
382 if ((channel == 36) || (channel == 40) || (channel == 44) || (channel == 48))
383 center_ch = 42;
384 if ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
385 center_ch = 58;
386 if ((channel == 100) || (channel == 104) || (channel == 108) || (channel == 112))
387 center_ch = 106;
388 if ((channel == 116) || (channel == 120) || (channel == 124) || (channel == 128))
389 center_ch = 122;
390 if ((channel == 132) || (channel == 136) || (channel == 140) || (channel == 144))
391 center_ch = 138;
392 if ((channel == 149) || (channel == 153) || (channel == 157) || (channel == 161))
393 center_ch = 155;
394 else if (channel <= 14)
395 center_ch = 7;
396 } else if (chnl_bw == CHANNEL_WIDTH_40) {
397 if (chnl_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
398 center_ch = channel + 2;
399 else
400 center_ch = channel - 2;
401 }
402
403 return center_ch;
404 }
405
rtw_get_on_cur_ch_time(struct adapter * adapter)406 inline unsigned long rtw_get_on_cur_ch_time(struct adapter *adapter)
407 {
408 if (adapter->mlmeextpriv.cur_channel == adapter_to_dvobj(adapter)->oper_channel)
409 return adapter_to_dvobj(adapter)->on_oper_ch_time;
410 else
411 return 0;
412 }
413
SelectChannel(struct adapter * padapter,unsigned char channel)414 void SelectChannel(struct adapter *padapter, unsigned char channel)
415 {
416 if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->setch_mutex)))
417 return;
418
419 /* saved channel info */
420 rtw_set_oper_ch(padapter, channel);
421
422 rtw_hal_set_chan(padapter, channel);
423
424 mutex_unlock(&(adapter_to_dvobj(padapter)->setch_mutex));
425 }
426
set_channel_bwmode(struct adapter * padapter,unsigned char channel,unsigned char channel_offset,unsigned short bwmode)427 void set_channel_bwmode(struct adapter *padapter, unsigned char channel, unsigned char channel_offset, unsigned short bwmode)
428 {
429 u8 center_ch, chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
430
431 if (padapter->bNotifyChannelChange)
432 DBG_871X("[%s] ch = %d, offset = %d, bwmode = %d\n", __func__, channel, channel_offset, bwmode);
433
434 center_ch = rtw_get_center_ch(channel, bwmode, channel_offset);
435
436 if (bwmode == CHANNEL_WIDTH_80) {
437 if (center_ch > channel)
438 chnl_offset80 = HAL_PRIME_CHNL_OFFSET_LOWER;
439 else if (center_ch < channel)
440 chnl_offset80 = HAL_PRIME_CHNL_OFFSET_UPPER;
441 else
442 chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
443 }
444
445 /* set Channel */
446 if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->setch_mutex)))
447 return;
448
449 /* saved channel/bw info */
450 rtw_set_oper_ch(padapter, channel);
451 rtw_set_oper_bw(padapter, bwmode);
452 rtw_set_oper_choffset(padapter, channel_offset);
453
454 rtw_hal_set_chnl_bw(padapter, center_ch, bwmode, channel_offset, chnl_offset80); /* set center channel */
455
456 mutex_unlock(&(adapter_to_dvobj(padapter)->setch_mutex));
457 }
458
get_my_bssid(struct wlan_bssid_ex * pnetwork)459 __inline u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork)
460 {
461 return pnetwork->MacAddress;
462 }
463
get_beacon_interval(struct wlan_bssid_ex * bss)464 u16 get_beacon_interval(struct wlan_bssid_ex *bss)
465 {
466 __le16 val;
467 memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2);
468
469 return le16_to_cpu(val);
470 }
471
is_client_associated_to_ap(struct adapter * padapter)472 int is_client_associated_to_ap(struct adapter *padapter)
473 {
474 struct mlme_ext_priv *pmlmeext;
475 struct mlme_ext_info *pmlmeinfo;
476
477 if (!padapter)
478 return _FAIL;
479
480 pmlmeext = &padapter->mlmeextpriv;
481 pmlmeinfo = &(pmlmeext->mlmext_info);
482
483 if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE))
484 return true;
485 else
486 return _FAIL;
487 }
488
is_client_associated_to_ibss(struct adapter * padapter)489 int is_client_associated_to_ibss(struct adapter *padapter)
490 {
491 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
492 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
493
494 if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE))
495 return true;
496 else
497 return _FAIL;
498 }
499
is_IBSS_empty(struct adapter * padapter)500 int is_IBSS_empty(struct adapter *padapter)
501 {
502 unsigned int i;
503 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
504 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
505
506 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
507 if (pmlmeinfo->FW_sta_info[i].status == 1)
508 return _FAIL;
509 }
510
511 return true;
512 }
513
decide_wait_for_beacon_timeout(unsigned int bcn_interval)514 unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval)
515 {
516 if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN)
517 return WAIT_FOR_BCN_TO_MIN;
518 else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX)
519 return WAIT_FOR_BCN_TO_MAX;
520 else
521 return ((bcn_interval << 2));
522 }
523
invalidate_cam_all(struct adapter * padapter)524 void invalidate_cam_all(struct adapter *padapter)
525 {
526 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
527 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
528
529 rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, NULL);
530
531 spin_lock_bh(&cam_ctl->lock);
532 cam_ctl->bitmap = 0;
533 memset(dvobj->cam_cache, 0, sizeof(struct cam_entry_cache)*TOTAL_CAM_ENTRY);
534 spin_unlock_bh(&cam_ctl->lock);
535 }
536
_ReadCAM(struct adapter * padapter,u32 addr)537 static u32 _ReadCAM(struct adapter *padapter, u32 addr)
538 {
539 u32 count = 0, cmd;
540 cmd = CAM_POLLINIG | addr;
541 rtw_write32(padapter, RWCAM, cmd);
542
543 do {
544 if (0 == (rtw_read32(padapter, REG_CAMCMD) & CAM_POLLINIG))
545 break;
546 } while (count++ < 100);
547
548 return rtw_read32(padapter, REG_CAMREAD);
549 }
read_cam(struct adapter * padapter,u8 entry,u8 * get_key)550 void read_cam(struct adapter *padapter, u8 entry, u8 *get_key)
551 {
552 u32 j, addr, cmd;
553 addr = entry << 3;
554
555 /* DBG_8192C("********* DUMP CAM Entry_#%02d***************\n", entry); */
556 for (j = 0; j < 6; j++) {
557 cmd = _ReadCAM(padapter, addr+j);
558 /* DBG_8192C("offset:0x%02x => 0x%08x\n", addr+j, cmd); */
559 if (j > 1) /* get key from cam */
560 memcpy(get_key+(j-2)*4, &cmd, 4);
561 }
562 /* DBG_8192C("*********************************\n"); */
563 }
564
_write_cam(struct adapter * padapter,u8 entry,u16 ctrl,u8 * mac,u8 * key)565 void _write_cam(struct adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key)
566 {
567 unsigned int i, val, addr;
568 int j;
569 u32 cam_val[2];
570
571 addr = entry << 3;
572
573 for (j = 5; j >= 0; j--) {
574 switch (j) {
575 case 0:
576 val = (ctrl | (mac[0] << 16) | (mac[1] << 24));
577 break;
578 case 1:
579 val = (mac[2] | (mac[3] << 8) | (mac[4] << 16) | (mac[5] << 24));
580 break;
581 default:
582 i = (j - 2) << 2;
583 val = (key[i] | (key[i+1] << 8) | (key[i+2] << 16) | (key[i+3] << 24));
584 break;
585 }
586
587 cam_val[0] = val;
588 cam_val[1] = addr + (unsigned int)j;
589
590 rtw_hal_set_hwreg(padapter, HW_VAR_CAM_WRITE, (u8 *)cam_val);
591 }
592 }
593
_clear_cam_entry(struct adapter * padapter,u8 entry)594 void _clear_cam_entry(struct adapter *padapter, u8 entry)
595 {
596 unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
597 unsigned char null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
598
599 _write_cam(padapter, entry, 0, null_sta, null_key);
600 }
601
write_cam(struct adapter * adapter,u8 id,u16 ctrl,u8 * mac,u8 * key)602 inline void write_cam(struct adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key)
603 {
604 _write_cam(adapter, id, ctrl, mac, key);
605 write_cam_cache(adapter, id, ctrl, mac, key);
606 }
607
clear_cam_entry(struct adapter * adapter,u8 id)608 inline void clear_cam_entry(struct adapter *adapter, u8 id)
609 {
610 _clear_cam_entry(adapter, id);
611 clear_cam_cache(adapter, id);
612 }
613
write_cam_from_cache(struct adapter * adapter,u8 id)614 inline void write_cam_from_cache(struct adapter *adapter, u8 id)
615 {
616 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
617 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
618 struct cam_entry_cache cache;
619
620 spin_lock_bh(&cam_ctl->lock);
621 memcpy(&cache, &dvobj->cam_cache[id], sizeof(struct cam_entry_cache));
622 spin_unlock_bh(&cam_ctl->lock);
623
624 _write_cam(adapter, id, cache.ctrl, cache.mac, cache.key);
625 }
626
write_cam_cache(struct adapter * adapter,u8 id,u16 ctrl,u8 * mac,u8 * key)627 void write_cam_cache(struct adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key)
628 {
629 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
630 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
631
632 spin_lock_bh(&cam_ctl->lock);
633
634 dvobj->cam_cache[id].ctrl = ctrl;
635 memcpy(dvobj->cam_cache[id].mac, mac, ETH_ALEN);
636 memcpy(dvobj->cam_cache[id].key, key, 16);
637
638 spin_unlock_bh(&cam_ctl->lock);
639 }
640
clear_cam_cache(struct adapter * adapter,u8 id)641 void clear_cam_cache(struct adapter *adapter, u8 id)
642 {
643 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
644 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
645
646 spin_lock_bh(&cam_ctl->lock);
647
648 memset(&(dvobj->cam_cache[id]), 0, sizeof(struct cam_entry_cache));
649
650 spin_unlock_bh(&cam_ctl->lock);
651 }
652
_rtw_camid_is_gk(struct adapter * adapter,u8 cam_id)653 static bool _rtw_camid_is_gk(struct adapter *adapter, u8 cam_id)
654 {
655 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
656 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
657 bool ret = false;
658
659 if (cam_id >= TOTAL_CAM_ENTRY)
660 goto exit;
661
662 if (!(cam_ctl->bitmap & BIT(cam_id)))
663 goto exit;
664
665 ret = (dvobj->cam_cache[cam_id].ctrl&BIT6)?true:false;
666
667 exit:
668 return ret;
669 }
670
_rtw_camid_search(struct adapter * adapter,u8 * addr,s16 kid)671 static s16 _rtw_camid_search(struct adapter *adapter, u8 *addr, s16 kid)
672 {
673 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
674 int i;
675 s16 cam_id = -1;
676
677 for (i = 0; i < TOTAL_CAM_ENTRY; i++) {
678 if (addr && memcmp(dvobj->cam_cache[i].mac, addr, ETH_ALEN))
679 continue;
680 if (kid >= 0 && kid != (dvobj->cam_cache[i].ctrl&0x03))
681 continue;
682
683 cam_id = i;
684 break;
685 }
686
687 if (addr)
688 DBG_871X(FUNC_ADPT_FMT" addr:"MAC_FMT" kid:%d, return cam_id:%d\n"
689 , FUNC_ADPT_ARG(adapter), MAC_ARG(addr), kid, cam_id);
690 else
691 DBG_871X(FUNC_ADPT_FMT" addr:%p kid:%d, return cam_id:%d\n"
692 , FUNC_ADPT_ARG(adapter), addr, kid, cam_id);
693
694 return cam_id;
695 }
696
rtw_camid_search(struct adapter * adapter,u8 * addr,s16 kid)697 s16 rtw_camid_search(struct adapter *adapter, u8 *addr, s16 kid)
698 {
699 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
700 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
701 s16 cam_id = -1;
702
703 spin_lock_bh(&cam_ctl->lock);
704 cam_id = _rtw_camid_search(adapter, addr, kid);
705 spin_unlock_bh(&cam_ctl->lock);
706
707 return cam_id;
708 }
709
rtw_camid_alloc(struct adapter * adapter,struct sta_info * sta,u8 kid)710 s16 rtw_camid_alloc(struct adapter *adapter, struct sta_info *sta, u8 kid)
711 {
712 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
713 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
714 s16 cam_id = -1;
715 struct mlme_ext_info *mlmeinfo;
716
717 spin_lock_bh(&cam_ctl->lock);
718
719 mlmeinfo = &adapter->mlmeextpriv.mlmext_info;
720
721 if ((((mlmeinfo->state&0x03) == WIFI_FW_AP_STATE) || ((mlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE))
722 && !sta) {
723 /* AP/Ad-hoc mode group key: static alloction to default key by key ID */
724 if (kid > 3) {
725 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" group key with invalid key id:%u\n"
726 , FUNC_ADPT_ARG(adapter), kid);
727 rtw_warn_on(1);
728 goto bitmap_handle;
729 }
730
731 cam_id = kid;
732 } else {
733 int i;
734 u8 *addr = sta?sta->hwaddr:NULL;
735
736 if (!sta) {
737 if (!(mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
738 /* bypass STA mode group key setting before connected(ex:WEP) because bssid is not ready */
739 goto bitmap_handle;
740 }
741
742 addr = get_bssid(&adapter->mlmepriv);
743 }
744
745 i = _rtw_camid_search(adapter, addr, kid);
746 if (i >= 0) {
747 /* Fix issue that pairwise and group key have same key id. Pairwise key first, group key can overwirte group only(ex: rekey) */
748 if (sta || _rtw_camid_is_gk(adapter, i) == true)
749 cam_id = i;
750 else
751 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" group key id:%u the same key id as pairwise key\n"
752 , FUNC_ADPT_ARG(adapter), kid);
753 goto bitmap_handle;
754 }
755
756 for (i = 4; i < TOTAL_CAM_ENTRY; i++)
757 if (!(cam_ctl->bitmap & BIT(i)))
758 break;
759
760 if (i == TOTAL_CAM_ENTRY) {
761 if (sta)
762 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" pairwise key with "MAC_FMT" id:%u no room\n"
763 , FUNC_ADPT_ARG(adapter), MAC_ARG(sta->hwaddr), kid);
764 else
765 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" group key id:%u no room\n"
766 , FUNC_ADPT_ARG(adapter), kid);
767 rtw_warn_on(1);
768 goto bitmap_handle;
769 }
770
771 cam_id = i;
772 }
773
774 bitmap_handle:
775 if (cam_id >= 0 && cam_id < 32)
776 cam_ctl->bitmap |= BIT(cam_id);
777
778 spin_unlock_bh(&cam_ctl->lock);
779
780 return cam_id;
781 }
782
rtw_camid_free(struct adapter * adapter,u8 cam_id)783 void rtw_camid_free(struct adapter *adapter, u8 cam_id)
784 {
785 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
786 struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
787
788 spin_lock_bh(&cam_ctl->lock);
789
790 if (cam_id < TOTAL_CAM_ENTRY)
791 cam_ctl->bitmap &= ~(BIT(cam_id));
792
793 spin_unlock_bh(&cam_ctl->lock);
794 }
795
allocate_fw_sta_entry(struct adapter * padapter)796 int allocate_fw_sta_entry(struct adapter *padapter)
797 {
798 unsigned int mac_id;
799 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
800 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
801
802 for (mac_id = IBSS_START_MAC_ID; mac_id < NUM_STA; mac_id++) {
803 if (pmlmeinfo->FW_sta_info[mac_id].status == 0) {
804 pmlmeinfo->FW_sta_info[mac_id].status = 1;
805 pmlmeinfo->FW_sta_info[mac_id].retry = 0;
806 break;
807 }
808 }
809
810 return mac_id;
811 }
812
flush_all_cam_entry(struct adapter * padapter)813 void flush_all_cam_entry(struct adapter *padapter)
814 {
815 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
816 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
817
818 invalidate_cam_all(padapter);
819 /* clear default key related key search setting */
820 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8 *)false);
821
822 memset((u8 *)(pmlmeinfo->FW_sta_info), 0, sizeof(pmlmeinfo->FW_sta_info));
823 }
824
WMM_param_handler(struct adapter * padapter,struct ndis_80211_var_ie * pIE)825 int WMM_param_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
826 {
827 /* struct registry_priv *pregpriv = &padapter->registrypriv; */
828 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
829 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
830 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
831
832 if (pmlmepriv->qospriv.qos_option == 0) {
833 pmlmeinfo->WMM_enable = 0;
834 return false;
835 }
836
837 if (!memcmp(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element)))
838 return false;
839 else
840 memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
841
842 pmlmeinfo->WMM_enable = 1;
843 return true;
844 }
845
WMMOnAssocRsp(struct adapter * padapter)846 void WMMOnAssocRsp(struct adapter *padapter)
847 {
848 u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
849 u8 acm_mask;
850 u16 TXOP;
851 u32 acParm, i;
852 u32 edca[4], inx[4];
853 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
854 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
855 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
856 struct registry_priv *pregpriv = &padapter->registrypriv;
857
858 acm_mask = 0;
859
860 if (pmlmeext->cur_wireless_mode & WIRELESS_11_24N)
861 aSifsTime = 16;
862 else
863 aSifsTime = 10;
864
865 if (pmlmeinfo->WMM_enable == 0) {
866 padapter->mlmepriv.acm_mask = 0;
867
868 AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
869
870 if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11A)) {
871 ECWMin = 4;
872 ECWMax = 10;
873 } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
874 ECWMin = 5;
875 ECWMax = 10;
876 } else {
877 ECWMin = 4;
878 ECWMax = 10;
879 }
880
881 TXOP = 0;
882 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
883 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
884 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
885 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
886
887 ECWMin = 2;
888 ECWMax = 3;
889 TXOP = 0x2f;
890 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
891 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
892 } else{
893 edca[0] = edca[1] = edca[2] = edca[3] = 0;
894
895 for (i = 0; i < 4; i++) {
896 ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
897 ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
898
899 /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
900 AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) * pmlmeinfo->slotTime + aSifsTime;
901
902 ECWMin = (pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f);
903 ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4;
904 TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit);
905
906 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
907
908 switch (ACI) {
909 case 0x0:
910 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
911 acm_mask |= (ACM ? BIT(1):0);
912 edca[XMIT_BE_QUEUE] = acParm;
913 break;
914
915 case 0x1:
916 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
917 /* acm_mask |= (ACM? BIT(0):0); */
918 edca[XMIT_BK_QUEUE] = acParm;
919 break;
920
921 case 0x2:
922 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
923 acm_mask |= (ACM ? BIT(2):0);
924 edca[XMIT_VI_QUEUE] = acParm;
925 break;
926
927 case 0x3:
928 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
929 acm_mask |= (ACM ? BIT(3):0);
930 edca[XMIT_VO_QUEUE] = acParm;
931 break;
932 }
933
934 DBG_871X("WMM(%x): %x, %x\n", ACI, ACM, acParm);
935 }
936
937 if (padapter->registrypriv.acm_method == 1)
938 rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
939 else
940 padapter->mlmepriv.acm_mask = acm_mask;
941
942 inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
943
944 if (pregpriv->wifi_spec == 1) {
945 u32 j, tmp, change_inx = false;
946
947 /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
948 for (i = 0; i < 4; i++) {
949 for (j = i+1; j < 4; j++) {
950 /* compare CW and AIFS */
951 if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF)) {
952 change_inx = true;
953 } else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
954 /* compare TXOP */
955 if ((edca[j] >> 16) > (edca[i] >> 16))
956 change_inx = true;
957 }
958
959 if (change_inx) {
960 tmp = edca[i];
961 edca[i] = edca[j];
962 edca[j] = tmp;
963
964 tmp = inx[i];
965 inx[i] = inx[j];
966 inx[j] = tmp;
967
968 change_inx = false;
969 }
970 }
971 }
972 }
973
974 for (i = 0; i < 4; i++) {
975 pxmitpriv->wmm_para_seq[i] = inx[i];
976 DBG_871X("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
977 }
978 }
979 }
980
bwmode_update_check(struct adapter * padapter,struct ndis_80211_var_ie * pIE)981 static void bwmode_update_check(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
982 {
983 unsigned char new_bwmode;
984 unsigned char new_ch_offset;
985 struct HT_info_element *pHT_info;
986 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
987 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
988 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
989 struct registry_priv *pregistrypriv = &padapter->registrypriv;
990 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
991 u8 cbw40_enable = 0;
992
993 if (!pIE)
994 return;
995
996 if (phtpriv->ht_option == false)
997 return;
998
999 if (pmlmeext->cur_bwmode >= CHANNEL_WIDTH_80)
1000 return;
1001
1002 if (pIE->Length > sizeof(struct HT_info_element))
1003 return;
1004
1005 pHT_info = (struct HT_info_element *)pIE->data;
1006
1007 if (pmlmeext->cur_channel > 14) {
1008 if ((pregistrypriv->bw_mode & 0xf0) > 0)
1009 cbw40_enable = 1;
1010 } else
1011 if ((pregistrypriv->bw_mode & 0x0f) > 0)
1012 cbw40_enable = 1;
1013
1014 if ((pHT_info->infos[0] & BIT(2)) && cbw40_enable) {
1015 new_bwmode = CHANNEL_WIDTH_40;
1016
1017 switch (pHT_info->infos[0] & 0x3) {
1018 case 1:
1019 new_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
1020 break;
1021
1022 case 3:
1023 new_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
1024 break;
1025
1026 default:
1027 new_bwmode = CHANNEL_WIDTH_20;
1028 new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1029 break;
1030 }
1031 } else{
1032 new_bwmode = CHANNEL_WIDTH_20;
1033 new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1034 }
1035
1036 if ((new_bwmode != pmlmeext->cur_bwmode) || (new_ch_offset != pmlmeext->cur_ch_offset)) {
1037 pmlmeinfo->bwmode_updated = true;
1038
1039 pmlmeext->cur_bwmode = new_bwmode;
1040 pmlmeext->cur_ch_offset = new_ch_offset;
1041
1042 /* update HT info also */
1043 HT_info_handler(padapter, pIE);
1044 } else
1045 pmlmeinfo->bwmode_updated = false;
1046
1047 if (true == pmlmeinfo->bwmode_updated) {
1048 struct sta_info *psta;
1049 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
1050 struct sta_priv *pstapriv = &padapter->stapriv;
1051
1052 /* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
1053
1054 /* update ap's stainfo */
1055 psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
1056 if (psta) {
1057 struct ht_priv *phtpriv_sta = &psta->htpriv;
1058
1059 if (phtpriv_sta->ht_option) {
1060 /* bwmode */
1061 psta->bw_mode = pmlmeext->cur_bwmode;
1062 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
1063 } else{
1064 psta->bw_mode = CHANNEL_WIDTH_20;
1065 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1066 }
1067
1068 rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta);
1069 }
1070 }
1071 }
1072
HT_caps_handler(struct adapter * padapter,struct ndis_80211_var_ie * pIE)1073 void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
1074 {
1075 unsigned int i;
1076 u8 rf_type;
1077 u8 max_AMPDU_len, min_MPDU_spacing;
1078 u8 cur_ldpc_cap = 0, cur_stbc_cap = 0;
1079 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1080 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1081 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1082 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1083
1084 if (!pIE)
1085 return;
1086
1087 if (phtpriv->ht_option == false)
1088 return;
1089
1090 pmlmeinfo->HT_caps_enable = 1;
1091
1092 for (i = 0; i < (pIE->Length); i++) {
1093 if (i != 2) {
1094 /* Commented by Albert 2010/07/12 */
1095 /* Got the endian issue here. */
1096 pmlmeinfo->HT_caps.u.HT_cap[i] &= (pIE->data[i]);
1097 } else{
1098 /* modify from fw by Thomas 2010/11/17 */
1099 if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3) > (pIE->data[i] & 0x3))
1100 max_AMPDU_len = (pIE->data[i] & 0x3);
1101 else
1102 max_AMPDU_len = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3);
1103
1104 if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) > (pIE->data[i] & 0x1c))
1105 min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c);
1106 else
1107 min_MPDU_spacing = (pIE->data[i] & 0x1c);
1108
1109 pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para = max_AMPDU_len | min_MPDU_spacing;
1110 }
1111 }
1112 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
1113
1114 /* update the MCS set */
1115 for (i = 0; i < 16; i++)
1116 pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= pmlmeext->default_supported_mcs_set[i];
1117
1118 /* update the MCS rates */
1119 switch (rf_type) {
1120 case RF_1T1R:
1121 case RF_1T2R:
1122 set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_1R);
1123 break;
1124 case RF_2T2R:
1125 default:
1126 #ifdef CONFIG_DISABLE_MCS13TO15
1127 if (pmlmeext->cur_bwmode == CHANNEL_WIDTH_40 && pregistrypriv->wifi_spec != 1)
1128 set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_2R_13TO15_OFF);
1129 else
1130 set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_2R);
1131 #else /* CONFIG_DISABLE_MCS13TO15 */
1132 set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_2R);
1133 #endif /* CONFIG_DISABLE_MCS13TO15 */
1134 }
1135
1136 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1137 /* Config STBC setting */
1138 if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && GET_HT_CAPABILITY_ELE_TX_STBC(pIE->data)) {
1139 SET_FLAG(cur_stbc_cap, STBC_HT_ENABLE_TX);
1140 DBG_871X("Enable HT Tx STBC !\n");
1141 }
1142 phtpriv->stbc_cap = cur_stbc_cap;
1143 } else {
1144 /* Config LDPC Coding Capability */
1145 if (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_TX) && GET_HT_CAPABILITY_ELE_LDPC_CAP(pIE->data)) {
1146 SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
1147 DBG_871X("Enable HT Tx LDPC!\n");
1148 }
1149 phtpriv->ldpc_cap = cur_ldpc_cap;
1150
1151 /* Config STBC setting */
1152 if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && GET_HT_CAPABILITY_ELE_RX_STBC(pIE->data)) {
1153 SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
1154 DBG_871X("Enable HT Tx STBC!\n");
1155 }
1156 phtpriv->stbc_cap = cur_stbc_cap;
1157 }
1158 }
1159
HT_info_handler(struct adapter * padapter,struct ndis_80211_var_ie * pIE)1160 void HT_info_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
1161 {
1162 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1163 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1164 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1165 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1166
1167 if (!pIE)
1168 return;
1169
1170 if (phtpriv->ht_option == false)
1171 return;
1172
1173 if (pIE->Length > sizeof(struct HT_info_element))
1174 return;
1175
1176 pmlmeinfo->HT_info_enable = 1;
1177 memcpy(&(pmlmeinfo->HT_info), pIE->data, pIE->Length);
1178
1179 return;
1180 }
1181
HTOnAssocRsp(struct adapter * padapter)1182 void HTOnAssocRsp(struct adapter *padapter)
1183 {
1184 unsigned char max_AMPDU_len;
1185 unsigned char min_MPDU_spacing;
1186 /* struct registry_priv *pregpriv = &padapter->registrypriv; */
1187 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1188 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1189
1190 DBG_871X("%s\n", __func__);
1191
1192 if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable)) {
1193 pmlmeinfo->HT_enable = 1;
1194 } else{
1195 pmlmeinfo->HT_enable = 0;
1196 /* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
1197 return;
1198 }
1199
1200 /* handle A-MPDU parameter field */
1201 /*
1202 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
1203 AMPDU_para [4:2]:Min MPDU Start Spacing
1204 */
1205 max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
1206
1207 min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
1208
1209 rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
1210
1211 rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
1212 }
1213
ERP_IE_handler(struct adapter * padapter,struct ndis_80211_var_ie * pIE)1214 void ERP_IE_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
1215 {
1216 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1217 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1218
1219 if (pIE->Length > 1)
1220 return;
1221
1222 pmlmeinfo->ERP_enable = 1;
1223 memcpy(&(pmlmeinfo->ERP_IE), pIE->data, pIE->Length);
1224 }
1225
VCS_update(struct adapter * padapter,struct sta_info * psta)1226 void VCS_update(struct adapter *padapter, struct sta_info *psta)
1227 {
1228 struct registry_priv *pregpriv = &padapter->registrypriv;
1229 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1230 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1231
1232 switch (pregpriv->vrtl_carrier_sense) {/* 0:off 1:on 2:auto */
1233 case 0: /* off */
1234 psta->rtsen = 0;
1235 psta->cts2self = 0;
1236 break;
1237
1238 case 1: /* on */
1239 if (pregpriv->vcs_type == 1) { /* 1:RTS/CTS 2:CTS to self */
1240 psta->rtsen = 1;
1241 psta->cts2self = 0;
1242 } else{
1243 psta->rtsen = 0;
1244 psta->cts2self = 1;
1245 }
1246 break;
1247
1248 case 2: /* auto */
1249 default:
1250 if ((pmlmeinfo->ERP_enable) && (pmlmeinfo->ERP_IE & BIT(1))) {
1251 if (pregpriv->vcs_type == 1) {
1252 psta->rtsen = 1;
1253 psta->cts2self = 0;
1254 } else{
1255 psta->rtsen = 0;
1256 psta->cts2self = 1;
1257 }
1258 } else{
1259 psta->rtsen = 0;
1260 psta->cts2self = 0;
1261 }
1262 break;
1263 }
1264 }
1265
update_ldpc_stbc_cap(struct sta_info * psta)1266 void update_ldpc_stbc_cap(struct sta_info *psta)
1267 {
1268 if (psta->htpriv.ht_option) {
1269 if (TEST_FLAG(psta->htpriv.ldpc_cap, LDPC_HT_ENABLE_TX))
1270 psta->ldpc = 1;
1271
1272 if (TEST_FLAG(psta->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
1273 psta->stbc = 1;
1274 } else {
1275 psta->ldpc = 0;
1276 psta->stbc = 0;
1277 }
1278 }
1279
rtw_check_bcn_info(struct adapter * Adapter,u8 * pframe,u32 packet_len)1280 int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
1281 {
1282 unsigned int len;
1283 unsigned char *p;
1284 unsigned short val16, subtype;
1285 struct wlan_network *cur_network = &(Adapter->mlmepriv.cur_network);
1286 /* u8 wpa_ie[255], rsn_ie[255]; */
1287 u16 wpa_len = 0, rsn_len = 0;
1288 u8 encryp_protocol = 0;
1289 struct wlan_bssid_ex *bssid;
1290 int group_cipher = 0, pairwise_cipher = 0, is_8021x = 0;
1291 unsigned char *pbuf;
1292 u32 wpa_ielen = 0;
1293 u8 *pbssid = GetAddr3Ptr(pframe);
1294 u32 hidden_ssid = 0;
1295 struct HT_info_element *pht_info = NULL;
1296 struct rtw_ieee80211_ht_cap *pht_cap = NULL;
1297 u32 bcn_channel;
1298 unsigned short ht_cap_info;
1299 unsigned char ht_info_infos_0;
1300 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
1301
1302 if (is_client_associated_to_ap(Adapter) == false)
1303 return true;
1304
1305 len = packet_len - sizeof(struct ieee80211_hdr_3addr);
1306
1307 if (len > MAX_IE_SZ) {
1308 DBG_871X("%s IE too long for survey event\n", __func__);
1309 return _FAIL;
1310 }
1311
1312 if (memcmp(cur_network->network.MacAddress, pbssid, 6)) {
1313 DBG_871X("Oops: rtw_check_network_encrypt linked but recv other bssid bcn\n" MAC_FMT MAC_FMT,
1314 MAC_ARG(pbssid), MAC_ARG(cur_network->network.MacAddress));
1315 return true;
1316 }
1317
1318 bssid = rtw_zmalloc(sizeof(struct wlan_bssid_ex));
1319 if (!bssid) {
1320 DBG_871X("%s rtw_zmalloc fail !!!\n", __func__);
1321 return true;
1322 }
1323
1324 if ((pmlmepriv->timeBcnInfoChkStart != 0) && (jiffies_to_msecs(jiffies - pmlmepriv->timeBcnInfoChkStart) > DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS)) {
1325 pmlmepriv->timeBcnInfoChkStart = 0;
1326 pmlmepriv->NumOfBcnInfoChkFail = 0;
1327 }
1328
1329 subtype = GetFrameSubType(pframe) >> 4;
1330
1331 if (subtype == WIFI_BEACON)
1332 bssid->Reserved[0] = 1;
1333
1334 bssid->Length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len;
1335
1336 /* below is to copy the information element */
1337 bssid->IELength = len;
1338 memcpy(bssid->IEs, (pframe + sizeof(struct ieee80211_hdr_3addr)), bssid->IELength);
1339
1340 /* check bw and channel offset */
1341 /* parsing HT_CAP_IE */
1342 p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
1343 if (p && len > 0) {
1344 pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
1345 ht_cap_info = le16_to_cpu(pht_cap->cap_info);
1346 } else {
1347 ht_cap_info = 0;
1348 }
1349 /* parsing HT_INFO_IE */
1350 p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
1351 if (p && len > 0) {
1352 pht_info = (struct HT_info_element *)(p + 2);
1353 ht_info_infos_0 = pht_info->infos[0];
1354 } else {
1355 ht_info_infos_0 = 0;
1356 }
1357 if (ht_cap_info != cur_network->BcnInfo.ht_cap_info ||
1358 ((ht_info_infos_0&0x03) != (cur_network->BcnInfo.ht_info_infos_0&0x03))) {
1359 DBG_871X("%s bcn now: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
1360 ht_cap_info, ht_info_infos_0);
1361 DBG_871X("%s bcn link: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
1362 cur_network->BcnInfo.ht_cap_info, cur_network->BcnInfo.ht_info_infos_0);
1363 DBG_871X("%s bw mode change\n", __func__);
1364 {
1365 /* bcn_info_update */
1366 cur_network->BcnInfo.ht_cap_info = ht_cap_info;
1367 cur_network->BcnInfo.ht_info_infos_0 = ht_info_infos_0;
1368 /* to do : need to check that whether modify related register of BB or not */
1369 }
1370 /* goto _mismatch; */
1371 }
1372
1373 /* Checking for channel */
1374 p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _DSSET_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
1375 if (p) {
1376 bcn_channel = *(p + 2);
1377 } else {/* In 5G, some ap do not have DSSET IE checking HT info for channel */
1378 rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
1379 if (pht_info) {
1380 bcn_channel = pht_info->primary_channel;
1381 } else { /* we don't find channel IE, so don't check it */
1382 /* DBG_871X("Oops: %s we don't find channel IE, so don't check it\n", __func__); */
1383 bcn_channel = Adapter->mlmeextpriv.cur_channel;
1384 }
1385 }
1386 if (bcn_channel != Adapter->mlmeextpriv.cur_channel) {
1387 DBG_871X("%s beacon channel:%d cur channel:%d disconnect\n", __func__,
1388 bcn_channel, Adapter->mlmeextpriv.cur_channel);
1389 goto _mismatch;
1390 }
1391
1392 /* checking SSID */
1393 p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _SSID_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
1394 if (!p) {
1395 DBG_871X("%s marc: cannot find SSID for survey event\n", __func__);
1396 hidden_ssid = true;
1397 } else {
1398 hidden_ssid = false;
1399 }
1400
1401 if ((NULL != p) && (false == hidden_ssid && (*(p + 1)))) {
1402 memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1));
1403 bssid->Ssid.SsidLength = *(p + 1);
1404 } else {
1405 bssid->Ssid.SsidLength = 0;
1406 bssid->Ssid.Ssid[0] = '\0';
1407 }
1408
1409 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d "
1410 "cur_network->network.Ssid.Ssid:%s len:%d\n", __func__, bssid->Ssid.Ssid,
1411 bssid->Ssid.SsidLength, cur_network->network.Ssid.Ssid,
1412 cur_network->network.Ssid.SsidLength));
1413
1414 if (memcmp(bssid->Ssid.Ssid, cur_network->network.Ssid.Ssid, 32) ||
1415 bssid->Ssid.SsidLength != cur_network->network.Ssid.SsidLength) {
1416 if (bssid->Ssid.Ssid[0] != '\0' && bssid->Ssid.SsidLength != 0) { /* not hidden ssid */
1417 DBG_871X("%s(), SSID is not match\n", __func__);
1418 goto _mismatch;
1419 }
1420 }
1421
1422 /* check encryption info */
1423 val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid);
1424
1425 if (val16 & BIT(4))
1426 bssid->Privacy = 1;
1427 else
1428 bssid->Privacy = 0;
1429
1430 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1431 ("%s(): cur_network->network.Privacy is %d, bssid.Privacy is %d\n",
1432 __func__, cur_network->network.Privacy, bssid->Privacy));
1433 if (cur_network->network.Privacy != bssid->Privacy) {
1434 DBG_871X("%s(), privacy is not match\n", __func__);
1435 goto _mismatch;
1436 }
1437
1438 rtw_get_sec_ie(bssid->IEs, bssid->IELength, NULL, &rsn_len, NULL, &wpa_len);
1439
1440 if (rsn_len > 0) {
1441 encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1442 } else if (wpa_len > 0) {
1443 encryp_protocol = ENCRYP_PROTOCOL_WPA;
1444 } else {
1445 if (bssid->Privacy)
1446 encryp_protocol = ENCRYP_PROTOCOL_WEP;
1447 }
1448
1449 if (cur_network->BcnInfo.encryp_protocol != encryp_protocol) {
1450 DBG_871X("%s(): enctyp is not match\n", __func__);
1451 goto _mismatch;
1452 }
1453
1454 if (encryp_protocol == ENCRYP_PROTOCOL_WPA || encryp_protocol == ENCRYP_PROTOCOL_WPA2) {
1455 pbuf = rtw_get_wpa_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength-12);
1456 if (pbuf && (wpa_ielen > 0)) {
1457 if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is_8021x)) {
1458 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1459 ("%s pnetwork->pairwise_cipher: %d, group_cipher is %d, is_8021x is %d\n", __func__,
1460 pairwise_cipher, group_cipher, is_8021x));
1461 }
1462 } else {
1463 pbuf = rtw_get_wpa2_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength-12);
1464
1465 if (pbuf && (wpa_ielen > 0)) {
1466 if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is_8021x)) {
1467 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1468 ("%s pnetwork->pairwise_cipher: %d, pnetwork->group_cipher is %d, is_802x is %d\n",
1469 __func__, pairwise_cipher, group_cipher, is_8021x));
1470 }
1471 }
1472 }
1473
1474 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
1475 ("%s cur_network->group_cipher is %d: %d\n", __func__, cur_network->BcnInfo.group_cipher, group_cipher));
1476 if (pairwise_cipher != cur_network->BcnInfo.pairwise_cipher || group_cipher != cur_network->BcnInfo.group_cipher) {
1477 DBG_871X("%s pairwise_cipher(%x:%x) or group_cipher(%x:%x) is not match\n", __func__,
1478 pairwise_cipher, cur_network->BcnInfo.pairwise_cipher,
1479 group_cipher, cur_network->BcnInfo.group_cipher);
1480 goto _mismatch;
1481 }
1482
1483 if (is_8021x != cur_network->BcnInfo.is_8021x) {
1484 DBG_871X("%s authentication is not match\n", __func__);
1485 goto _mismatch;
1486 }
1487 }
1488
1489 kfree((u8 *)bssid);
1490 return _SUCCESS;
1491
1492 _mismatch:
1493 kfree((u8 *)bssid);
1494
1495 if (pmlmepriv->NumOfBcnInfoChkFail == 0)
1496 pmlmepriv->timeBcnInfoChkStart = jiffies;
1497
1498 pmlmepriv->NumOfBcnInfoChkFail++;
1499 DBG_871X("%s by "ADPT_FMT" - NumOfChkFail = %d (SeqNum of this Beacon frame = %d).\n", __func__, ADPT_ARG(Adapter), pmlmepriv->NumOfBcnInfoChkFail, GetSequence(pframe));
1500
1501 if ((pmlmepriv->timeBcnInfoChkStart != 0) && (jiffies_to_msecs(jiffies - pmlmepriv->timeBcnInfoChkStart) <= DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS)
1502 && (pmlmepriv->NumOfBcnInfoChkFail >= DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD)) {
1503 DBG_871X("%s by "ADPT_FMT" - NumOfChkFail = %d >= threshold : %d (in %d ms), return FAIL.\n", __func__, ADPT_ARG(Adapter), pmlmepriv->NumOfBcnInfoChkFail,
1504 DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD, jiffies_to_msecs(jiffies - pmlmepriv->timeBcnInfoChkStart));
1505 pmlmepriv->timeBcnInfoChkStart = 0;
1506 pmlmepriv->NumOfBcnInfoChkFail = 0;
1507 return _FAIL;
1508 }
1509
1510 return _SUCCESS;
1511 }
1512
update_beacon_info(struct adapter * padapter,u8 * pframe,uint pkt_len,struct sta_info * psta)1513 void update_beacon_info(struct adapter *padapter, u8 *pframe, uint pkt_len, struct sta_info *psta)
1514 {
1515 unsigned int i;
1516 unsigned int len;
1517 struct ndis_80211_var_ie *pIE;
1518
1519 len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN);
1520
1521 for (i = 0; i < len;) {
1522 pIE = (struct ndis_80211_var_ie *)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i);
1523
1524 switch (pIE->ElementID) {
1525 case _VENDOR_SPECIFIC_IE_:
1526 /* to update WMM paramter set while receiving beacon */
1527 if (!memcmp(pIE->data, WMM_PARA_OUI, 6) && pIE->Length == WLAN_WMM_LEN) /* WMM */
1528 if (WMM_param_handler(padapter, pIE))
1529 report_wmm_edca_update(padapter);
1530
1531 break;
1532
1533 case _HT_EXTRA_INFO_IE_: /* HT info */
1534 /* HT_info_handler(padapter, pIE); */
1535 bwmode_update_check(padapter, pIE);
1536 break;
1537
1538 case _ERPINFO_IE_:
1539 ERP_IE_handler(padapter, pIE);
1540 VCS_update(padapter, psta);
1541 break;
1542
1543 default:
1544 break;
1545 }
1546
1547 i += (pIE->Length + 2);
1548 }
1549 }
1550
is_ap_in_tkip(struct adapter * padapter)1551 unsigned int is_ap_in_tkip(struct adapter *padapter)
1552 {
1553 u32 i;
1554 struct ndis_80211_var_ie *pIE;
1555 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1556 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1557 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
1558
1559 if (rtw_get_capability((struct wlan_bssid_ex *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
1560 for (i = sizeof(struct ndis_802_11_fix_ie); i < pmlmeinfo->network.IELength;) {
1561 pIE = (struct ndis_80211_var_ie *)(pmlmeinfo->network.IEs + i);
1562
1563 switch (pIE->ElementID) {
1564 case _VENDOR_SPECIFIC_IE_:
1565 if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) && (!memcmp((pIE->data + 12), WPA_TKIP_CIPHER, 4)))
1566 return true;
1567
1568 break;
1569
1570 case _RSN_IE_2_:
1571 if (!memcmp((pIE->data + 8), RSN_TKIP_CIPHER, 4))
1572 return true;
1573
1574 default:
1575 break;
1576 }
1577
1578 i += (pIE->Length + 2);
1579 }
1580
1581 return false;
1582 } else
1583 return false;
1584 }
1585
support_short_GI(struct adapter * padapter,struct HT_caps_element * pHT_caps,u8 bwmode)1586 int support_short_GI(struct adapter *padapter, struct HT_caps_element *pHT_caps, u8 bwmode)
1587 {
1588 unsigned char bit_offset;
1589 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1590 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1591
1592 if (!(pmlmeinfo->HT_enable))
1593 return _FAIL;
1594
1595 bit_offset = (bwmode & CHANNEL_WIDTH_40) ? 6 : 5;
1596
1597 if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info) & (0x1 << bit_offset))
1598 return _SUCCESS;
1599 else
1600 return _FAIL;
1601 }
1602
get_highest_rate_idx(u32 mask)1603 unsigned char get_highest_rate_idx(u32 mask)
1604 {
1605 int i;
1606 unsigned char rate_idx = 0;
1607
1608 for (i = 31; i >= 0; i--) {
1609 if (mask & BIT(i)) {
1610 rate_idx = i;
1611 break;
1612 }
1613 }
1614
1615 return rate_idx;
1616 }
1617
Update_RA_Entry(struct adapter * padapter,struct sta_info * psta)1618 void Update_RA_Entry(struct adapter *padapter, struct sta_info *psta)
1619 {
1620 rtw_hal_update_ra_mask(psta, 0);
1621 }
1622
1623 void enable_rate_adaptive(struct adapter *padapter, struct sta_info *psta);
enable_rate_adaptive(struct adapter * padapter,struct sta_info * psta)1624 void enable_rate_adaptive(struct adapter *padapter, struct sta_info *psta)
1625 {
1626 Update_RA_Entry(padapter, psta);
1627 }
1628
set_sta_rate(struct adapter * padapter,struct sta_info * psta)1629 void set_sta_rate(struct adapter *padapter, struct sta_info *psta)
1630 {
1631 /* rate adaptive */
1632 enable_rate_adaptive(padapter, psta);
1633 }
1634
check_assoc_AP(u8 * pframe,uint len)1635 unsigned char check_assoc_AP(u8 *pframe, uint len)
1636 {
1637 unsigned int i;
1638 struct ndis_80211_var_ie *pIE;
1639
1640 for (i = sizeof(struct ndis_802_11_fix_ie); i < len;) {
1641 pIE = (struct ndis_80211_var_ie *)(pframe + i);
1642
1643 switch (pIE->ElementID) {
1644 case _VENDOR_SPECIFIC_IE_:
1645 if ((!memcmp(pIE->data, ARTHEROS_OUI1, 3)) || (!memcmp(pIE->data, ARTHEROS_OUI2, 3))) {
1646 DBG_871X("link to Artheros AP\n");
1647 return HT_IOT_PEER_ATHEROS;
1648 } else if ((!memcmp(pIE->data, BROADCOM_OUI1, 3))
1649 || (!memcmp(pIE->data, BROADCOM_OUI2, 3))
1650 || (!memcmp(pIE->data, BROADCOM_OUI3, 3))) {
1651 DBG_871X("link to Broadcom AP\n");
1652 return HT_IOT_PEER_BROADCOM;
1653 } else if (!memcmp(pIE->data, MARVELL_OUI, 3)) {
1654 DBG_871X("link to Marvell AP\n");
1655 return HT_IOT_PEER_MARVELL;
1656 } else if (!memcmp(pIE->data, RALINK_OUI, 3)) {
1657 DBG_871X("link to Ralink AP\n");
1658 return HT_IOT_PEER_RALINK;
1659 } else if (!memcmp(pIE->data, CISCO_OUI, 3)) {
1660 DBG_871X("link to Cisco AP\n");
1661 return HT_IOT_PEER_CISCO;
1662 } else if (!memcmp(pIE->data, REALTEK_OUI, 3)) {
1663 u32 Vender = HT_IOT_PEER_REALTEK;
1664
1665 if (pIE->Length >= 5) {
1666 if (pIE->data[4] == 1)
1667 /* if (pIE->data[5] & RT_HT_CAP_USE_LONG_PREAMBLE) */
1668 /* bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_LONG_PREAMBLE; */
1669 if (pIE->data[5] & RT_HT_CAP_USE_92SE)
1670 /* bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE; */
1671 Vender = HT_IOT_PEER_REALTEK_92SE;
1672
1673 if (pIE->data[5] & RT_HT_CAP_USE_SOFTAP)
1674 Vender = HT_IOT_PEER_REALTEK_SOFTAP;
1675
1676 if (pIE->data[4] == 2) {
1677 if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_BCUT) {
1678 Vender = HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP;
1679 DBG_871X("link to Realtek JAGUAR_BCUTAP\n");
1680 }
1681 if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_CCUT) {
1682 Vender = HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP;
1683 DBG_871X("link to Realtek JAGUAR_CCUTAP\n");
1684 }
1685 }
1686 }
1687
1688 DBG_871X("link to Realtek AP\n");
1689 return Vender;
1690 } else if (!memcmp(pIE->data, AIRGOCAP_OUI, 3)) {
1691 DBG_871X("link to Airgo Cap\n");
1692 return HT_IOT_PEER_AIRGO;
1693 } else
1694 break;
1695
1696 default:
1697 break;
1698 }
1699
1700 i += (pIE->Length + 2);
1701 }
1702
1703 DBG_871X("link to new AP\n");
1704 return HT_IOT_PEER_UNKNOWN;
1705 }
1706
update_IOT_info(struct adapter * padapter)1707 void update_IOT_info(struct adapter *padapter)
1708 {
1709 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1710 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1711
1712 switch (pmlmeinfo->assoc_AP_vendor) {
1713 case HT_IOT_PEER_MARVELL:
1714 pmlmeinfo->turboMode_cts2self = 1;
1715 pmlmeinfo->turboMode_rtsen = 0;
1716 break;
1717
1718 case HT_IOT_PEER_RALINK:
1719 pmlmeinfo->turboMode_cts2self = 0;
1720 pmlmeinfo->turboMode_rtsen = 1;
1721 /* disable high power */
1722 Switch_DM_Func(padapter, (~DYNAMIC_BB_DYNAMIC_TXPWR), false);
1723 break;
1724 case HT_IOT_PEER_REALTEK:
1725 /* rtw_write16(padapter, 0x4cc, 0xffff); */
1726 /* rtw_write16(padapter, 0x546, 0x01c0); */
1727 /* disable high power */
1728 Switch_DM_Func(padapter, (~DYNAMIC_BB_DYNAMIC_TXPWR), false);
1729 break;
1730 default:
1731 pmlmeinfo->turboMode_cts2self = 0;
1732 pmlmeinfo->turboMode_rtsen = 1;
1733 break;
1734 }
1735 }
1736
update_capinfo(struct adapter * Adapter,u16 updateCap)1737 void update_capinfo(struct adapter *Adapter, u16 updateCap)
1738 {
1739 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
1740 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1741 bool ShortPreamble;
1742
1743 /* Check preamble mode, 2005.01.06, by rcnjko. */
1744 /* Mark to update preamble value forever, 2008.03.18 by lanhsin */
1745 /* if (pMgntInfo->RegPreambleMode == PREAMBLE_AUTO) */
1746 {
1747 if (updateCap & cShortPreamble) {
1748 /* Short Preamble */
1749 if (pmlmeinfo->preamble_mode != PREAMBLE_SHORT) { /* PREAMBLE_LONG or PREAMBLE_AUTO */
1750 ShortPreamble = true;
1751 pmlmeinfo->preamble_mode = PREAMBLE_SHORT;
1752 rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
1753 }
1754 } else{
1755 /* Long Preamble */
1756 if (pmlmeinfo->preamble_mode != PREAMBLE_LONG) { /* PREAMBLE_SHORT or PREAMBLE_AUTO */
1757 ShortPreamble = false;
1758 pmlmeinfo->preamble_mode = PREAMBLE_LONG;
1759 rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
1760 }
1761 }
1762 }
1763
1764 if (updateCap & cIBSS)
1765 /* Filen: See 802.11-2007 p.91 */
1766 pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1767 else {
1768 /* Filen: See 802.11-2007 p.90 */
1769 if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N | WIRELESS_11A | WIRELESS_11_5N | WIRELESS_11AC))
1770 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1771 else if (pmlmeext->cur_wireless_mode & (WIRELESS_11G)) {
1772 if ((updateCap & cShortSlotTime) /* && (!(pMgntInfo->pHTInfo->RT2RT_HT_Mode & RT_HT_CAP_USE_LONG_PREAMBLE)) */)
1773 /* Short Slot Time */
1774 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1775 else
1776 /* Long Slot Time */
1777 pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1778 } else
1779 /* B Mode */
1780 pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1781 }
1782
1783 rtw_hal_set_hwreg(Adapter, HW_VAR_SLOT_TIME, &pmlmeinfo->slotTime);
1784 }
1785
update_wireless_mode(struct adapter * padapter)1786 void update_wireless_mode(struct adapter *padapter)
1787 {
1788 int ratelen, network_type = 0;
1789 u32 SIFS_Timer;
1790 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1791 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1792 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
1793 unsigned char *rate = cur_network->SupportedRates;
1794
1795 ratelen = rtw_get_rateset_len(cur_network->SupportedRates);
1796
1797 if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
1798 pmlmeinfo->HT_enable = 1;
1799
1800 if (pmlmeext->cur_channel > 14) {
1801 if (pmlmeinfo->VHT_enable)
1802 network_type = WIRELESS_11AC;
1803 else if (pmlmeinfo->HT_enable)
1804 network_type = WIRELESS_11_5N;
1805
1806 network_type |= WIRELESS_11A;
1807 } else{
1808 if (pmlmeinfo->VHT_enable)
1809 network_type = WIRELESS_11AC;
1810 else if (pmlmeinfo->HT_enable)
1811 network_type = WIRELESS_11_24N;
1812
1813 if ((cckratesonly_included(rate, ratelen)) == true)
1814 network_type |= WIRELESS_11B;
1815 else if ((cckrates_included(rate, ratelen)) == true)
1816 network_type |= WIRELESS_11BG;
1817 else
1818 network_type |= WIRELESS_11G;
1819 }
1820
1821 pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode;
1822
1823 SIFS_Timer = 0x0a0a0808; /* 0x0808 -> for CCK, 0x0a0a -> for OFDM */
1824 /* change this value if having IOT issues. */
1825
1826 padapter->HalFunc.SetHwRegHandler(padapter, HW_VAR_RESP_SIFS, (u8 *)&SIFS_Timer);
1827
1828 padapter->HalFunc.SetHwRegHandler(padapter, HW_VAR_WIRELESS_MODE, (u8 *)&(pmlmeext->cur_wireless_mode));
1829
1830 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1831 update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
1832 else
1833 update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
1834 }
1835
update_sta_basic_rate(struct sta_info * psta,u8 wireless_mode)1836 void update_sta_basic_rate(struct sta_info *psta, u8 wireless_mode)
1837 {
1838 if (IsSupportedTxCCK(wireless_mode)) {
1839 /* Only B, B/G, and B/G/N AP could use CCK rate */
1840 memcpy(psta->bssrateset, rtw_basic_rate_cck, 4);
1841 psta->bssratelen = 4;
1842 } else{
1843 memcpy(psta->bssrateset, rtw_basic_rate_ofdm, 3);
1844 psta->bssratelen = 3;
1845 }
1846 }
1847
update_sta_support_rate(struct adapter * padapter,u8 * pvar_ie,uint var_ie_len,int cam_idx)1848 int update_sta_support_rate(struct adapter *padapter, u8 *pvar_ie, uint var_ie_len, int cam_idx)
1849 {
1850 unsigned int ie_len;
1851 struct ndis_80211_var_ie *pIE;
1852 int supportRateNum = 0;
1853 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1854 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1855
1856 pIE = (struct ndis_80211_var_ie *)rtw_get_ie(pvar_ie, _SUPPORTEDRATES_IE_, &ie_len, var_ie_len);
1857 if (!pIE)
1858 return _FAIL;
1859
1860 memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates, pIE->data, ie_len);
1861 supportRateNum = ie_len;
1862
1863 pIE = (struct ndis_80211_var_ie *)rtw_get_ie(pvar_ie, _EXT_SUPPORTEDRATES_IE_, &ie_len, var_ie_len);
1864 if (pIE)
1865 memcpy((pmlmeinfo->FW_sta_info[cam_idx].SupportedRates + supportRateNum), pIE->data, ie_len);
1866
1867 return _SUCCESS;
1868 }
1869
process_addba_req(struct adapter * padapter,u8 * paddba_req,u8 * addr)1870 void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr)
1871 {
1872 struct sta_info *psta;
1873 u16 tid, start_seq, param;
1874 struct recv_reorder_ctrl *preorder_ctrl;
1875 struct sta_priv *pstapriv = &padapter->stapriv;
1876 struct ADDBA_request *preq = (struct ADDBA_request *)paddba_req;
1877 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1878 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1879
1880 psta = rtw_get_stainfo(pstapriv, addr);
1881
1882 if (psta) {
1883 start_seq = le16_to_cpu(preq->BA_starting_seqctrl) >> 4;
1884
1885 param = le16_to_cpu(preq->BA_para_set);
1886 tid = (param>>2)&0x0f;
1887
1888 preorder_ctrl = &psta->recvreorder_ctrl[tid];
1889
1890 #ifdef CONFIG_UPDATE_INDICATE_SEQ_WHILE_PROCESS_ADDBA_REQ
1891 preorder_ctrl->indicate_seq = start_seq;
1892 #ifdef DBG_RX_SEQ
1893 DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, start_seq: %d\n", __func__, __LINE__,
1894 preorder_ctrl->indicate_seq, start_seq);
1895 #endif
1896 #else
1897 preorder_ctrl->indicate_seq = 0xffff;
1898 #endif
1899
1900 preorder_ctrl->enable = pmlmeinfo->accept_addba_req;
1901 }
1902 }
1903
update_TSF(struct mlme_ext_priv * pmlmeext,u8 * pframe,uint len)1904 void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
1905 {
1906 u8 *pIE;
1907 __le32 *pbuf;
1908
1909 pIE = pframe + sizeof(struct ieee80211_hdr_3addr);
1910 pbuf = (__le32 *)pIE;
1911
1912 pmlmeext->TSFValue = le32_to_cpu(*(pbuf+1));
1913
1914 pmlmeext->TSFValue = pmlmeext->TSFValue << 32;
1915
1916 pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
1917 }
1918
correct_TSF(struct adapter * padapter,struct mlme_ext_priv * pmlmeext)1919 void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext)
1920 {
1921 rtw_hal_set_hwreg(padapter, HW_VAR_CORRECT_TSF, NULL);
1922 }
1923
adaptive_early_32k(struct mlme_ext_priv * pmlmeext,u8 * pframe,uint len)1924 void adaptive_early_32k(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
1925 {
1926 int i;
1927 u8 *pIE;
1928 __le32 *pbuf;
1929 u64 tsf = 0;
1930 u32 delay_ms;
1931 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1932
1933 pmlmeext->bcn_cnt++;
1934
1935 pIE = pframe + sizeof(struct ieee80211_hdr_3addr);
1936 pbuf = (__le32 *)pIE;
1937
1938 tsf = le32_to_cpu(*(pbuf+1));
1939 tsf = tsf << 32;
1940 tsf |= le32_to_cpu(*pbuf);
1941
1942 /* DBG_871X("%s(): tsf_upper = 0x%08x, tsf_lower = 0x%08x\n", __func__, (u32)(tsf>>32), (u32)tsf); */
1943
1944 /* delay = (timestamp mod 1024*100)/1000 (unit: ms) */
1945 /* delay_ms = do_div(tsf, (pmlmeinfo->bcn_interval*1024))/1000; */
1946 delay_ms = rtw_modular64(tsf, (pmlmeinfo->bcn_interval*1024));
1947 delay_ms = delay_ms/1000;
1948
1949 if (delay_ms >= 8)
1950 pmlmeext->bcn_delay_cnt[8]++;
1951 /* pmlmeext->bcn_delay_ratio[8] = (pmlmeext->bcn_delay_cnt[8] * 100) /pmlmeext->bcn_cnt; */
1952 else
1953 pmlmeext->bcn_delay_cnt[delay_ms]++;
1954 /* pmlmeext->bcn_delay_ratio[delay_ms] = (pmlmeext->bcn_delay_cnt[delay_ms] * 100) /pmlmeext->bcn_cnt; */
1955
1956 /*
1957 DBG_871X("%s(): (a)bcn_cnt = %d\n", __func__, pmlmeext->bcn_cnt);
1958
1959
1960 for (i = 0; i<9; i++)
1961 {
1962 DBG_871X("%s():bcn_delay_cnt[%d]=%d, bcn_delay_ratio[%d]=%d\n", __func__, i,
1963 pmlmeext->bcn_delay_cnt[i] , i, pmlmeext->bcn_delay_ratio[i]);
1964 }
1965 */
1966
1967 /* dump for adaptive_early_32k */
1968 if (pmlmeext->bcn_cnt > 100 && (pmlmeext->adaptive_tsf_done == true)) {
1969 u8 ratio_20_delay, ratio_80_delay;
1970 u8 DrvBcnEarly, DrvBcnTimeOut;
1971
1972 ratio_20_delay = 0;
1973 ratio_80_delay = 0;
1974 DrvBcnEarly = 0xff;
1975 DrvBcnTimeOut = 0xff;
1976
1977 DBG_871X("%s(): bcn_cnt = %d\n", __func__, pmlmeext->bcn_cnt);
1978
1979 for (i = 0; i < 9; i++) {
1980 pmlmeext->bcn_delay_ratio[i] = (pmlmeext->bcn_delay_cnt[i] * 100) / pmlmeext->bcn_cnt;
1981
1982 DBG_871X("%s():bcn_delay_cnt[%d]=%d, bcn_delay_ratio[%d]=%d\n", __func__, i,
1983 pmlmeext->bcn_delay_cnt[i], i, pmlmeext->bcn_delay_ratio[i]);
1984
1985 ratio_20_delay += pmlmeext->bcn_delay_ratio[i];
1986 ratio_80_delay += pmlmeext->bcn_delay_ratio[i];
1987
1988 if (ratio_20_delay > 20 && DrvBcnEarly == 0xff) {
1989 DrvBcnEarly = i;
1990 DBG_871X("%s(): DrvBcnEarly = %d\n", __func__, DrvBcnEarly);
1991 }
1992
1993 if (ratio_80_delay > 80 && DrvBcnTimeOut == 0xff) {
1994 DrvBcnTimeOut = i;
1995 DBG_871X("%s(): DrvBcnTimeOut = %d\n", __func__, DrvBcnTimeOut);
1996 }
1997
1998 /* reset adaptive_early_32k cnt */
1999 pmlmeext->bcn_delay_cnt[i] = 0;
2000 pmlmeext->bcn_delay_ratio[i] = 0;
2001 }
2002
2003 pmlmeext->DrvBcnEarly = DrvBcnEarly;
2004 pmlmeext->DrvBcnTimeOut = DrvBcnTimeOut;
2005
2006 pmlmeext->bcn_cnt = 0;
2007 }
2008 }
2009
beacon_timing_control(struct adapter * padapter)2010 void beacon_timing_control(struct adapter *padapter)
2011 {
2012 rtw_hal_bcn_related_reg_setting(padapter);
2013 }
2014
rtw_alloc_macid(struct adapter * padapter,struct sta_info * psta)2015 void rtw_alloc_macid(struct adapter *padapter, struct sta_info *psta)
2016 {
2017 int i;
2018 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2019 struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
2020
2021 if (!memcmp(psta->hwaddr, bc_addr, ETH_ALEN))
2022 return;
2023
2024 if (!memcmp(psta->hwaddr, myid(&padapter->eeprompriv), ETH_ALEN)) {
2025 psta->mac_id = NUM_STA;
2026 return;
2027 }
2028
2029 spin_lock_bh(&pdvobj->lock);
2030 for (i = 0; i < NUM_STA; i++) {
2031 if (pdvobj->macid[i] == false) {
2032 pdvobj->macid[i] = true;
2033 break;
2034 }
2035 }
2036 spin_unlock_bh(&pdvobj->lock);
2037
2038 if (i > (NUM_STA-1)) {
2039 psta->mac_id = NUM_STA;
2040 DBG_871X(" no room for more MACIDs\n");
2041 } else{
2042 psta->mac_id = i;
2043 DBG_871X("%s = %d\n", __func__, psta->mac_id);
2044 }
2045 }
2046
rtw_release_macid(struct adapter * padapter,struct sta_info * psta)2047 void rtw_release_macid(struct adapter *padapter, struct sta_info *psta)
2048 {
2049 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2050 struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
2051
2052 if (!memcmp(psta->hwaddr, bc_addr, ETH_ALEN))
2053 return;
2054
2055 if (!memcmp(psta->hwaddr, myid(&padapter->eeprompriv), ETH_ALEN))
2056 return;
2057
2058 spin_lock_bh(&pdvobj->lock);
2059 if (psta->mac_id < NUM_STA && psta->mac_id != 1) {
2060 if (pdvobj->macid[psta->mac_id] == true) {
2061 DBG_871X("%s = %d\n", __func__, psta->mac_id);
2062 pdvobj->macid[psta->mac_id] = false;
2063 psta->mac_id = NUM_STA;
2064 }
2065 }
2066 spin_unlock_bh(&pdvobj->lock);
2067 }
2068 /* For 8188E RA */
rtw_search_max_mac_id(struct adapter * padapter)2069 u8 rtw_search_max_mac_id(struct adapter *padapter)
2070 {
2071 u8 max_mac_id = 0;
2072 struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
2073 int i;
2074 spin_lock_bh(&pdvobj->lock);
2075 for (i = (NUM_STA-1); i >= 0 ; i--) {
2076 if (pdvobj->macid[i] == true)
2077 break;
2078 }
2079 max_mac_id = i;
2080 spin_unlock_bh(&pdvobj->lock);
2081
2082 return max_mac_id;
2083 }
2084
dvobj_get_port0_adapter(struct dvobj_priv * dvobj)2085 struct adapter *dvobj_get_port0_adapter(struct dvobj_priv *dvobj)
2086 {
2087 if (get_iface_type(dvobj->padapters[i]) != IFACE_PORT0)
2088 return NULL;
2089
2090 return dvobj->padapters;
2091 }
2092
2093 #ifdef CONFIG_GPIO_API
rtw_get_gpio(struct net_device * netdev,int gpio_num)2094 int rtw_get_gpio(struct net_device *netdev, int gpio_num)
2095 {
2096 u8 value;
2097 u8 direction;
2098 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(netdev);
2099 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(adapter);
2100
2101 rtw_ps_deny(adapter, PS_DENY_IOCTL);
2102
2103 DBG_871X("rf_pwrstate = 0x%02x\n", pwrpriv->rf_pwrstate);
2104 LeaveAllPowerSaveModeDirect(adapter);
2105
2106 /* Read GPIO Direction */
2107 direction = (rtw_read8(adapter, REG_GPIO_PIN_CTRL + 2) & BIT(gpio_num)) >> gpio_num;
2108
2109 /* According the direction to read register value */
2110 if (direction)
2111 value = (rtw_read8(adapter, REG_GPIO_PIN_CTRL + 1) & BIT(gpio_num)) >> gpio_num;
2112 else
2113 value = (rtw_read8(adapter, REG_GPIO_PIN_CTRL) & BIT(gpio_num)) >> gpio_num;
2114
2115 rtw_ps_deny_cancel(adapter, PS_DENY_IOCTL);
2116 DBG_871X("%s direction =%d value =%d\n", __func__, direction, value);
2117
2118 return value;
2119 }
2120 EXPORT_SYMBOL(rtw_get_gpio);
2121
rtw_set_gpio_output_value(struct net_device * netdev,int gpio_num,bool isHigh)2122 int rtw_set_gpio_output_value(struct net_device *netdev, int gpio_num, bool isHigh)
2123 {
2124 u8 direction = 0;
2125 u8 res = -1;
2126 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(netdev);
2127
2128 /* Check GPIO is 4~7 */
2129 if (gpio_num > 7 || gpio_num < 4) {
2130 DBG_871X("%s The gpio number does not included 4~7.\n", __func__);
2131 return -1;
2132 }
2133
2134 rtw_ps_deny(adapter, PS_DENY_IOCTL);
2135
2136 LeaveAllPowerSaveModeDirect(adapter);
2137
2138 /* Read GPIO direction */
2139 direction = (rtw_read8(adapter, REG_GPIO_PIN_CTRL + 2) & BIT(gpio_num)) >> gpio_num;
2140
2141 /* If GPIO is output direction, setting value. */
2142 if (direction) {
2143 if (isHigh)
2144 rtw_write8(adapter, REG_GPIO_PIN_CTRL + 1, rtw_read8(adapter, REG_GPIO_PIN_CTRL + 1) | BIT(gpio_num));
2145 else
2146 rtw_write8(adapter, REG_GPIO_PIN_CTRL + 1, rtw_read8(adapter, REG_GPIO_PIN_CTRL + 1) & ~BIT(gpio_num));
2147
2148 DBG_871X("%s Set gpio %x[%d]=%d\n", __func__, REG_GPIO_PIN_CTRL+1, gpio_num, isHigh);
2149 res = 0;
2150 } else{
2151 DBG_871X("%s The gpio is input, not be set!\n", __func__);
2152 res = -1;
2153 }
2154
2155 rtw_ps_deny_cancel(adapter, PS_DENY_IOCTL);
2156 return res;
2157 }
2158 EXPORT_SYMBOL(rtw_set_gpio_output_value);
2159
rtw_config_gpio(struct net_device * netdev,int gpio_num,bool isOutput)2160 int rtw_config_gpio(struct net_device *netdev, int gpio_num, bool isOutput)
2161 {
2162 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(netdev);
2163
2164 if (gpio_num > 7 || gpio_num < 4) {
2165 DBG_871X("%s The gpio number does not included 4~7.\n", __func__);
2166 return -1;
2167 }
2168
2169 DBG_871X("%s gpio_num =%d direction =%d\n", __func__, gpio_num, isOutput);
2170
2171 rtw_ps_deny(adapter, PS_DENY_IOCTL);
2172
2173 LeaveAllPowerSaveModeDirect(adapter);
2174
2175 if (isOutput)
2176 rtw_write8(adapter, REG_GPIO_PIN_CTRL + 2, rtw_read8(adapter, REG_GPIO_PIN_CTRL + 2) | BIT(gpio_num));
2177 else
2178 rtw_write8(adapter, REG_GPIO_PIN_CTRL + 2, rtw_read8(adapter, REG_GPIO_PIN_CTRL + 2) & ~BIT(gpio_num));
2179
2180 rtw_ps_deny_cancel(adapter, PS_DENY_IOCTL);
2181
2182 return 0;
2183 }
2184 EXPORT_SYMBOL(rtw_config_gpio);
2185 #endif
2186
2187 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
rtw_get_current_ip_address(struct adapter * padapter,u8 * pcurrentip)2188 void rtw_get_current_ip_address(struct adapter *padapter, u8 *pcurrentip)
2189 {
2190 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2191 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2192 struct in_device *my_ip_ptr = padapter->pnetdev->ip_ptr;
2193 u8 ipaddress[4];
2194
2195 if ((pmlmeinfo->state & WIFI_FW_LINKING_STATE) ||
2196 pmlmeinfo->state & WIFI_FW_AP_STATE) {
2197 if (my_ip_ptr) {
2198 struct in_ifaddr *my_ifa_list = my_ip_ptr->ifa_list;
2199 if (my_ifa_list) {
2200 ipaddress[0] = my_ifa_list->ifa_address & 0xFF;
2201 ipaddress[1] = (my_ifa_list->ifa_address >> 8) & 0xFF;
2202 ipaddress[2] = (my_ifa_list->ifa_address >> 16) & 0xFF;
2203 ipaddress[3] = my_ifa_list->ifa_address >> 24;
2204 DBG_871X("%s: %d.%d.%d.%d ==========\n", __func__,
2205 ipaddress[0], ipaddress[1], ipaddress[2], ipaddress[3]);
2206 memcpy(pcurrentip, ipaddress, 4);
2207 }
2208 }
2209 }
2210 }
2211 #endif
2212 #ifdef CONFIG_WOWLAN
rtw_get_sec_iv(struct adapter * padapter,u8 * pcur_dot11txpn,u8 * StaAddr)2213 void rtw_get_sec_iv(struct adapter *padapter, u8 *pcur_dot11txpn, u8 *StaAddr)
2214 {
2215 struct sta_info *psta;
2216 struct security_priv *psecpriv = &padapter->securitypriv;
2217
2218 memset(pcur_dot11txpn, 0, 8);
2219 if (NULL == StaAddr)
2220 return;
2221 psta = rtw_get_stainfo(&padapter->stapriv, StaAddr);
2222 DBG_871X("%s(): StaAddr: %02x %02x %02x %02x %02x %02x\n",
2223 __func__, StaAddr[0], StaAddr[1], StaAddr[2],
2224 StaAddr[3], StaAddr[4], StaAddr[5]);
2225
2226 if (psta) {
2227 if (psecpriv->dot11PrivacyAlgrthm != _NO_PRIVACY_ && psta->dot11txpn.val > 0)
2228 psta->dot11txpn.val--;
2229 AES_IV(pcur_dot11txpn, psta->dot11txpn, 0);
2230
2231 DBG_871X("%s(): CurrentIV: %02x %02x %02x %02x %02x %02x %02x %02x\n"
2232 , __func__, pcur_dot11txpn[0], pcur_dot11txpn[1],
2233 pcur_dot11txpn[2], pcur_dot11txpn[3], pcur_dot11txpn[4],
2234 pcur_dot11txpn[5], pcur_dot11txpn[6], pcur_dot11txpn[7]);
2235 }
2236 }
rtw_set_sec_pn(struct adapter * padapter)2237 void rtw_set_sec_pn(struct adapter *padapter)
2238 {
2239 struct sta_info *psta;
2240 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2241 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2242 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
2243 struct security_priv *psecpriv = &padapter->securitypriv;
2244
2245 psta = rtw_get_stainfo(&padapter->stapriv,
2246 get_my_bssid(&pmlmeinfo->network));
2247
2248 if (psta) {
2249 if (pwrpriv->wowlan_fw_iv > psta->dot11txpn.val) {
2250 if (psecpriv->dot11PrivacyAlgrthm != _NO_PRIVACY_)
2251 psta->dot11txpn.val = pwrpriv->wowlan_fw_iv + 2;
2252 } else {
2253 DBG_871X("%s(): FW IV is smaller than driver\n", __func__);
2254 psta->dot11txpn.val += 2;
2255 }
2256 DBG_871X("%s: dot11txpn: 0x%016llx\n", __func__, psta->dot11txpn.val);
2257 }
2258 }
2259 #endif /* CONFIG_WOWLAN */
2260
2261 #ifdef CONFIG_PNO_SUPPORT
2262 #define CSCAN_TLV_TYPE_SSID_IE 'S'
2263 #define CIPHER_IE "key_mgmt ="
2264 #define CIPHER_NONE "NONE"
2265 #define CIPHER_WPA_PSK "WPA-PSK"
2266 #define CIPHER_WPA_EAP "WPA-EAP IEEE8021X"
2267
2268 #endif /* CONFIG_PNO_SUPPORT */
2269