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