1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2009-2012 Realtek Corporation.
8 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
13 *****************************************************************************/
24 #include <linux/module.h>
25 #include <linux/udp.h>
28 *NOTICE!!!: This file will be very big, we should
29 *keep it clear under following roles:
31 *This file include following parts, so, if you add new
32 *functions into this file, please check which part it
33 *should includes. or check if you should add new part
36 *1) mac80211 init functions
37 *2) tx information functions
38 *3) functions called by core.c
39 *4) wq & timer callback functions
40 *5) frame process functions
47 /*********************************************************
49 * mac80211 init functions
51 *********************************************************/
52 static struct ieee80211_channel rtl_channeltable_2g[] = {
53 {.center_freq = 2412, .hw_value = 1,},
54 {.center_freq = 2417, .hw_value = 2,},
55 {.center_freq = 2422, .hw_value = 3,},
56 {.center_freq = 2427, .hw_value = 4,},
57 {.center_freq = 2432, .hw_value = 5,},
58 {.center_freq = 2437, .hw_value = 6,},
59 {.center_freq = 2442, .hw_value = 7,},
60 {.center_freq = 2447, .hw_value = 8,},
61 {.center_freq = 2452, .hw_value = 9,},
62 {.center_freq = 2457, .hw_value = 10,},
63 {.center_freq = 2462, .hw_value = 11,},
64 {.center_freq = 2467, .hw_value = 12,},
65 {.center_freq = 2472, .hw_value = 13,},
66 {.center_freq = 2484, .hw_value = 14,},
69 static struct ieee80211_channel rtl_channeltable_5g[] = {
70 {.center_freq = 5180, .hw_value = 36,},
71 {.center_freq = 5200, .hw_value = 40,},
72 {.center_freq = 5220, .hw_value = 44,},
73 {.center_freq = 5240, .hw_value = 48,},
74 {.center_freq = 5260, .hw_value = 52,},
75 {.center_freq = 5280, .hw_value = 56,},
76 {.center_freq = 5300, .hw_value = 60,},
77 {.center_freq = 5320, .hw_value = 64,},
78 {.center_freq = 5500, .hw_value = 100,},
79 {.center_freq = 5520, .hw_value = 104,},
80 {.center_freq = 5540, .hw_value = 108,},
81 {.center_freq = 5560, .hw_value = 112,},
82 {.center_freq = 5580, .hw_value = 116,},
83 {.center_freq = 5600, .hw_value = 120,},
84 {.center_freq = 5620, .hw_value = 124,},
85 {.center_freq = 5640, .hw_value = 128,},
86 {.center_freq = 5660, .hw_value = 132,},
87 {.center_freq = 5680, .hw_value = 136,},
88 {.center_freq = 5700, .hw_value = 140,},
89 {.center_freq = 5745, .hw_value = 149,},
90 {.center_freq = 5765, .hw_value = 153,},
91 {.center_freq = 5785, .hw_value = 157,},
92 {.center_freq = 5805, .hw_value = 161,},
93 {.center_freq = 5825, .hw_value = 165,},
96 static struct ieee80211_rate rtl_ratetable_2g[] = {
97 {.bitrate = 10, .hw_value = 0x00,},
98 {.bitrate = 20, .hw_value = 0x01,},
99 {.bitrate = 55, .hw_value = 0x02,},
100 {.bitrate = 110, .hw_value = 0x03,},
101 {.bitrate = 60, .hw_value = 0x04,},
102 {.bitrate = 90, .hw_value = 0x05,},
103 {.bitrate = 120, .hw_value = 0x06,},
104 {.bitrate = 180, .hw_value = 0x07,},
105 {.bitrate = 240, .hw_value = 0x08,},
106 {.bitrate = 360, .hw_value = 0x09,},
107 {.bitrate = 480, .hw_value = 0x0a,},
108 {.bitrate = 540, .hw_value = 0x0b,},
111 static struct ieee80211_rate rtl_ratetable_5g[] = {
112 {.bitrate = 60, .hw_value = 0x04,},
113 {.bitrate = 90, .hw_value = 0x05,},
114 {.bitrate = 120, .hw_value = 0x06,},
115 {.bitrate = 180, .hw_value = 0x07,},
116 {.bitrate = 240, .hw_value = 0x08,},
117 {.bitrate = 360, .hw_value = 0x09,},
118 {.bitrate = 480, .hw_value = 0x0a,},
119 {.bitrate = 540, .hw_value = 0x0b,},
122 static const struct ieee80211_supported_band rtl_band_2ghz = {
123 .band = NL80211_BAND_2GHZ,
125 .channels = rtl_channeltable_2g,
126 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
128 .bitrates = rtl_ratetable_2g,
129 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
134 static struct ieee80211_supported_band rtl_band_5ghz = {
135 .band = NL80211_BAND_5GHZ,
137 .channels = rtl_channeltable_5g,
138 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
140 .bitrates = rtl_ratetable_5g,
141 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
146 static const u8 tid_to_ac[] = {
147 2, /* IEEE80211_AC_BE */
148 3, /* IEEE80211_AC_BK */
149 3, /* IEEE80211_AC_BK */
150 2, /* IEEE80211_AC_BE */
151 1, /* IEEE80211_AC_VI */
152 1, /* IEEE80211_AC_VI */
153 0, /* IEEE80211_AC_VO */
154 0, /* IEEE80211_AC_VO */
157 u8 rtl_tid_to_ac(u8 tid)
159 return tid_to_ac[tid];
162 static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
163 struct ieee80211_sta_ht_cap *ht_cap)
165 struct rtl_priv *rtlpriv = rtl_priv(hw);
166 struct rtl_phy *rtlphy = &rtlpriv->phy;
168 ht_cap->ht_supported = true;
169 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
170 IEEE80211_HT_CAP_SGI_40 |
171 IEEE80211_HT_CAP_SGI_20 |
172 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
174 if (rtlpriv->rtlhal.disable_amsdu_8k)
175 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
178 *Maximum length of AMPDU that the STA can receive.
179 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
181 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
183 /*Minimum MPDU start spacing , */
184 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
186 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
188 /*hw->wiphy->bands[NL80211_BAND_2GHZ]
191 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
192 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
193 *if rx_ant >= 3 rx_mask[2]= 0xff;
194 *if BW_40 rx_mask[4]= 0x01;
195 *highest supported RX rate
197 if (rtlpriv->dm.supp_phymode_switch) {
198 pr_info("Support phy mode switch\n");
200 ht_cap->mcs.rx_mask[0] = 0xFF;
201 ht_cap->mcs.rx_mask[1] = 0xFF;
202 ht_cap->mcs.rx_mask[4] = 0x01;
204 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
206 if (get_rf_type(rtlphy) == RF_1T2R ||
207 get_rf_type(rtlphy) == RF_2T2R) {
208 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
210 ht_cap->mcs.rx_mask[0] = 0xFF;
211 ht_cap->mcs.rx_mask[1] = 0xFF;
212 ht_cap->mcs.rx_mask[4] = 0x01;
214 ht_cap->mcs.rx_highest =
215 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
216 } else if (get_rf_type(rtlphy) == RF_1T1R) {
217 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
219 ht_cap->mcs.rx_mask[0] = 0xFF;
220 ht_cap->mcs.rx_mask[1] = 0x00;
221 ht_cap->mcs.rx_mask[4] = 0x01;
223 ht_cap->mcs.rx_highest =
224 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
229 static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
230 struct ieee80211_sta_vht_cap *vht_cap)
232 struct rtl_priv *rtlpriv = rtl_priv(hw);
233 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
235 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE ||
236 rtlhal->hw_type == HARDWARE_TYPE_RTL8822BE) {
239 vht_cap->vht_supported = true;
241 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
242 IEEE80211_VHT_CAP_SHORT_GI_80 |
243 IEEE80211_VHT_CAP_TXSTBC |
244 IEEE80211_VHT_CAP_RXSTBC_1 |
245 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
246 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
247 IEEE80211_VHT_CAP_HTC_VHT |
248 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
249 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
250 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
253 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
254 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
255 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
256 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
257 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
258 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
259 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
260 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
262 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
263 vht_cap->vht_mcs.rx_highest =
264 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
265 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
266 vht_cap->vht_mcs.tx_highest =
267 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
268 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
271 vht_cap->vht_supported = true;
273 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
274 IEEE80211_VHT_CAP_SHORT_GI_80 |
275 IEEE80211_VHT_CAP_TXSTBC |
276 IEEE80211_VHT_CAP_RXSTBC_1 |
277 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
278 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
279 IEEE80211_VHT_CAP_HTC_VHT |
280 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
281 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
282 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
285 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
286 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
287 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
288 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
289 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
290 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
291 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
292 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
294 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
295 vht_cap->vht_mcs.rx_highest =
296 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
297 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
298 vht_cap->vht_mcs.tx_highest =
299 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
303 static void _rtl_init_mac80211(struct ieee80211_hw *hw)
305 struct rtl_priv *rtlpriv = rtl_priv(hw);
306 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
307 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
308 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
309 struct ieee80211_supported_band *sband;
311 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
312 rtlhal->bandset == BAND_ON_BOTH) {
314 /* <1> use mac->bands as mem for hw->wiphy->bands */
315 sband = &rtlmac->bands[NL80211_BAND_2GHZ];
317 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
318 * to default value(1T1R)
320 memcpy(&rtlmac->bands[NL80211_BAND_2GHZ], &rtl_band_2ghz,
321 sizeof(struct ieee80211_supported_band));
323 /* <3> init ht cap base on ant_num */
324 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
326 /* <4> set mac->sband to wiphy->sband */
327 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
330 /* <1> use mac->bands as mem for hw->wiphy->bands */
331 sband = &rtlmac->bands[NL80211_BAND_5GHZ];
333 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
334 * to default value(1T1R)
336 memcpy(&rtlmac->bands[NL80211_BAND_5GHZ], &rtl_band_5ghz,
337 sizeof(struct ieee80211_supported_band));
339 /* <3> init ht cap base on ant_num */
340 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
342 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
343 /* <4> set mac->sband to wiphy->sband */
344 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
346 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
347 /* <1> use mac->bands as mem for hw->wiphy->bands */
348 sband = &rtlmac->bands[NL80211_BAND_2GHZ];
350 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
351 * to default value(1T1R)
353 memcpy(&rtlmac->bands[NL80211_BAND_2GHZ],
355 sizeof(struct ieee80211_supported_band));
357 /* <3> init ht cap base on ant_num */
358 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
360 /* <4> set mac->sband to wiphy->sband */
361 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
362 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
363 /* <1> use mac->bands as mem for hw->wiphy->bands */
364 sband = &rtlmac->bands[NL80211_BAND_5GHZ];
366 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
367 * to default value(1T1R)
369 memcpy(&rtlmac->bands[NL80211_BAND_5GHZ],
371 sizeof(struct ieee80211_supported_band));
373 /* <3> init ht cap base on ant_num */
374 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
376 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
377 /* <4> set mac->sband to wiphy->sband */
378 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
380 pr_err("Err BAND %d\n",
381 rtlhal->current_bandtype);
384 /* <5> set hw caps */
385 ieee80211_hw_set(hw, SIGNAL_DBM);
386 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
387 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
388 ieee80211_hw_set(hw, CONNECTION_MONITOR);
389 ieee80211_hw_set(hw, MFP_CAPABLE);
390 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
391 ieee80211_hw_set(hw, SUPPORTS_TX_FRAG);
392 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
393 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
395 /* swlps or hwlps has been set in diff chip in init_sw_vars */
396 if (rtlpriv->psc.swctrl_lps) {
397 ieee80211_hw_set(hw, SUPPORTS_PS);
398 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
400 if (rtlpriv->psc.fwctrl_lps) {
401 ieee80211_hw_set(hw, SUPPORTS_PS);
402 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
404 hw->wiphy->interface_modes =
405 BIT(NL80211_IFTYPE_AP) |
406 BIT(NL80211_IFTYPE_STATION) |
407 BIT(NL80211_IFTYPE_ADHOC) |
408 BIT(NL80211_IFTYPE_MESH_POINT) |
409 BIT(NL80211_IFTYPE_P2P_CLIENT) |
410 BIT(NL80211_IFTYPE_P2P_GO);
411 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
413 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
415 hw->wiphy->rts_threshold = 2347;
418 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
420 /* TODO: Correct this value for our hw */
421 hw->max_listen_interval = MAX_LISTEN_INTERVAL;
422 hw->max_rate_tries = MAX_RATE_TRIES;
423 /* hw->max_rates = 1; */
424 hw->sta_data_size = sizeof(struct rtl_sta_info);
426 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
428 if (rtlpriv->psc.wo_wlan_mode) {
429 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
430 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
431 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
432 rtlpriv->wowlan.n_patterns =
433 MAX_SUPPORT_WOL_PATTERN_NUM;
434 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
435 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
437 hw->wiphy->wowlan = &rtlpriv->wowlan;
441 /* <6> mac address */
442 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
443 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
445 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
447 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
448 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
452 static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
454 struct rtl_priv *rtlpriv = rtl_priv(hw);
457 timer_setup(&rtlpriv->works.watchdog_timer,
458 rtl_watch_dog_timer_callback, 0);
459 timer_setup(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
460 rtl_easy_concurrent_retrytimer_callback, 0);
462 rtlpriv->works.hw = hw;
463 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
464 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
465 (void *)rtl_watchdog_wq_callback);
466 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
467 (void *)rtl_ips_nic_off_wq_callback);
468 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
469 (void *)rtl_swlps_wq_callback);
470 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
471 (void *)rtl_swlps_rfon_wq_callback);
472 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
473 (void *)rtl_fwevt_wq_callback);
474 INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq,
475 (void *)rtl_c2hcmd_wq_callback);
478 void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
480 struct rtl_priv *rtlpriv = rtl_priv(hw);
482 del_timer_sync(&rtlpriv->works.watchdog_timer);
484 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
485 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
486 cancel_delayed_work(&rtlpriv->works.ps_work);
487 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
488 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
489 cancel_delayed_work(&rtlpriv->works.c2hcmd_wq);
492 void rtl_init_rfkill(struct ieee80211_hw *hw)
494 struct rtl_priv *rtlpriv = rtl_priv(hw);
500 /*set init state to on */
501 rtlpriv->rfkill.rfkill_state = true;
502 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
504 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
507 pr_info("rtlwifi: wireless switch is %s\n",
508 rtlpriv->rfkill.rfkill_state ? "on" : "off");
510 rtlpriv->rfkill.rfkill_state = radio_state;
512 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
513 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
516 wiphy_rfkill_start_polling(hw->wiphy);
519 void rtl_deinit_rfkill(struct ieee80211_hw *hw)
521 wiphy_rfkill_stop_polling(hw->wiphy);
524 int rtl_init_core(struct ieee80211_hw *hw)
526 struct rtl_priv *rtlpriv = rtl_priv(hw);
527 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
529 /* <1> init mac80211 */
530 _rtl_init_mac80211(hw);
533 /* <2> rate control register */
534 hw->rate_control_algorithm = "rtl_rc";
537 * <3> init CRDA must come after init
538 * mac80211 hw in _rtl_init_mac80211.
540 if (rtl_regd_init(hw, rtl_reg_notifier)) {
541 pr_err("REGD init failed\n");
546 mutex_init(&rtlpriv->locks.conf_mutex);
547 mutex_init(&rtlpriv->locks.ips_mutex);
548 mutex_init(&rtlpriv->locks.lps_mutex);
549 spin_lock_init(&rtlpriv->locks.irq_th_lock);
550 spin_lock_init(&rtlpriv->locks.h2c_lock);
551 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
552 spin_lock_init(&rtlpriv->locks.rf_lock);
553 spin_lock_init(&rtlpriv->locks.waitq_lock);
554 spin_lock_init(&rtlpriv->locks.entry_list_lock);
555 spin_lock_init(&rtlpriv->locks.c2hcmd_lock);
556 spin_lock_init(&rtlpriv->locks.scan_list_lock);
557 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
558 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
559 spin_lock_init(&rtlpriv->locks.iqk_lock);
561 INIT_LIST_HEAD(&rtlpriv->entry_list);
562 INIT_LIST_HEAD(&rtlpriv->c2hcmd_list);
563 INIT_LIST_HEAD(&rtlpriv->scan_list.list);
565 rtlmac->link_state = MAC80211_NOLINK;
567 /* <6> init deferred work */
568 _rtl_init_deferred_work(hw);
573 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
575 void rtl_deinit_core(struct ieee80211_hw *hw)
577 rtl_c2hcmd_launcher(hw, 0);
578 rtl_free_entries_from_scan_list(hw);
581 void rtl_init_rx_config(struct ieee80211_hw *hw)
583 struct rtl_priv *rtlpriv = rtl_priv(hw);
584 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
586 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)&mac->rx_conf);
589 /*********************************************************
591 * tx information functions
593 *********************************************************/
594 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
595 struct rtl_tcb_desc *tcb_desc,
596 struct ieee80211_tx_info *info)
598 struct rtl_priv *rtlpriv = rtl_priv(hw);
599 u8 rate_flag = info->control.rates[0].flags;
601 tcb_desc->use_shortpreamble = false;
603 /* 1M can only use Long Preamble. 11B spec */
604 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
606 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
607 tcb_desc->use_shortpreamble = true;
610 static void _rtl_query_shortgi(struct ieee80211_hw *hw,
611 struct ieee80211_sta *sta,
612 struct rtl_tcb_desc *tcb_desc,
613 struct ieee80211_tx_info *info)
615 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
616 u8 rate_flag = info->control.rates[0].flags;
617 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
618 u8 sgi_80 = 0, bw_80 = 0;
620 tcb_desc->use_shortgi = false;
625 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
626 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
627 sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
629 if (!sta->ht_cap.ht_supported && !sta->vht_cap.vht_supported)
632 if (!sgi_40 && !sgi_20)
635 if (mac->opmode == NL80211_IFTYPE_STATION) {
638 } else if (mac->opmode == NL80211_IFTYPE_AP ||
639 mac->opmode == NL80211_IFTYPE_ADHOC ||
640 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
641 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
642 bw_80 = sta->vht_cap.vht_supported;
647 tcb_desc->use_shortgi = true;
649 tcb_desc->use_shortgi = false;
652 tcb_desc->use_shortgi = true;
653 else if (!bw_40 && sgi_20)
654 tcb_desc->use_shortgi = true;
657 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
658 tcb_desc->use_shortgi = false;
661 static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
662 struct rtl_tcb_desc *tcb_desc,
663 struct ieee80211_tx_info *info)
665 struct rtl_priv *rtlpriv = rtl_priv(hw);
666 u8 rate_flag = info->control.rates[0].flags;
668 /* Common Settings */
669 tcb_desc->rts_stbc = false;
670 tcb_desc->cts_enable = false;
671 tcb_desc->rts_sc = 0;
672 tcb_desc->rts_bw = false;
673 tcb_desc->rts_use_shortpreamble = false;
674 tcb_desc->rts_use_shortgi = false;
676 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
677 /* Use CTS-to-SELF in protection mode. */
678 tcb_desc->rts_enable = true;
679 tcb_desc->cts_enable = true;
680 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
681 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
682 /* Use RTS-CTS in protection mode. */
683 tcb_desc->rts_enable = true;
684 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
688 u8 rtl_mrate_idx_to_arfr_id(struct ieee80211_hw *hw, u8 rate_index,
689 enum wireless_mode wirelessmode)
691 struct rtl_priv *rtlpriv = rtl_priv(hw);
692 struct rtl_phy *rtlphy = &rtlpriv->phy;
695 switch (rate_index) {
696 case RATR_INX_WIRELESS_NGB:
697 if (rtlphy->rf_type == RF_1T1R)
698 ret = RATEID_IDX_BGN_40M_1SS;
700 ret = RATEID_IDX_BGN_40M_2SS;
702 case RATR_INX_WIRELESS_N:
703 case RATR_INX_WIRELESS_NG:
704 if (rtlphy->rf_type == RF_1T1R)
705 ret = RATEID_IDX_GN_N1SS;
707 ret = RATEID_IDX_GN_N2SS;
709 case RATR_INX_WIRELESS_NB:
710 if (rtlphy->rf_type == RF_1T1R)
711 ret = RATEID_IDX_BGN_20M_1SS_BN;
713 ret = RATEID_IDX_BGN_20M_2SS_BN;
715 case RATR_INX_WIRELESS_GB:
718 case RATR_INX_WIRELESS_G:
721 case RATR_INX_WIRELESS_B:
724 case RATR_INX_WIRELESS_MC:
725 if (wirelessmode == WIRELESS_MODE_B ||
726 wirelessmode == WIRELESS_MODE_G ||
727 wirelessmode == WIRELESS_MODE_N_24G ||
728 wirelessmode == WIRELESS_MODE_AC_24G)
733 case RATR_INX_WIRELESS_AC_5N:
734 if (rtlphy->rf_type == RF_1T1R)
735 ret = RATEID_IDX_VHT_1SS;
737 ret = RATEID_IDX_VHT_2SS;
739 case RATR_INX_WIRELESS_AC_24N:
740 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
741 if (rtlphy->rf_type == RF_1T1R)
742 ret = RATEID_IDX_VHT_1SS;
744 ret = RATEID_IDX_VHT_2SS;
746 if (rtlphy->rf_type == RF_1T1R)
747 ret = RATEID_IDX_MIX1;
749 ret = RATEID_IDX_MIX2;
753 ret = RATEID_IDX_BGN_40M_2SS;
759 static inline u8 _rtl_rate_id(struct ieee80211_hw *hw,
760 struct rtl_sta_info *sta_entry,
763 struct rtl_priv *rtlpriv = rtl_priv(hw);
765 if (rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) {
766 int wireless_mode = sta_entry ?
767 sta_entry->wireless_mode : WIRELESS_MODE_G;
769 return rtl_mrate_idx_to_arfr_id(hw, rate_index, wireless_mode);
775 static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
776 struct ieee80211_sta *sta,
777 struct rtl_tcb_desc *tcb_desc)
779 struct rtl_priv *rtlpriv = rtl_priv(hw);
780 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
781 struct rtl_sta_info *sta_entry = NULL;
782 u8 ratr_index = _rtl_rate_id(hw, sta_entry, RATR_INX_WIRELESS_MC);
785 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
786 ratr_index = sta_entry->ratr_index;
788 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
789 if (mac->opmode == NL80211_IFTYPE_STATION) {
790 tcb_desc->ratr_index = 0;
791 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
792 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
793 if (tcb_desc->multicast || tcb_desc->broadcast) {
795 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
796 tcb_desc->use_driver_rate = 1;
797 tcb_desc->ratr_index =
798 _rtl_rate_id(hw, sta_entry,
799 RATR_INX_WIRELESS_MC);
801 tcb_desc->ratr_index = ratr_index;
803 } else if (mac->opmode == NL80211_IFTYPE_AP) {
804 tcb_desc->ratr_index = ratr_index;
808 if (rtlpriv->dm.useramask) {
809 tcb_desc->ratr_index = ratr_index;
810 /* TODO we will differentiate adhoc and station future */
811 if (mac->opmode == NL80211_IFTYPE_STATION ||
812 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
813 tcb_desc->mac_id = 0;
816 (rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID))
817 ; /* use sta_entry->ratr_index */
818 else if (mac->mode == WIRELESS_MODE_AC_5G)
819 tcb_desc->ratr_index =
820 _rtl_rate_id(hw, sta_entry,
821 RATR_INX_WIRELESS_AC_5N);
822 else if (mac->mode == WIRELESS_MODE_AC_24G)
823 tcb_desc->ratr_index =
824 _rtl_rate_id(hw, sta_entry,
825 RATR_INX_WIRELESS_AC_24N);
826 else if (mac->mode == WIRELESS_MODE_N_24G)
827 tcb_desc->ratr_index =
828 _rtl_rate_id(hw, sta_entry,
829 RATR_INX_WIRELESS_NGB);
830 else if (mac->mode == WIRELESS_MODE_N_5G)
831 tcb_desc->ratr_index =
832 _rtl_rate_id(hw, sta_entry,
833 RATR_INX_WIRELESS_NG);
834 else if (mac->mode & WIRELESS_MODE_G)
835 tcb_desc->ratr_index =
836 _rtl_rate_id(hw, sta_entry,
837 RATR_INX_WIRELESS_GB);
838 else if (mac->mode & WIRELESS_MODE_B)
839 tcb_desc->ratr_index =
840 _rtl_rate_id(hw, sta_entry,
841 RATR_INX_WIRELESS_B);
842 else if (mac->mode & WIRELESS_MODE_A)
843 tcb_desc->ratr_index =
844 _rtl_rate_id(hw, sta_entry,
845 RATR_INX_WIRELESS_G);
847 } else if (mac->opmode == NL80211_IFTYPE_AP ||
848 mac->opmode == NL80211_IFTYPE_ADHOC) {
851 tcb_desc->mac_id = sta->aid + 1;
853 tcb_desc->mac_id = 1;
855 tcb_desc->mac_id = 0;
861 static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
862 struct ieee80211_sta *sta,
863 struct rtl_tcb_desc *tcb_desc)
865 struct rtl_priv *rtlpriv = rtl_priv(hw);
866 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
868 tcb_desc->packet_bw = false;
871 if (mac->opmode == NL80211_IFTYPE_AP ||
872 mac->opmode == NL80211_IFTYPE_ADHOC ||
873 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
874 if (!(sta->ht_cap.ht_supported) ||
875 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
877 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
878 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
881 if (tcb_desc->multicast || tcb_desc->broadcast)
884 /*use legency rate, shall use 20MHz */
885 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
888 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
890 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
891 rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE ||
892 (rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT)) {
893 if (mac->opmode == NL80211_IFTYPE_AP ||
894 mac->opmode == NL80211_IFTYPE_ADHOC ||
895 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
896 if (!(sta->vht_cap.vht_supported))
898 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
900 !(sta->vht_cap.vht_supported))
903 if (tcb_desc->hw_rate <=
904 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
906 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
910 static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
911 struct ieee80211_sta *sta)
913 struct rtl_priv *rtlpriv = rtl_priv(hw);
914 struct rtl_phy *rtlphy = &rtlpriv->phy;
916 u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
918 if ((get_rf_type(rtlphy) == RF_2T2R) &&
919 (tx_mcs_map & 0x000c) != 0x000c) {
920 if ((tx_mcs_map & 0x000c) >> 2 ==
921 IEEE80211_VHT_MCS_SUPPORT_0_7)
923 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
924 else if ((tx_mcs_map & 0x000c) >> 2 ==
925 IEEE80211_VHT_MCS_SUPPORT_0_8)
927 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS8];
930 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
932 if ((tx_mcs_map & 0x0003) ==
933 IEEE80211_VHT_MCS_SUPPORT_0_7)
935 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
936 else if ((tx_mcs_map & 0x0003) ==
937 IEEE80211_VHT_MCS_SUPPORT_0_8)
939 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS8];
942 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
948 static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
949 struct ieee80211_sta *sta)
951 struct rtl_priv *rtlpriv = rtl_priv(hw);
952 struct rtl_phy *rtlphy = &rtlpriv->phy;
955 if (get_rf_type(rtlphy) == RF_2T2R &&
956 sta->ht_cap.mcs.rx_mask[1] != 0)
957 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
959 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
964 /* mac80211's rate_idx is like this:
966 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
969 * (rx_status->flag & RX_FLAG_HT) = 0,
970 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
973 * (rx_status->flag & RX_FLAG_HT) = 1,
974 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
976 * 5G band:rx_status->band == NL80211_BAND_5GHZ
978 * (rx_status->flag & RX_FLAG_HT) = 0,
979 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
982 * (rx_status->flag & RX_FLAG_HT) = 1,
983 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
986 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
987 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
989 int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
996 case DESC_RATEVHT1SS_MCS0:
999 case DESC_RATEVHT1SS_MCS1:
1002 case DESC_RATEVHT1SS_MCS2:
1005 case DESC_RATEVHT1SS_MCS3:
1008 case DESC_RATEVHT1SS_MCS4:
1011 case DESC_RATEVHT1SS_MCS5:
1014 case DESC_RATEVHT1SS_MCS6:
1017 case DESC_RATEVHT1SS_MCS7:
1020 case DESC_RATEVHT1SS_MCS8:
1023 case DESC_RATEVHT1SS_MCS9:
1026 case DESC_RATEVHT2SS_MCS0:
1029 case DESC_RATEVHT2SS_MCS1:
1032 case DESC_RATEVHT2SS_MCS2:
1035 case DESC_RATEVHT2SS_MCS3:
1038 case DESC_RATEVHT2SS_MCS4:
1041 case DESC_RATEVHT2SS_MCS5:
1044 case DESC_RATEVHT2SS_MCS6:
1047 case DESC_RATEVHT2SS_MCS7:
1050 case DESC_RATEVHT2SS_MCS8:
1053 case DESC_RATEVHT2SS_MCS9:
1063 if (hw->conf.chandef.chan->band == NL80211_BAND_2GHZ) {
1064 switch (desc_rate) {
1106 switch (desc_rate) {
1137 switch (desc_rate) {
1168 case DESC_RATEMCS10:
1171 case DESC_RATEMCS11:
1174 case DESC_RATEMCS12:
1177 case DESC_RATEMCS13:
1180 case DESC_RATEMCS14:
1183 case DESC_RATEMCS15:
1194 static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw,
1195 struct ieee80211_tx_info *info)
1197 struct rtl_priv *rtlpriv = rtl_priv(hw);
1198 struct ieee80211_tx_rate *r = &info->status.rates[0];
1199 struct ieee80211_rate *txrate;
1202 if (r->flags & IEEE80211_TX_RC_MCS) {
1204 hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 +
1206 } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) {
1207 /* VHT MCS0-9, NSS */
1208 if (ieee80211_rate_get_vht_nss(r) == 2)
1209 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
1211 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
1213 hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r);
1216 txrate = ieee80211_get_tx_rate(hw, info);
1219 hw_value = txrate->hw_value;
1223 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G &&
1224 hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M])
1225 hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M];
1230 void rtl_get_tcb_desc(struct ieee80211_hw *hw,
1231 struct ieee80211_tx_info *info,
1232 struct ieee80211_sta *sta,
1233 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
1235 struct rtl_priv *rtlpriv = rtl_priv(hw);
1236 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
1237 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1238 struct rtl_sta_info *sta_entry =
1239 (sta ? (struct rtl_sta_info *)sta->drv_priv : NULL);
1241 __le16 fc = rtl_get_fc(skb);
1243 tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info);
1245 if (rtl_is_tx_report_skb(hw, skb))
1246 tcb_desc->use_spe_rpt = 1;
1248 if (!ieee80211_is_data(fc)) {
1249 tcb_desc->use_driver_rate = true;
1250 tcb_desc->ratr_index = _rtl_rate_id(hw, sta_entry,
1251 RATR_INX_WIRELESS_MC);
1252 tcb_desc->disable_ratefallback = 1;
1253 tcb_desc->mac_id = 0;
1254 tcb_desc->packet_bw = false;
1260 * We set data rate INX 0
1261 * in rtl_rc.c if skb is special data or
1262 * mgt which need low data rate.
1266 * So tcb_desc->hw_rate is just used for
1267 * special data and mgt frames
1269 if (info->control.rates[0].idx == 0 || ieee80211_is_nullfunc(fc)) {
1270 tcb_desc->use_driver_rate = true;
1271 tcb_desc->ratr_index = _rtl_rate_id(hw, sta_entry,
1272 RATR_INX_WIRELESS_MC);
1274 tcb_desc->disable_ratefallback = 1;
1275 } else if (sta && sta->vht_cap.vht_supported) {
1277 * Because hw will never use hw_rate
1278 * when tcb_desc->use_driver_rate = false
1279 * so we never set highest N rate here,
1280 * and N rate will all be controlled by FW
1281 * when tcb_desc->use_driver_rate = false
1283 tcb_desc->hw_rate = _rtl_get_vht_highest_n_rate(hw, sta);
1284 } else if (sta && sta->ht_cap.ht_supported) {
1285 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw, sta);
1287 enum rtl_var_map var = RTL_RC_OFDM_RATE54M;
1289 if (rtlmac->mode == WIRELESS_MODE_B)
1290 var = RTL_RC_CCK_RATE11M;
1292 tcb_desc->hw_rate = rtlpriv->cfg->maps[var];
1295 if (is_multicast_ether_addr(hdr->addr1))
1296 tcb_desc->multicast = 1;
1297 else if (is_broadcast_ether_addr(hdr->addr1))
1298 tcb_desc->broadcast = 1;
1300 _rtl_txrate_selectmode(hw, sta, tcb_desc);
1301 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
1302 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
1303 _rtl_query_shortgi(hw, sta, tcb_desc, info);
1304 _rtl_query_protection_mode(hw, tcb_desc, info);
1307 bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
1309 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1310 struct rtl_priv *rtlpriv = rtl_priv(hw);
1311 __le16 fc = rtl_get_fc(skb);
1313 if (rtlpriv->dm.supp_phymode_switch &&
1314 mac->link_state < MAC80211_LINKED &&
1315 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
1316 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1317 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1319 if (ieee80211_is_auth(fc)) {
1320 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
1322 mac->link_state = MAC80211_LINKING;
1324 rtlpriv->phy.need_iqk = true;
1329 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
1330 u8 *bssid, u16 tid);
1332 static void process_agg_start(struct ieee80211_hw *hw,
1333 struct ieee80211_hdr *hdr, u16 tid)
1335 struct rtl_priv *rtlpriv = rtl_priv(hw);
1336 struct ieee80211_rx_status rx_status = { 0 };
1337 struct sk_buff *skb_delba = NULL;
1339 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
1341 rx_status.freq = hw->conf.chandef.chan->center_freq;
1342 rx_status.band = hw->conf.chandef.chan->band;
1343 rx_status.flag |= RX_FLAG_DECRYPTED;
1344 rx_status.flag |= RX_FLAG_MACTIME_START;
1345 rx_status.rate_idx = 0;
1346 rx_status.signal = 50 + 10;
1347 memcpy(IEEE80211_SKB_RXCB(skb_delba),
1348 &rx_status, sizeof(rx_status));
1349 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1353 ieee80211_rx_irqsafe(hw, skb_delba);
1357 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1359 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1360 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1361 struct rtl_priv *rtlpriv = rtl_priv(hw);
1362 __le16 fc = rtl_get_fc(skb);
1363 u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
1366 if (!ieee80211_is_action(fc))
1375 if (mac->act_scanning)
1378 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1379 "%s ACT_ADDBAREQ From :%pM\n",
1380 is_tx ? "Tx" : "Rx", hdr->addr2);
1381 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
1382 skb->data, skb->len);
1384 struct ieee80211_sta *sta = NULL;
1385 struct rtl_sta_info *sta_entry = NULL;
1386 struct rtl_tid_data *tid_data;
1387 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1388 u16 capab = 0, tid = 0;
1391 sta = rtl_find_sta(hw, hdr->addr3);
1393 RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
1394 DBG_DMESG, "sta is NULL\n");
1400 (struct rtl_sta_info *)sta->drv_priv;
1406 le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1408 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1409 if (tid >= MAX_TID_COUNT) {
1413 tid_data = &sta_entry->tids[tid];
1414 if (tid_data->agg.rx_agg_state ==
1416 process_agg_start(hw, hdr, tid);
1421 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1422 "%s ACT_ADDBARSP From :%pM\n",
1423 is_tx ? "Tx" : "Rx", hdr->addr2);
1426 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1427 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
1438 static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
1441 struct ieee80211_hw *hw = rtlpriv->hw;
1443 rtlpriv->ra.is_special_data = true;
1444 if (rtlpriv->cfg->ops->get_btc_status())
1445 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(rtlpriv,
1448 ppsc->last_delaylps_stamp_jiffies = jiffies;
1451 static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
1452 struct sk_buff *skb, bool is_enc)
1454 struct rtl_priv *rtlpriv = rtl_priv(hw);
1455 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1456 u8 encrypt_header_len = 0;
1459 switch (rtlpriv->sec.pairwise_enc_algorithm) {
1460 case WEP40_ENCRYPTION:
1461 case WEP104_ENCRYPTION:
1462 encrypt_header_len = 4;/*WEP_IV_LEN*/
1464 case TKIP_ENCRYPTION:
1465 encrypt_header_len = 8;/*TKIP_IV_LEN*/
1467 case AESCCMP_ENCRYPTION:
1468 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
1474 offset = mac_hdr_len + SNAP_SIZE;
1476 offset += encrypt_header_len;
1478 return skb->data + offset;
1481 /*should call before software enc*/
1482 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
1485 struct rtl_priv *rtlpriv = rtl_priv(hw);
1486 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1487 __le16 fc = rtl_get_fc(skb);
1489 const u8 *ether_type_ptr;
1490 const struct iphdr *ip;
1492 if (!ieee80211_is_data(fc))
1495 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
1496 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1498 if (ether_type == ETH_P_IP) {
1499 ip = (struct iphdr *)((u8 *)ether_type_ptr +
1501 if (ip->protocol == IPPROTO_UDP) {
1502 struct udphdr *udp = (struct udphdr *)((u8 *)ip +
1504 if (((((u8 *)udp)[1] == 68) &&
1505 (((u8 *)udp)[3] == 67)) ||
1506 ((((u8 *)udp)[1] == 67) &&
1507 (((u8 *)udp)[3] == 68))) {
1508 /* 68 : UDP BOOTP client
1509 * 67 : UDP BOOTP server
1511 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
1512 DBG_DMESG, "dhcp %s !!\n",
1513 (is_tx) ? "Tx" : "Rx");
1516 setup_special_tx(rtlpriv, ppsc,
1522 } else if (ether_type == ETH_P_ARP) {
1524 setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
1527 } else if (ether_type == ETH_P_PAE) {
1528 /* EAPOL is seen as in-4way */
1529 rtlpriv->btcoexist.btc_info.in_4way = true;
1530 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1531 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1533 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1534 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
1537 rtlpriv->ra.is_special_data = true;
1539 ppsc->last_delaylps_stamp_jiffies = jiffies;
1541 setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
1545 } else if (ether_type == ETH_P_IPV6) {
1546 /* TODO: Handle any IPv6 cases that need special handling.
1547 * For now, always return false
1553 rtlpriv->ra.is_special_data = false;
1557 bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
1560 const u8 *ether_type_ptr;
1562 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
1563 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1566 if (ether_type == ETH_P_PAE)
1572 static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
1574 struct rtl_priv *rtlpriv = rtl_priv(hw);
1575 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1579 * SW_DEFINE[11:8] are reserved (driver fills zeros)
1580 * SW_DEFINE[7:2] are used by driver
1581 * SW_DEFINE[1:0] are reserved for firmware (driver fills zeros)
1583 sn = (atomic_inc_return(&tx_report->sn) & 0x003F) << 2;
1585 tx_report->last_sent_sn = sn;
1586 tx_report->last_sent_time = jiffies;
1588 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1589 "Send TX-Report sn=0x%X\n", sn);
1594 void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
1595 struct ieee80211_hw *hw)
1597 if (ptcb_desc->use_spe_rpt) {
1598 u16 sn = rtl_get_tx_report_sn(hw);
1600 SET_TX_DESC_SPE_RPT(pdesc, 1);
1601 SET_TX_DESC_SW_DEFINE(pdesc, sn);
1605 void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
1607 struct rtl_priv *rtlpriv = rtl_priv(hw);
1608 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1612 if (rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_FW_C2H) {
1614 st = tmp_buf[7] & 0xC0;
1615 retry = tmp_buf[8] & 0x3F;
1617 sn = ((tmp_buf[7] & 0x0F) << 8) | tmp_buf[6];
1618 st = tmp_buf[0] & 0xC0;
1619 retry = tmp_buf[2] & 0x3F;
1622 tx_report->last_recv_sn = sn;
1624 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1625 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
1629 bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
1631 struct rtl_priv *rtlpriv = rtl_priv(hw);
1632 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1634 if (tx_report->last_sent_sn == tx_report->last_recv_sn)
1637 if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
1638 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
1639 "Check TX-Report timeout!! s_sn=0x%X r_sn=0x%X\n",
1640 tx_report->last_sent_sn, tx_report->last_recv_sn);
1641 return true; /* 3 sec. (timeout) seen as acked */
1647 void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
1649 struct rtl_priv *rtlpriv = rtl_priv(hw);
1652 for (i = 0; i < wait_ms; i++) {
1653 if (rtl_check_tx_report_acked(hw))
1655 usleep_range(1000, 2000);
1656 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1657 "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
1661 u32 rtl_get_hal_edca_param(struct ieee80211_hw *hw,
1662 struct ieee80211_vif *vif,
1663 enum wireless_mode wirelessmode,
1664 struct ieee80211_tx_queue_params *param)
1670 /* AIFS = AIFSN * slot time + SIFS */
1671 switch (wirelessmode) {
1672 case WIRELESS_MODE_A:
1673 case WIRELESS_MODE_N_24G:
1674 case WIRELESS_MODE_N_5G:
1675 case WIRELESS_MODE_AC_5G:
1676 case WIRELESS_MODE_AC_24G:
1680 case WIRELESS_MODE_G:
1681 slottime = (vif->bss_conf.use_short_slot ? 9 : 20);
1687 reg |= (param->txop & 0x7FF) << 16;
1688 reg |= (fls(param->cw_max) & 0xF) << 12;
1689 reg |= (fls(param->cw_min) & 0xF) << 8;
1690 reg |= (param->aifs & 0x0F) * slottime + sifstime;
1695 /*********************************************************
1697 * functions called by core.c
1699 *********************************************************/
1700 int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1701 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1703 struct rtl_priv *rtlpriv = rtl_priv(hw);
1704 struct rtl_tid_data *tid_data;
1705 struct rtl_sta_info *sta_entry = NULL;
1710 if (unlikely(tid >= MAX_TID_COUNT))
1713 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1716 tid_data = &sta_entry->tids[tid];
1718 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1719 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1720 tid_data->seq_number);
1722 *ssn = tid_data->seq_number;
1723 tid_data->agg.agg_state = RTL_AGG_START;
1725 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1729 int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1730 struct ieee80211_sta *sta, u16 tid)
1732 struct rtl_priv *rtlpriv = rtl_priv(hw);
1733 struct rtl_tid_data *tid_data;
1734 struct rtl_sta_info *sta_entry = NULL;
1739 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1740 "on ra = %pM tid = %d\n", sta->addr, tid);
1742 if (unlikely(tid >= MAX_TID_COUNT))
1745 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1746 tid_data = &sta_entry->tids[tid];
1747 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
1749 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1753 int rtl_rx_agg_start(struct ieee80211_hw *hw,
1754 struct ieee80211_sta *sta, u16 tid)
1756 struct rtl_priv *rtlpriv = rtl_priv(hw);
1757 struct rtl_tid_data *tid_data;
1758 struct rtl_sta_info *sta_entry = NULL;
1764 if (unlikely(tid >= MAX_TID_COUNT))
1767 if (rtlpriv->cfg->ops->get_btc_status()) {
1768 rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
1775 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1778 tid_data = &sta_entry->tids[tid];
1780 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1781 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1782 tid_data->seq_number);
1784 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1788 int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1789 struct ieee80211_sta *sta, u16 tid)
1791 struct rtl_priv *rtlpriv = rtl_priv(hw);
1792 struct rtl_sta_info *sta_entry = NULL;
1797 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1798 "on ra = %pM tid = %d\n", sta->addr, tid);
1800 if (unlikely(tid >= MAX_TID_COUNT))
1803 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1804 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1809 int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1810 struct ieee80211_sta *sta, u16 tid)
1812 struct rtl_priv *rtlpriv = rtl_priv(hw);
1813 struct rtl_sta_info *sta_entry = NULL;
1818 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1819 "on ra = %pM tid = %d\n", sta->addr, tid);
1821 if (unlikely(tid >= MAX_TID_COUNT))
1824 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1825 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
1830 void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
1832 struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
1833 u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0;
1835 if (rtlpriv->cfg->ops->get_btc_status())
1836 btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
1837 &ctrl_agg_size, &agg_size);
1839 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
1840 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
1841 reject_agg, ctrl_agg_size, agg_size);
1843 rtlpriv->hw->max_rx_aggregation_subframes =
1844 (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF_HT);
1847 /*********************************************************
1849 * wq & timer callback functions
1851 *********************************************************/
1852 /* this function is used for roaming */
1853 void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1855 struct rtl_priv *rtlpriv = rtl_priv(hw);
1856 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1858 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1861 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1864 /* check if this really is a beacon */
1865 if (!ieee80211_is_beacon(hdr->frame_control) &&
1866 !ieee80211_is_probe_resp(hdr->frame_control))
1869 /* min. beacon length + FCS_LEN */
1870 if (skb->len <= 40 + FCS_LEN)
1873 /* and only beacons from the associated BSSID, please */
1874 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
1877 rtlpriv->link_info.bcn_rx_inperiod++;
1880 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
1882 struct rtl_priv *rtlpriv = rtl_priv(hw);
1883 struct rtl_bssid_entry *entry, *next;
1885 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1886 list_del(&entry->list);
1888 rtlpriv->scan_list.num--;
1892 void rtl_scan_list_expire(struct ieee80211_hw *hw)
1894 struct rtl_priv *rtlpriv = rtl_priv(hw);
1895 struct rtl_bssid_entry *entry, *next;
1896 unsigned long flags;
1898 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1900 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1902 if (jiffies_to_msecs(jiffies - entry->age) < 180000)
1905 list_del(&entry->list);
1906 rtlpriv->scan_list.num--;
1908 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1909 "BSSID=%pM is expire in scan list (total=%d)\n",
1910 entry->bssid, rtlpriv->scan_list.num);
1914 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1916 rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
1919 void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
1921 struct rtl_priv *rtlpriv = rtl_priv(hw);
1922 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1923 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1924 unsigned long flags;
1926 struct rtl_bssid_entry *entry;
1927 bool entry_found = false;
1929 /* check if it is scanning */
1930 if (!mac->act_scanning)
1933 /* check if this really is a beacon */
1934 if (!ieee80211_is_beacon(hdr->frame_control) &&
1935 !ieee80211_is_probe_resp(hdr->frame_control))
1938 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1940 list_for_each_entry(entry, &rtlpriv->scan_list.list, list) {
1941 if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) {
1942 list_del_init(&entry->list);
1944 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1945 "Update BSSID=%pM to scan list (total=%d)\n",
1946 hdr->addr3, rtlpriv->scan_list.num);
1952 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1957 memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
1958 rtlpriv->scan_list.num++;
1960 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1961 "Add BSSID=%pM to scan list (total=%d)\n",
1962 hdr->addr3, rtlpriv->scan_list.num);
1965 entry->age = jiffies;
1967 list_add_tail(&entry->list, &rtlpriv->scan_list.list);
1970 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1973 void rtl_watchdog_wq_callback(void *data)
1975 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1978 struct ieee80211_hw *hw = rtlworks->hw;
1979 struct rtl_priv *rtlpriv = rtl_priv(hw);
1980 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1981 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1982 bool busytraffic = false;
1983 bool tx_busy_traffic = false;
1984 bool rx_busy_traffic = false;
1985 bool higher_busytraffic = false;
1986 bool higher_busyrxtraffic = false;
1988 u32 rx_cnt_inp4eriod = 0;
1989 u32 tx_cnt_inp4eriod = 0;
1990 u32 aver_rx_cnt_inperiod = 0;
1991 u32 aver_tx_cnt_inperiod = 0;
1992 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1993 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
1995 if (is_hal_stop(rtlhal))
1998 /* <1> Determine if action frame is allowed */
1999 if (mac->link_state > MAC80211_NOLINK) {
2000 if (mac->cnt_after_linked < 20)
2001 mac->cnt_after_linked++;
2003 mac->cnt_after_linked = 0;
2006 /* <2> to check if traffic busy, if
2007 * busytraffic we don't change channel
2009 if (mac->link_state >= MAC80211_LINKED) {
2010 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
2011 for (idx = 0; idx <= 2; idx++) {
2012 rtlpriv->link_info.num_rx_in4period[idx] =
2013 rtlpriv->link_info.num_rx_in4period[idx + 1];
2014 rtlpriv->link_info.num_tx_in4period[idx] =
2015 rtlpriv->link_info.num_tx_in4period[idx + 1];
2017 rtlpriv->link_info.num_rx_in4period[3] =
2018 rtlpriv->link_info.num_rx_inperiod;
2019 rtlpriv->link_info.num_tx_in4period[3] =
2020 rtlpriv->link_info.num_tx_inperiod;
2021 for (idx = 0; idx <= 3; idx++) {
2023 rtlpriv->link_info.num_rx_in4period[idx];
2025 rtlpriv->link_info.num_tx_in4period[idx];
2027 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
2028 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
2030 /* (2) check traffic busy */
2031 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
2033 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
2034 rx_busy_traffic = true;
2036 tx_busy_traffic = false;
2039 /* Higher Tx/Rx data. */
2040 if (aver_rx_cnt_inperiod > 4000 ||
2041 aver_tx_cnt_inperiod > 4000) {
2042 higher_busytraffic = true;
2044 /* Extremely high Rx data. */
2045 if (aver_rx_cnt_inperiod > 5000)
2046 higher_busyrxtraffic = true;
2049 /* check every tid's tx traffic */
2050 for (tid = 0; tid <= 7; tid++) {
2051 for (idx = 0; idx <= 2; idx++)
2052 rtlpriv->link_info.tidtx_in4period[tid][idx] =
2053 rtlpriv->link_info.tidtx_in4period[tid]
2055 rtlpriv->link_info.tidtx_in4period[tid][3] =
2056 rtlpriv->link_info.tidtx_inperiod[tid];
2058 for (idx = 0; idx <= 3; idx++)
2059 tidtx_inp4eriod[tid] +=
2060 rtlpriv->link_info.tidtx_in4period[tid][idx];
2061 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
2062 if (aver_tidtx_inperiod[tid] > 5000)
2063 rtlpriv->link_info.higher_busytxtraffic[tid] =
2066 rtlpriv->link_info.higher_busytxtraffic[tid] =
2070 /* PS is controlled by coex. */
2071 if (rtlpriv->cfg->ops->get_btc_status() &&
2072 rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
2073 goto label_lps_done;
2075 if (rtlpriv->link_info.num_rx_inperiod +
2076 rtlpriv->link_info.num_tx_inperiod > 8 ||
2077 rtlpriv->link_info.num_rx_inperiod > 2)
2086 rtlpriv->link_info.num_rx_inperiod = 0;
2087 rtlpriv->link_info.num_tx_inperiod = 0;
2088 for (tid = 0; tid <= 7; tid++)
2089 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
2091 rtlpriv->link_info.busytraffic = busytraffic;
2092 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
2093 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
2094 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
2095 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
2097 rtlpriv->stats.txbytesunicast_inperiod =
2098 rtlpriv->stats.txbytesunicast -
2099 rtlpriv->stats.txbytesunicast_last;
2100 rtlpriv->stats.rxbytesunicast_inperiod =
2101 rtlpriv->stats.rxbytesunicast -
2102 rtlpriv->stats.rxbytesunicast_last;
2103 rtlpriv->stats.txbytesunicast_last = rtlpriv->stats.txbytesunicast;
2104 rtlpriv->stats.rxbytesunicast_last = rtlpriv->stats.rxbytesunicast;
2106 rtlpriv->stats.txbytesunicast_inperiod_tp =
2107 (u32)(rtlpriv->stats.txbytesunicast_inperiod * 8 / 2 /
2109 rtlpriv->stats.rxbytesunicast_inperiod_tp =
2110 (u32)(rtlpriv->stats.rxbytesunicast_inperiod * 8 / 2 /
2114 if (!rtlpriv->cfg->mod_params->disable_watchdog)
2115 rtlpriv->cfg->ops->dm_watchdog(hw);
2118 if (mac->link_state == MAC80211_LINKED &&
2119 mac->opmode == NL80211_IFTYPE_STATION) {
2120 if ((rtlpriv->link_info.bcn_rx_inperiod +
2121 rtlpriv->link_info.num_rx_inperiod) == 0) {
2122 rtlpriv->link_info.roam_times++;
2123 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
2124 "AP off for %d s\n",
2125 (rtlpriv->link_info.roam_times * 2));
2127 /* if we can't recv beacon for 10s,
2128 * we should reconnect this AP
2130 if (rtlpriv->link_info.roam_times >= 5) {
2131 pr_err("AP off, try to reconnect now\n");
2132 rtlpriv->link_info.roam_times = 0;
2133 ieee80211_connection_loss(rtlpriv->mac80211.vif);
2136 rtlpriv->link_info.roam_times = 0;
2140 if (rtlpriv->cfg->ops->get_btc_status())
2141 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
2143 if (rtlpriv->btcoexist.btc_info.in_4way) {
2144 if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
2145 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
2146 rtlpriv->btcoexist.btc_info.in_4way = false;
2149 rtlpriv->link_info.bcn_rx_inperiod = 0;
2152 rtl_scan_list_expire(hw);
2155 void rtl_watch_dog_timer_callback(struct timer_list *t)
2157 struct rtl_priv *rtlpriv = from_timer(rtlpriv, t, works.watchdog_timer);
2159 queue_delayed_work(rtlpriv->works.rtl_wq,
2160 &rtlpriv->works.watchdog_wq, 0);
2162 mod_timer(&rtlpriv->works.watchdog_timer,
2163 jiffies + MSECS(RTL_WATCH_DOG_TIME));
2166 void rtl_fwevt_wq_callback(void *data)
2168 struct rtl_works *rtlworks =
2169 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
2170 struct ieee80211_hw *hw = rtlworks->hw;
2171 struct rtl_priv *rtlpriv = rtl_priv(hw);
2173 rtlpriv->cfg->ops->c2h_command_handle(hw);
2176 void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val)
2178 struct rtl_priv *rtlpriv = rtl_priv(hw);
2179 unsigned long flags;
2180 struct rtl_c2hcmd *c2hcmd;
2182 c2hcmd = kmalloc(sizeof(*c2hcmd),
2183 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
2188 c2hcmd->val = kmalloc(len,
2189 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
2197 memcpy(c2hcmd->val, val, len);
2200 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2202 list_add_tail(&c2hcmd->list, &rtlpriv->c2hcmd_list);
2204 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2207 queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
2215 RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING,
2216 "C2H cmd enqueue fail.\n");
2219 void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
2221 struct rtl_priv *rtlpriv = rtl_priv(hw);
2222 unsigned long flags;
2223 struct rtl_c2hcmd *c2hcmd;
2226 for (i = 0; i < 200; i++) {
2227 /* dequeue a task */
2228 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2230 c2hcmd = list_first_entry_or_null(&rtlpriv->c2hcmd_list,
2231 struct rtl_c2hcmd, list);
2234 list_del(&c2hcmd->list);
2236 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2242 if (rtlpriv->cfg->ops->c2h_content_parsing && exec)
2243 rtlpriv->cfg->ops->c2h_content_parsing(hw,
2244 c2hcmd->tag, c2hcmd->len, c2hcmd->val);
2253 void rtl_c2hcmd_wq_callback(void *data)
2255 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
2258 struct ieee80211_hw *hw = rtlworks->hw;
2260 rtl_c2hcmd_launcher(hw, 1);
2263 void rtl_easy_concurrent_retrytimer_callback(struct timer_list *t)
2265 struct rtl_priv *rtlpriv =
2266 from_timer(rtlpriv, t, works.dualmac_easyconcurrent_retrytimer);
2267 struct ieee80211_hw *hw = rtlpriv->hw;
2268 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
2273 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
2276 /*********************************************************
2278 * frame process functions
2280 *********************************************************/
2281 u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
2283 struct ieee80211_mgmt *mgmt = (void *)data;
2286 pos = (u8 *)mgmt->u.beacon.variable;
2289 if (pos + 2 + pos[1] > end)
2300 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
2301 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
2302 static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
2303 enum ieee80211_smps_mode smps,
2306 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2307 struct sk_buff *skb;
2308 struct ieee80211_mgmt *action_frame;
2310 /* 27 = header + category + action + smps mode */
2311 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
2315 skb_reserve(skb, hw->extra_tx_headroom);
2316 action_frame = skb_put_zero(skb, 27);
2317 memcpy(action_frame->da, da, ETH_ALEN);
2318 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
2319 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2320 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2321 IEEE80211_STYPE_ACTION);
2322 action_frame->u.action.category = WLAN_CATEGORY_HT;
2323 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
2325 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
2326 case IEEE80211_SMPS_NUM_MODES:/* 4 */
2329 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
2330 action_frame->u.action.u.ht_smps.smps_control =
2331 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
2333 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
2334 action_frame->u.action.u.ht_smps.smps_control =
2335 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
2337 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
2338 action_frame->u.action.u.ht_smps.smps_control =
2339 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
2346 int rtl_send_smps_action(struct ieee80211_hw *hw,
2347 struct ieee80211_sta *sta,
2348 enum ieee80211_smps_mode smps)
2350 struct rtl_priv *rtlpriv = rtl_priv(hw);
2351 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2352 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
2353 struct sk_buff *skb = NULL;
2354 struct rtl_tcb_desc tcb_desc;
2355 u8 bssid[ETH_ALEN] = {0};
2357 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
2359 if (rtlpriv->mac80211.act_scanning)
2365 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
2368 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
2371 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
2372 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
2374 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
2376 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
2377 /* this is a type = mgmt * stype = action frame */
2379 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2380 struct rtl_sta_info *sta_entry =
2381 (struct rtl_sta_info *)sta->drv_priv;
2382 sta_entry->mimo_ps = smps;
2383 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */
2385 info->control.rates[0].idx = 0;
2386 info->band = hw->conf.chandef.chan->band;
2387 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
2395 void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
2397 struct rtl_priv *rtlpriv = rtl_priv(hw);
2398 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2399 enum io_type iotype;
2401 if (!is_hal_stop(rtlhal)) {
2402 switch (operation) {
2403 case SCAN_OPT_BACKUP:
2404 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
2405 rtlpriv->cfg->ops->set_hw_reg(hw,
2409 case SCAN_OPT_RESTORE:
2410 iotype = IO_CMD_RESUME_DM_BY_SCAN;
2411 rtlpriv->cfg->ops->set_hw_reg(hw,
2416 pr_err("Unknown Scan Backup operation.\n");
2422 /* because mac80211 have issues when can receive del ba
2423 * so here we just make a fake del_ba if we receive a ba_req
2424 * but rx_agg was opened to let mac80211 release some ba
2425 * related resources, so please this del_ba for tx
2427 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
2428 u8 *sa, u8 *bssid, u16 tid)
2430 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2431 struct sk_buff *skb;
2432 struct ieee80211_mgmt *action_frame;
2435 /* 27 = header + category + action + smps mode */
2436 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
2440 skb_reserve(skb, hw->extra_tx_headroom);
2441 action_frame = skb_put_zero(skb, 34);
2442 memcpy(action_frame->sa, sa, ETH_ALEN);
2443 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
2444 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2445 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2446 IEEE80211_STYPE_ACTION);
2447 action_frame->u.action.category = WLAN_CATEGORY_BACK;
2448 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
2449 params = (u16)(1 << 11); /* bit 11 initiator */
2450 params |= (u16)(tid << 12); /* bit 15:12 TID number */
2452 action_frame->u.action.u.delba.params = cpu_to_le16(params);
2453 action_frame->u.action.u.delba.reason_code =
2454 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
2459 bool rtl_check_beacon_key(struct ieee80211_hw *hw, void *data, unsigned int len)
2461 struct rtl_priv *rtlpriv = rtl_priv(hw);
2462 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2463 struct rtl_phy *rtlphy = &rtlpriv->phy;
2464 struct ieee80211_hdr *hdr = data;
2465 struct ieee80211_ht_cap *ht_cap_ie;
2466 struct ieee80211_ht_operation *ht_oper_ie = NULL;
2467 struct rtl_beacon_keys bcn_key = {};
2468 struct rtl_beacon_keys *cur_bcn_key;
2476 if (mac->opmode != NL80211_IFTYPE_STATION)
2479 /* check if this really is a beacon*/
2480 if (!ieee80211_is_beacon(hdr->frame_control))
2483 /* min. beacon length + FCS_LEN */
2484 if (len <= 40 + FCS_LEN)
2487 cur_bcn_key = &mac->cur_beacon_keys;
2489 if (rtlpriv->mac80211.link_state == MAC80211_NOLINK) {
2490 if (cur_bcn_key->valid) {
2491 cur_bcn_key->valid = false;
2492 RT_TRACE(rtlpriv, COMP_BEACON, DBG_LOUD,
2493 "Reset cur_beacon_keys.valid to false!\n");
2498 /* and only beacons from the associated BSSID, please */
2499 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
2502 /***** Parsing DS Param IE ******/
2503 ds_param = rtl_find_ie(data, len - FCS_LEN, WLAN_EID_DS_PARAMS);
2505 if (ds_param && !(ds_param[1] < sizeof(*ds_param))) {
2506 ds_param_len = ds_param[1];
2507 bcn_key.bcn_channel = ds_param[2];
2512 /***** Parsing HT Cap. IE ******/
2513 ht_cap = rtl_find_ie(data, len - FCS_LEN, WLAN_EID_HT_CAPABILITY);
2515 if (ht_cap && !(ht_cap[1] < sizeof(*ht_cap))) {
2516 ht_cap_len = ht_cap[1];
2517 ht_cap_ie = (struct ieee80211_ht_cap *)&ht_cap[2];
2518 bcn_key.ht_cap_info = ht_cap_ie->cap_info;
2523 /***** Parsing HT Info. IE ******/
2524 ht_oper = rtl_find_ie(data, len - FCS_LEN, WLAN_EID_HT_OPERATION);
2526 if (ht_oper && !(ht_oper[1] < sizeof(*ht_oper))) {
2527 ht_oper_len = ht_oper[1];
2528 ht_oper_ie = (struct ieee80211_ht_operation *)&ht_oper[2];
2533 /* update bcn_key */
2535 if (!ds_param && ht_oper && ht_oper_ie)
2536 bcn_key.bcn_channel = ht_oper_ie->primary_chan;
2538 if (ht_oper && ht_oper_ie)
2539 bcn_key.ht_info_infos_0_sco = ht_oper_ie->ht_param & 0x03;
2541 bcn_key.valid = true;
2543 /* update cur_beacon_keys or compare beacon key */
2544 if (rtlpriv->mac80211.link_state != MAC80211_LINKED &&
2545 rtlpriv->mac80211.link_state != MAC80211_LINKED_SCANNING)
2548 if (!cur_bcn_key->valid) {
2549 /* update cur_beacon_keys */
2550 memcpy(cur_bcn_key, &bcn_key, sizeof(bcn_key));
2551 cur_bcn_key->valid = true;
2553 RT_TRACE(rtlpriv, COMP_BEACON, DBG_LOUD,
2554 "Beacon key update!ch=%d, ht_cap_info=0x%x, sco=0x%x\n",
2555 cur_bcn_key->bcn_channel,
2556 cur_bcn_key->ht_cap_info,
2557 cur_bcn_key->ht_info_infos_0_sco);
2561 /* compare beacon key */
2562 if (!memcmp(cur_bcn_key, &bcn_key, sizeof(bcn_key))) {
2563 /* same beacon key */
2564 mac->new_beacon_cnt = 0;
2568 if (cur_bcn_key->bcn_channel == bcn_key.bcn_channel &&
2569 cur_bcn_key->ht_cap_info == bcn_key.ht_cap_info) {
2570 /* Beacon HT info IE, secondary channel offset check */
2572 if (cur_bcn_key->ht_info_infos_0_sco >
2573 bcn_key.ht_info_infos_0_sco) {
2574 /* Not a new beacon */
2575 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2576 "Beacon BW change! sco:0x%x -> 0x%x\n",
2577 cur_bcn_key->ht_info_infos_0_sco,
2578 bcn_key.ht_info_infos_0_sco);
2580 cur_bcn_key->ht_info_infos_0_sco =
2581 bcn_key.ht_info_infos_0_sco;
2584 if (rtlphy->max_ht_chan_bw >= HT_CHANNEL_WIDTH_20_40) {
2585 /* Not a new beacon */
2586 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2587 "Beacon BW change! sco:0x%x -> 0x%x\n",
2588 cur_bcn_key->ht_info_infos_0_sco,
2589 bcn_key.ht_info_infos_0_sco);
2591 cur_bcn_key->ht_info_infos_0_sco =
2592 bcn_key.ht_info_infos_0_sco;
2594 mac->new_beacon_cnt++;
2598 mac->new_beacon_cnt++;
2601 if (mac->new_beacon_cnt == 1) {
2602 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2603 "Get new beacon.\n");
2604 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2605 "Cur : ch=%d, ht_cap=0x%x, sco=0x%x\n",
2606 cur_bcn_key->bcn_channel,
2607 cur_bcn_key->ht_cap_info,
2608 cur_bcn_key->ht_info_infos_0_sco);
2609 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2610 "New RX : ch=%d, ht_cap=0x%x, sco=0x%x\n",
2611 bcn_key.bcn_channel,
2612 bcn_key.ht_cap_info,
2613 bcn_key.ht_info_infos_0_sco);
2615 } else if (mac->new_beacon_cnt > 1) {
2616 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2617 "new beacon cnt: %d\n",
2618 mac->new_beacon_cnt);
2621 if (mac->new_beacon_cnt > 3) {
2622 ieee80211_connection_loss(rtlpriv->mac80211.vif);
2623 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2624 "new beacon cnt >3, disconnect !\n");
2632 /*********************************************************
2636 *********************************************************/
2637 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
2638 struct octet_string vendor_ie)
2640 struct rtl_priv *rtlpriv = rtl_priv(hw);
2641 bool matched = false;
2642 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
2643 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
2644 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
2645 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
2646 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
2647 static u8 racap[] = { 0x00, 0x0c, 0x43 };
2648 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
2649 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
2651 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
2652 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
2653 rtlpriv->mac80211.vendor = PEER_ATH;
2655 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
2656 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
2657 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
2658 rtlpriv->mac80211.vendor = PEER_BROAD;
2660 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
2661 rtlpriv->mac80211.vendor = PEER_RAL;
2663 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
2664 rtlpriv->mac80211.vendor = PEER_CISCO;
2666 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
2667 rtlpriv->mac80211.vendor = PEER_MARV;
2674 static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
2677 struct ieee80211_mgmt *mgmt = (void *)data;
2678 struct octet_string vendor_ie;
2681 pos = (u8 *)mgmt->u.beacon.variable;
2684 if (pos[0] == 221) {
2685 vendor_ie.length = pos[1];
2686 vendor_ie.octet = &pos[2];
2687 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
2691 if (pos + 2 + pos[1] > end)
2699 void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
2701 struct rtl_priv *rtlpriv = rtl_priv(hw);
2702 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2703 struct ieee80211_hdr *hdr = (void *)data;
2704 u32 vendor = PEER_UNKNOWN;
2706 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
2707 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
2708 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
2709 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
2710 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
2711 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
2712 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
2713 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
2714 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
2715 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
2716 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
2717 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
2718 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
2719 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
2720 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
2721 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
2723 if (mac->opmode != NL80211_IFTYPE_STATION)
2726 if (mac->link_state == MAC80211_NOLINK) {
2727 mac->vendor = PEER_UNKNOWN;
2731 if (mac->cnt_after_linked > 2)
2734 /* check if this really is a beacon */
2735 if (!ieee80211_is_beacon(hdr->frame_control))
2738 /* min. beacon length + FCS_LEN */
2739 if (len <= 40 + FCS_LEN)
2742 /* and only beacons from the associated BSSID, please */
2743 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
2746 if (rtl_find_221_ie(hw, data, len))
2747 vendor = mac->vendor;
2749 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
2750 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
2751 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
2752 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
2753 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
2754 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
2755 vendor == PEER_ATH) {
2757 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
2758 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
2759 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
2760 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
2761 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
2762 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
2763 vendor == PEER_RAL) {
2764 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
2766 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
2767 vendor == PEER_CISCO) {
2768 vendor = PEER_CISCO;
2769 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
2770 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
2771 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
2772 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
2773 vendor == PEER_BROAD) {
2774 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
2775 vendor = PEER_BROAD;
2776 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
2777 vendor == PEER_MARV) {
2779 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
2782 mac->vendor = vendor;
2788 MODULE_LICENSE("GPL");
2789 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2791 struct rtl_global_var rtl_global_var = {};
2793 int rtl_core_module_init(void)
2795 if (rtl_rate_control_register())
2796 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
2799 rtl_debugfs_add_topdir();
2801 /* init some global vars */
2802 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2803 spin_lock_init(&rtl_global_var.glb_list_lock);
2808 void rtl_core_module_exit(void)
2811 rtl_rate_control_unregister();
2813 /* remove debugfs */
2814 rtl_debugfs_remove_topdir();