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