1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
35 #include <linux/module.h>
36 #include <linux/udp.h>
39 *NOTICE!!!: This file will be very big, we should
40 *keep it clear under following roles:
42 *This file include following parts, so, if you add new
43 *functions into this file, please check which part it
44 *should includes. or check if you should add new part
47 *1) mac80211 init functions
48 *2) tx information functions
49 *3) functions called by core.c
50 *4) wq & timer callback functions
51 *5) frame process functions
58 /*********************************************************
60 * mac80211 init functions
62 *********************************************************/
63 static struct ieee80211_channel rtl_channeltable_2g[] = {
64 {.center_freq = 2412, .hw_value = 1,},
65 {.center_freq = 2417, .hw_value = 2,},
66 {.center_freq = 2422, .hw_value = 3,},
67 {.center_freq = 2427, .hw_value = 4,},
68 {.center_freq = 2432, .hw_value = 5,},
69 {.center_freq = 2437, .hw_value = 6,},
70 {.center_freq = 2442, .hw_value = 7,},
71 {.center_freq = 2447, .hw_value = 8,},
72 {.center_freq = 2452, .hw_value = 9,},
73 {.center_freq = 2457, .hw_value = 10,},
74 {.center_freq = 2462, .hw_value = 11,},
75 {.center_freq = 2467, .hw_value = 12,},
76 {.center_freq = 2472, .hw_value = 13,},
77 {.center_freq = 2484, .hw_value = 14,},
80 static struct ieee80211_channel rtl_channeltable_5g[] = {
81 {.center_freq = 5180, .hw_value = 36,},
82 {.center_freq = 5200, .hw_value = 40,},
83 {.center_freq = 5220, .hw_value = 44,},
84 {.center_freq = 5240, .hw_value = 48,},
85 {.center_freq = 5260, .hw_value = 52,},
86 {.center_freq = 5280, .hw_value = 56,},
87 {.center_freq = 5300, .hw_value = 60,},
88 {.center_freq = 5320, .hw_value = 64,},
89 {.center_freq = 5500, .hw_value = 100,},
90 {.center_freq = 5520, .hw_value = 104,},
91 {.center_freq = 5540, .hw_value = 108,},
92 {.center_freq = 5560, .hw_value = 112,},
93 {.center_freq = 5580, .hw_value = 116,},
94 {.center_freq = 5600, .hw_value = 120,},
95 {.center_freq = 5620, .hw_value = 124,},
96 {.center_freq = 5640, .hw_value = 128,},
97 {.center_freq = 5660, .hw_value = 132,},
98 {.center_freq = 5680, .hw_value = 136,},
99 {.center_freq = 5700, .hw_value = 140,},
100 {.center_freq = 5745, .hw_value = 149,},
101 {.center_freq = 5765, .hw_value = 153,},
102 {.center_freq = 5785, .hw_value = 157,},
103 {.center_freq = 5805, .hw_value = 161,},
104 {.center_freq = 5825, .hw_value = 165,},
107 static struct ieee80211_rate rtl_ratetable_2g[] = {
108 {.bitrate = 10, .hw_value = 0x00,},
109 {.bitrate = 20, .hw_value = 0x01,},
110 {.bitrate = 55, .hw_value = 0x02,},
111 {.bitrate = 110, .hw_value = 0x03,},
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 struct ieee80211_rate rtl_ratetable_5g[] = {
123 {.bitrate = 60, .hw_value = 0x04,},
124 {.bitrate = 90, .hw_value = 0x05,},
125 {.bitrate = 120, .hw_value = 0x06,},
126 {.bitrate = 180, .hw_value = 0x07,},
127 {.bitrate = 240, .hw_value = 0x08,},
128 {.bitrate = 360, .hw_value = 0x09,},
129 {.bitrate = 480, .hw_value = 0x0a,},
130 {.bitrate = 540, .hw_value = 0x0b,},
133 static const struct ieee80211_supported_band rtl_band_2ghz = {
134 .band = NL80211_BAND_2GHZ,
136 .channels = rtl_channeltable_2g,
137 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
139 .bitrates = rtl_ratetable_2g,
140 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
145 static struct ieee80211_supported_band rtl_band_5ghz = {
146 .band = NL80211_BAND_5GHZ,
148 .channels = rtl_channeltable_5g,
149 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
151 .bitrates = rtl_ratetable_5g,
152 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
157 static const u8 tid_to_ac[] = {
158 2, /* IEEE80211_AC_BE */
159 3, /* IEEE80211_AC_BK */
160 3, /* IEEE80211_AC_BK */
161 2, /* IEEE80211_AC_BE */
162 1, /* IEEE80211_AC_VI */
163 1, /* IEEE80211_AC_VI */
164 0, /* IEEE80211_AC_VO */
165 0, /* IEEE80211_AC_VO */
168 u8 rtl_tid_to_ac(u8 tid)
170 return tid_to_ac[tid];
172 EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
174 static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
175 struct ieee80211_sta_ht_cap *ht_cap)
177 struct rtl_priv *rtlpriv = rtl_priv(hw);
178 struct rtl_phy *rtlphy = &(rtlpriv->phy);
180 ht_cap->ht_supported = true;
181 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
182 IEEE80211_HT_CAP_SGI_40 |
183 IEEE80211_HT_CAP_SGI_20 |
184 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
186 if (rtlpriv->rtlhal.disable_amsdu_8k)
187 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
190 *Maximum length of AMPDU that the STA can receive.
191 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
193 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
195 /*Minimum MPDU start spacing , */
196 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
198 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
200 /*hw->wiphy->bands[NL80211_BAND_2GHZ]
203 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
204 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
205 *if rx_ant >= 3 rx_mask[2]= 0xff;
206 *if BW_40 rx_mask[4]= 0x01;
207 *highest supported RX rate
209 if (rtlpriv->dm.supp_phymode_switch) {
210 pr_info("Support phy mode switch\n");
212 ht_cap->mcs.rx_mask[0] = 0xFF;
213 ht_cap->mcs.rx_mask[1] = 0xFF;
214 ht_cap->mcs.rx_mask[4] = 0x01;
216 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
218 if (get_rf_type(rtlphy) == RF_1T2R ||
219 get_rf_type(rtlphy) == RF_2T2R) {
220 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
222 ht_cap->mcs.rx_mask[0] = 0xFF;
223 ht_cap->mcs.rx_mask[1] = 0xFF;
224 ht_cap->mcs.rx_mask[4] = 0x01;
226 ht_cap->mcs.rx_highest =
227 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
228 } else if (get_rf_type(rtlphy) == RF_1T1R) {
229 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
231 ht_cap->mcs.rx_mask[0] = 0xFF;
232 ht_cap->mcs.rx_mask[1] = 0x00;
233 ht_cap->mcs.rx_mask[4] = 0x01;
235 ht_cap->mcs.rx_highest =
236 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
241 static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
242 struct ieee80211_sta_vht_cap *vht_cap)
244 struct rtl_priv *rtlpriv = rtl_priv(hw);
245 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
247 if (!(rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT))
250 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE ||
251 rtlhal->hw_type == HARDWARE_TYPE_RTL8822BE) {
254 vht_cap->vht_supported = true;
256 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
257 IEEE80211_VHT_CAP_SHORT_GI_80 |
258 IEEE80211_VHT_CAP_TXSTBC |
259 IEEE80211_VHT_CAP_RXSTBC_1 |
260 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
261 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
262 IEEE80211_VHT_CAP_HTC_VHT |
263 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
264 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
265 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
268 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
269 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
270 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
271 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
272 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
273 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
274 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
275 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
277 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
278 vht_cap->vht_mcs.rx_highest =
279 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
280 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
281 vht_cap->vht_mcs.tx_highest =
282 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
283 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
286 vht_cap->vht_supported = true;
288 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
289 IEEE80211_VHT_CAP_SHORT_GI_80 |
290 IEEE80211_VHT_CAP_TXSTBC |
291 IEEE80211_VHT_CAP_RXSTBC_1 |
292 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
293 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
294 IEEE80211_VHT_CAP_HTC_VHT |
295 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
296 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
297 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
300 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
301 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
302 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
303 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
304 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
305 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
306 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
307 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
309 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
310 vht_cap->vht_mcs.rx_highest =
311 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
312 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
313 vht_cap->vht_mcs.tx_highest =
314 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
318 static void _rtl_init_mac80211(struct ieee80211_hw *hw)
320 struct rtl_priv *rtlpriv = rtl_priv(hw);
321 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
322 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
323 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
324 struct ieee80211_supported_band *sband;
326 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
327 rtlhal->bandset == BAND_ON_BOTH) {
329 /* <1> use mac->bands as mem for hw->wiphy->bands */
330 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
332 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
333 * to default value(1T1R) */
334 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz,
335 sizeof(struct ieee80211_supported_band));
337 /* <3> init ht cap base on ant_num */
338 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
340 /* <4> set mac->sband to wiphy->sband */
341 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
344 /* <1> use mac->bands as mem for hw->wiphy->bands */
345 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
347 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
348 * to default value(1T1R) */
349 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz,
350 sizeof(struct ieee80211_supported_band));
352 /* <3> init ht cap base on ant_num */
353 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
355 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
356 /* <4> set mac->sband to wiphy->sband */
357 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
359 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
360 /* <1> use mac->bands as mem for hw->wiphy->bands */
361 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
363 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
364 * to default value(1T1R) */
365 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]),
367 sizeof(struct ieee80211_supported_band));
369 /* <3> init ht cap base on ant_num */
370 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
372 /* <4> set mac->sband to wiphy->sband */
373 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
374 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
375 /* <1> use mac->bands as mem for hw->wiphy->bands */
376 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
378 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
379 * to default value(1T1R) */
380 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]),
382 sizeof(struct ieee80211_supported_band));
384 /* <3> init ht cap base on ant_num */
385 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
387 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
388 /* <4> set mac->sband to wiphy->sband */
389 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
391 pr_err("Err BAND %d\n",
392 rtlhal->current_bandtype);
395 /* <5> set hw caps */
396 ieee80211_hw_set(hw, SIGNAL_DBM);
397 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
398 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
399 ieee80211_hw_set(hw, MFP_CAPABLE);
400 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
401 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
402 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
404 /* swlps or hwlps has been set in diff chip in init_sw_vars */
405 if (rtlpriv->psc.swctrl_lps) {
406 ieee80211_hw_set(hw, SUPPORTS_PS);
407 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
409 if (rtlpriv->psc.fwctrl_lps) {
410 ieee80211_hw_set(hw, SUPPORTS_PS);
411 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
413 hw->wiphy->interface_modes =
414 BIT(NL80211_IFTYPE_AP) |
415 BIT(NL80211_IFTYPE_STATION) |
416 BIT(NL80211_IFTYPE_ADHOC) |
417 BIT(NL80211_IFTYPE_MESH_POINT) |
418 BIT(NL80211_IFTYPE_P2P_CLIENT) |
419 BIT(NL80211_IFTYPE_P2P_GO);
420 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
422 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
424 hw->wiphy->rts_threshold = 2347;
427 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
429 /* TODO: Correct this value for our hw */
430 hw->max_listen_interval = MAX_LISTEN_INTERVAL;
431 hw->max_rate_tries = MAX_RATE_TRIES;
432 /* hw->max_rates = 1; */
433 hw->sta_data_size = sizeof(struct rtl_sta_info);
435 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
437 if (rtlpriv->psc.wo_wlan_mode) {
438 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
439 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
440 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
441 rtlpriv->wowlan.n_patterns =
442 MAX_SUPPORT_WOL_PATTERN_NUM;
443 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
444 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
446 hw->wiphy->wowlan = &rtlpriv->wowlan;
450 /* <6> mac address */
451 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
452 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
454 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
455 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
456 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
460 static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
462 struct rtl_priv *rtlpriv = rtl_priv(hw);
465 timer_setup(&rtlpriv->works.watchdog_timer,
466 rtl_watch_dog_timer_callback, 0);
467 timer_setup(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
468 rtl_easy_concurrent_retrytimer_callback, 0);
470 rtlpriv->works.hw = hw;
471 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
472 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
473 (void *)rtl_watchdog_wq_callback);
474 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
475 (void *)rtl_ips_nic_off_wq_callback);
476 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
477 (void *)rtl_swlps_wq_callback);
478 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
479 (void *)rtl_swlps_rfon_wq_callback);
480 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
481 (void *)rtl_fwevt_wq_callback);
482 INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq,
483 (void *)rtl_c2hcmd_wq_callback);
487 void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq)
489 struct rtl_priv *rtlpriv = rtl_priv(hw);
491 del_timer_sync(&rtlpriv->works.watchdog_timer);
493 cancel_delayed_work_sync(&rtlpriv->works.watchdog_wq);
495 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
497 cancel_delayed_work_sync(&rtlpriv->works.ips_nic_off_wq);
498 cancel_delayed_work_sync(&rtlpriv->works.ps_work);
499 cancel_delayed_work_sync(&rtlpriv->works.ps_rfon_wq);
500 cancel_delayed_work_sync(&rtlpriv->works.fwevt_wq);
501 cancel_delayed_work_sync(&rtlpriv->works.c2hcmd_wq);
503 EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
505 void rtl_init_rfkill(struct ieee80211_hw *hw)
507 struct rtl_priv *rtlpriv = rtl_priv(hw);
513 /*set init state to on */
514 rtlpriv->rfkill.rfkill_state = true;
515 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
517 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
520 pr_info("rtlwifi: wireless switch is %s\n",
521 rtlpriv->rfkill.rfkill_state ? "on" : "off");
523 rtlpriv->rfkill.rfkill_state = radio_state;
525 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
526 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
529 wiphy_rfkill_start_polling(hw->wiphy);
531 EXPORT_SYMBOL(rtl_init_rfkill);
533 void rtl_deinit_rfkill(struct ieee80211_hw *hw)
535 wiphy_rfkill_stop_polling(hw->wiphy);
537 EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
539 int rtl_init_core(struct ieee80211_hw *hw)
541 struct rtl_priv *rtlpriv = rtl_priv(hw);
542 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
544 /* <1> init mac80211 */
545 _rtl_init_mac80211(hw);
548 /* <2> rate control register */
549 hw->rate_control_algorithm = "rtl_rc";
552 * <3> init CRDA must come after init
553 * mac80211 hw in _rtl_init_mac80211.
555 if (rtl_regd_init(hw, rtl_reg_notifier)) {
556 pr_err("REGD init failed\n");
561 mutex_init(&rtlpriv->locks.conf_mutex);
562 mutex_init(&rtlpriv->locks.ips_mutex);
563 mutex_init(&rtlpriv->locks.lps_mutex);
564 spin_lock_init(&rtlpriv->locks.irq_th_lock);
565 spin_lock_init(&rtlpriv->locks.h2c_lock);
566 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
567 spin_lock_init(&rtlpriv->locks.rf_lock);
568 spin_lock_init(&rtlpriv->locks.waitq_lock);
569 spin_lock_init(&rtlpriv->locks.entry_list_lock);
570 spin_lock_init(&rtlpriv->locks.c2hcmd_lock);
571 spin_lock_init(&rtlpriv->locks.scan_list_lock);
572 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
573 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
574 spin_lock_init(&rtlpriv->locks.iqk_lock);
576 INIT_LIST_HEAD(&rtlpriv->entry_list);
577 INIT_LIST_HEAD(&rtlpriv->scan_list.list);
578 skb_queue_head_init(&rtlpriv->tx_report.queue);
579 skb_queue_head_init(&rtlpriv->c2hcmd_queue);
581 rtlmac->link_state = MAC80211_NOLINK;
583 /* <6> init deferred work */
584 _rtl_init_deferred_work(hw);
588 EXPORT_SYMBOL_GPL(rtl_init_core);
590 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
591 static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw,
594 void rtl_deinit_core(struct ieee80211_hw *hw)
596 rtl_c2hcmd_launcher(hw, 0);
597 rtl_free_entries_from_scan_list(hw);
598 rtl_free_entries_from_ack_queue(hw, false);
600 EXPORT_SYMBOL_GPL(rtl_deinit_core);
602 void rtl_init_rx_config(struct ieee80211_hw *hw)
604 struct rtl_priv *rtlpriv = rtl_priv(hw);
605 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
607 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
609 EXPORT_SYMBOL_GPL(rtl_init_rx_config);
611 /*********************************************************
613 * tx information functions
615 *********************************************************/
616 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
617 struct rtl_tcb_desc *tcb_desc,
618 struct ieee80211_tx_info *info)
620 struct rtl_priv *rtlpriv = rtl_priv(hw);
621 u8 rate_flag = info->control.rates[0].flags;
623 tcb_desc->use_shortpreamble = false;
625 /* 1M can only use Long Preamble. 11B spec */
626 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
628 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
629 tcb_desc->use_shortpreamble = true;
634 static void _rtl_query_shortgi(struct ieee80211_hw *hw,
635 struct ieee80211_sta *sta,
636 struct rtl_tcb_desc *tcb_desc,
637 struct ieee80211_tx_info *info)
639 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
640 u8 rate_flag = info->control.rates[0].flags;
641 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
642 u8 sgi_80 = 0, bw_80 = 0;
643 tcb_desc->use_shortgi = false;
648 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
649 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
650 sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
652 if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
655 if (!sgi_40 && !sgi_20)
658 if (mac->opmode == NL80211_IFTYPE_STATION) {
661 } else if (mac->opmode == NL80211_IFTYPE_AP ||
662 mac->opmode == NL80211_IFTYPE_ADHOC ||
663 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
664 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
665 bw_80 = sta->vht_cap.vht_supported;
670 tcb_desc->use_shortgi = true;
672 tcb_desc->use_shortgi = false;
675 tcb_desc->use_shortgi = true;
676 else if (!bw_40 && sgi_20)
677 tcb_desc->use_shortgi = true;
680 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
681 tcb_desc->use_shortgi = false;
684 static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
685 struct rtl_tcb_desc *tcb_desc,
686 struct ieee80211_tx_info *info)
688 struct rtl_priv *rtlpriv = rtl_priv(hw);
689 u8 rate_flag = info->control.rates[0].flags;
691 /* Common Settings */
692 tcb_desc->rts_stbc = false;
693 tcb_desc->cts_enable = false;
694 tcb_desc->rts_sc = 0;
695 tcb_desc->rts_bw = false;
696 tcb_desc->rts_use_shortpreamble = false;
697 tcb_desc->rts_use_shortgi = false;
699 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
700 /* Use CTS-to-SELF in protection mode. */
701 tcb_desc->rts_enable = true;
702 tcb_desc->cts_enable = true;
703 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
704 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
705 /* Use RTS-CTS in protection mode. */
706 tcb_desc->rts_enable = true;
707 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
711 u8 rtl_mrate_idx_to_arfr_id(struct ieee80211_hw *hw, u8 rate_index,
712 enum wireless_mode wirelessmode)
714 struct rtl_priv *rtlpriv = rtl_priv(hw);
715 struct rtl_phy *rtlphy = &rtlpriv->phy;
718 switch (rate_index) {
719 case RATR_INX_WIRELESS_NGB:
720 if (rtlphy->rf_type == RF_1T1R)
721 ret = RATEID_IDX_BGN_40M_1SS;
723 ret = RATEID_IDX_BGN_40M_2SS;
725 case RATR_INX_WIRELESS_N:
726 case RATR_INX_WIRELESS_NG:
727 if (rtlphy->rf_type == RF_1T1R)
728 ret = RATEID_IDX_GN_N1SS;
730 ret = RATEID_IDX_GN_N2SS;
732 case RATR_INX_WIRELESS_NB:
733 if (rtlphy->rf_type == RF_1T1R)
734 ret = RATEID_IDX_BGN_20M_1SS_BN;
736 ret = RATEID_IDX_BGN_20M_2SS_BN;
738 case RATR_INX_WIRELESS_GB:
741 case RATR_INX_WIRELESS_G:
744 case RATR_INX_WIRELESS_B:
747 case RATR_INX_WIRELESS_MC:
748 if (wirelessmode == WIRELESS_MODE_B ||
749 wirelessmode == WIRELESS_MODE_G ||
750 wirelessmode == WIRELESS_MODE_N_24G ||
751 wirelessmode == WIRELESS_MODE_AC_24G)
756 case RATR_INX_WIRELESS_AC_5N:
757 if (rtlphy->rf_type == RF_1T1R)
758 ret = RATEID_IDX_VHT_1SS;
760 ret = RATEID_IDX_VHT_2SS;
762 case RATR_INX_WIRELESS_AC_24N:
763 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
764 if (rtlphy->rf_type == RF_1T1R)
765 ret = RATEID_IDX_VHT_1SS;
767 ret = RATEID_IDX_VHT_2SS;
769 if (rtlphy->rf_type == RF_1T1R)
770 ret = RATEID_IDX_MIX1;
772 ret = RATEID_IDX_MIX2;
776 ret = RATEID_IDX_BGN_40M_2SS;
781 EXPORT_SYMBOL(rtl_mrate_idx_to_arfr_id);
783 static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
784 struct ieee80211_sta *sta,
785 struct rtl_tcb_desc *tcb_desc)
787 #define SET_RATE_ID(rate_id) \
788 ({typeof(rate_id) _id = rate_id; \
789 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
790 rtl_mrate_idx_to_arfr_id(hw, _id, \
791 (sta_entry ? sta_entry->wireless_mode : \
792 WIRELESS_MODE_G)) : \
795 struct rtl_priv *rtlpriv = rtl_priv(hw);
796 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
797 struct rtl_sta_info *sta_entry = NULL;
798 u8 ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC);
801 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
802 ratr_index = sta_entry->ratr_index;
804 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
805 if (mac->opmode == NL80211_IFTYPE_STATION) {
806 tcb_desc->ratr_index = 0;
807 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
808 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
809 if (tcb_desc->multicast || tcb_desc->broadcast) {
811 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
812 tcb_desc->use_driver_rate = 1;
813 tcb_desc->ratr_index =
814 SET_RATE_ID(RATR_INX_WIRELESS_MC);
816 tcb_desc->ratr_index = ratr_index;
818 } else if (mac->opmode == NL80211_IFTYPE_AP) {
819 tcb_desc->ratr_index = ratr_index;
823 if (rtlpriv->dm.useramask) {
824 tcb_desc->ratr_index = ratr_index;
825 /* TODO we will differentiate adhoc and station future */
826 if (mac->opmode == NL80211_IFTYPE_STATION ||
827 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
828 tcb_desc->mac_id = 0;
831 (rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID))
832 ; /* use sta_entry->ratr_index */
833 else if (mac->mode == WIRELESS_MODE_AC_5G)
834 tcb_desc->ratr_index =
835 SET_RATE_ID(RATR_INX_WIRELESS_AC_5N);
836 else if (mac->mode == WIRELESS_MODE_AC_24G)
837 tcb_desc->ratr_index =
838 SET_RATE_ID(RATR_INX_WIRELESS_AC_24N);
839 else if (mac->mode == WIRELESS_MODE_N_24G)
840 tcb_desc->ratr_index =
841 SET_RATE_ID(RATR_INX_WIRELESS_NGB);
842 else if (mac->mode == WIRELESS_MODE_N_5G)
843 tcb_desc->ratr_index =
844 SET_RATE_ID(RATR_INX_WIRELESS_NG);
845 else if (mac->mode & WIRELESS_MODE_G)
846 tcb_desc->ratr_index =
847 SET_RATE_ID(RATR_INX_WIRELESS_GB);
848 else if (mac->mode & WIRELESS_MODE_B)
849 tcb_desc->ratr_index =
850 SET_RATE_ID(RATR_INX_WIRELESS_B);
851 else if (mac->mode & WIRELESS_MODE_A)
852 tcb_desc->ratr_index =
853 SET_RATE_ID(RATR_INX_WIRELESS_G);
855 } else if (mac->opmode == NL80211_IFTYPE_AP ||
856 mac->opmode == NL80211_IFTYPE_ADHOC) {
859 tcb_desc->mac_id = sta->aid + 1;
861 tcb_desc->mac_id = 1;
863 tcb_desc->mac_id = 0;
870 static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
871 struct ieee80211_sta *sta,
872 struct rtl_tcb_desc *tcb_desc)
874 struct rtl_priv *rtlpriv = rtl_priv(hw);
875 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
877 tcb_desc->packet_bw = false;
880 if (mac->opmode == NL80211_IFTYPE_AP ||
881 mac->opmode == NL80211_IFTYPE_ADHOC ||
882 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
883 if (!(sta->ht_cap.ht_supported) ||
884 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
886 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
887 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
890 if (tcb_desc->multicast || tcb_desc->broadcast)
893 /*use legency rate, shall use 20MHz */
894 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
897 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
899 if (rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT) {
900 if (mac->opmode == NL80211_IFTYPE_AP ||
901 mac->opmode == NL80211_IFTYPE_ADHOC ||
902 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
903 if (!(sta->vht_cap.vht_supported))
905 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
907 !(sta->vht_cap.vht_supported))
910 if (tcb_desc->hw_rate <=
911 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
913 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
917 static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
918 struct ieee80211_sta *sta)
920 struct rtl_priv *rtlpriv = rtl_priv(hw);
921 struct rtl_phy *rtlphy = &(rtlpriv->phy);
923 u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
925 if ((get_rf_type(rtlphy) == RF_2T2R) &&
926 (tx_mcs_map & 0x000c) != 0x000c) {
927 if ((tx_mcs_map & 0x000c) >> 2 ==
928 IEEE80211_VHT_MCS_SUPPORT_0_7)
930 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
931 else if ((tx_mcs_map & 0x000c) >> 2 ==
932 IEEE80211_VHT_MCS_SUPPORT_0_8)
934 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS8];
937 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
939 if ((tx_mcs_map & 0x0003) ==
940 IEEE80211_VHT_MCS_SUPPORT_0_7)
942 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
943 else if ((tx_mcs_map & 0x0003) ==
944 IEEE80211_VHT_MCS_SUPPORT_0_8)
946 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS8];
949 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
955 static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
956 struct ieee80211_sta *sta)
958 struct rtl_priv *rtlpriv = rtl_priv(hw);
959 struct rtl_phy *rtlphy = &rtlpriv->phy;
962 if (get_rf_type(rtlphy) == RF_2T2R &&
963 sta->ht_cap.mcs.rx_mask[1] != 0)
964 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
966 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
971 /* mac80211's rate_idx is like this:
973 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
976 * (rx_status->flag & RX_FLAG_HT) = 0,
977 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
980 * (rx_status->flag & RX_FLAG_HT) = 1,
981 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
983 * 5G band:rx_status->band == NL80211_BAND_5GHZ
985 * (rx_status->flag & RX_FLAG_HT) = 0,
986 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
989 * (rx_status->flag & RX_FLAG_HT) = 1,
990 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
993 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
994 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
996 int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
1002 switch (desc_rate) {
1003 case DESC_RATEVHT1SS_MCS0:
1006 case DESC_RATEVHT1SS_MCS1:
1009 case DESC_RATEVHT1SS_MCS2:
1012 case DESC_RATEVHT1SS_MCS3:
1015 case DESC_RATEVHT1SS_MCS4:
1018 case DESC_RATEVHT1SS_MCS5:
1021 case DESC_RATEVHT1SS_MCS6:
1024 case DESC_RATEVHT1SS_MCS7:
1027 case DESC_RATEVHT1SS_MCS8:
1030 case DESC_RATEVHT1SS_MCS9:
1033 case DESC_RATEVHT2SS_MCS0:
1036 case DESC_RATEVHT2SS_MCS1:
1039 case DESC_RATEVHT2SS_MCS2:
1042 case DESC_RATEVHT2SS_MCS3:
1045 case DESC_RATEVHT2SS_MCS4:
1048 case DESC_RATEVHT2SS_MCS5:
1051 case DESC_RATEVHT2SS_MCS6:
1054 case DESC_RATEVHT2SS_MCS7:
1057 case DESC_RATEVHT2SS_MCS8:
1060 case DESC_RATEVHT2SS_MCS9:
1069 if (false == isht) {
1070 if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
1071 switch (desc_rate) {
1113 switch (desc_rate) {
1144 switch (desc_rate) {
1175 case DESC_RATEMCS10:
1178 case DESC_RATEMCS11:
1181 case DESC_RATEMCS12:
1184 case DESC_RATEMCS13:
1187 case DESC_RATEMCS14:
1190 case DESC_RATEMCS15:
1200 EXPORT_SYMBOL(rtlwifi_rate_mapping);
1202 static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw,
1203 struct ieee80211_tx_info *info)
1205 struct rtl_priv *rtlpriv = rtl_priv(hw);
1206 struct ieee80211_tx_rate *r = &info->status.rates[0];
1207 struct ieee80211_rate *txrate;
1210 if (r->flags & IEEE80211_TX_RC_MCS) {
1212 hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 +
1214 } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) {
1215 /* VHT MCS0-9, NSS */
1216 if (ieee80211_rate_get_vht_nss(r) == 2)
1217 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
1219 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
1221 hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r);
1224 txrate = ieee80211_get_tx_rate(hw, info);
1227 hw_value = txrate->hw_value;
1231 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G &&
1232 hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M])
1233 hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M];
1238 void rtl_get_tcb_desc(struct ieee80211_hw *hw,
1239 struct ieee80211_tx_info *info,
1240 struct ieee80211_sta *sta,
1241 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
1243 #define SET_RATE_ID(rate_id) \
1244 ({typeof(rate_id) _id = rate_id; \
1245 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
1246 rtl_mrate_idx_to_arfr_id(hw, _id, \
1247 (sta_entry ? sta_entry->wireless_mode : \
1248 WIRELESS_MODE_G)) : \
1251 struct rtl_priv *rtlpriv = rtl_priv(hw);
1252 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
1253 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1254 struct rtl_sta_info *sta_entry =
1255 (sta ? (struct rtl_sta_info *)sta->drv_priv : NULL);
1257 __le16 fc = rtl_get_fc(skb);
1259 tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info);
1261 if (rtl_is_tx_report_skb(hw, skb))
1262 tcb_desc->use_spe_rpt = 1;
1264 if (ieee80211_is_data(fc)) {
1266 *we set data rate INX 0
1267 *in rtl_rc.c if skb is special data or
1268 *mgt which need low data rate.
1272 *So tcb_desc->hw_rate is just used for
1273 *special data and mgt frames
1275 if (info->control.rates[0].idx == 0 ||
1276 ieee80211_is_nullfunc(fc)) {
1277 tcb_desc->use_driver_rate = true;
1278 tcb_desc->ratr_index =
1279 SET_RATE_ID(RATR_INX_WIRELESS_MC);
1281 tcb_desc->disable_ratefallback = 1;
1284 *because hw will nerver use hw_rate
1285 *when tcb_desc->use_driver_rate = false
1286 *so we never set highest N rate here,
1287 *and N rate will all be controlled by FW
1288 *when tcb_desc->use_driver_rate = false
1290 if (sta && sta->vht_cap.vht_supported) {
1292 _rtl_get_vht_highest_n_rate(hw, sta);
1294 if (sta && sta->ht_cap.ht_supported) {
1296 _rtl_get_highest_n_rate(hw, sta);
1298 if (rtlmac->mode == WIRELESS_MODE_B) {
1300 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
1303 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
1309 if (is_multicast_ether_addr(hdr->addr1))
1310 tcb_desc->multicast = 1;
1311 else if (is_broadcast_ether_addr(hdr->addr1))
1312 tcb_desc->broadcast = 1;
1314 _rtl_txrate_selectmode(hw, sta, tcb_desc);
1315 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
1316 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
1317 _rtl_query_shortgi(hw, sta, tcb_desc, info);
1318 _rtl_query_protection_mode(hw, tcb_desc, info);
1320 tcb_desc->use_driver_rate = true;
1321 tcb_desc->ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC);
1322 tcb_desc->disable_ratefallback = 1;
1323 tcb_desc->mac_id = 0;
1324 tcb_desc->packet_bw = false;
1328 EXPORT_SYMBOL(rtl_get_tcb_desc);
1330 bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
1332 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1333 struct rtl_priv *rtlpriv = rtl_priv(hw);
1334 __le16 fc = rtl_get_fc(skb);
1336 if (rtlpriv->dm.supp_phymode_switch &&
1337 mac->link_state < MAC80211_LINKED &&
1338 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
1339 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1340 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1342 if (ieee80211_is_auth(fc)) {
1343 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
1345 mac->link_state = MAC80211_LINKING;
1347 rtlpriv->phy.need_iqk = true;
1353 EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
1355 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
1356 u8 *bssid, u16 tid);
1358 static void process_agg_start(struct ieee80211_hw *hw,
1359 struct ieee80211_hdr *hdr, u16 tid)
1361 struct rtl_priv *rtlpriv = rtl_priv(hw);
1362 struct ieee80211_rx_status rx_status = { 0 };
1363 struct sk_buff *skb_delba = NULL;
1365 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
1367 rx_status.freq = hw->conf.chandef.chan->center_freq;
1368 rx_status.band = hw->conf.chandef.chan->band;
1369 rx_status.flag |= RX_FLAG_DECRYPTED;
1370 rx_status.flag |= RX_FLAG_MACTIME_START;
1371 rx_status.rate_idx = 0;
1372 rx_status.signal = 50 + 10;
1373 memcpy(IEEE80211_SKB_RXCB(skb_delba),
1374 &rx_status, sizeof(rx_status));
1375 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1379 ieee80211_rx_irqsafe(hw, skb_delba);
1383 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1385 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1386 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1387 struct rtl_priv *rtlpriv = rtl_priv(hw);
1388 __le16 fc = rtl_get_fc(skb);
1389 u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
1392 if (!ieee80211_is_action(fc))
1401 if (mac->act_scanning)
1404 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1405 "%s ACT_ADDBAREQ From :%pM\n",
1406 is_tx ? "Tx" : "Rx", hdr->addr2);
1407 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
1408 skb->data, skb->len);
1410 struct ieee80211_sta *sta = NULL;
1411 struct rtl_sta_info *sta_entry = NULL;
1412 struct rtl_tid_data *tid_data;
1413 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1414 u16 capab = 0, tid = 0;
1417 sta = rtl_find_sta(hw, hdr->addr3);
1419 RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
1420 DBG_DMESG, "sta is NULL\n");
1426 (struct rtl_sta_info *)sta->drv_priv;
1432 le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1434 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1435 if (tid >= MAX_TID_COUNT) {
1439 tid_data = &sta_entry->tids[tid];
1440 if (tid_data->agg.rx_agg_state ==
1442 process_agg_start(hw, hdr, tid);
1447 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1448 "%s ACT_ADDBARSP From :%pM\n",
1449 is_tx ? "Tx" : "Rx", hdr->addr2);
1452 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1453 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
1463 EXPORT_SYMBOL_GPL(rtl_action_proc);
1465 static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
1468 struct ieee80211_hw *hw = rtlpriv->hw;
1470 rtlpriv->ra.is_special_data = true;
1471 if (rtlpriv->cfg->ops->get_btc_status())
1472 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
1475 ppsc->last_delaylps_stamp_jiffies = jiffies;
1478 static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
1479 struct sk_buff *skb, bool is_enc)
1481 struct rtl_priv *rtlpriv = rtl_priv(hw);
1482 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1483 u8 encrypt_header_len = 0;
1486 switch (rtlpriv->sec.pairwise_enc_algorithm) {
1487 case WEP40_ENCRYPTION:
1488 case WEP104_ENCRYPTION:
1489 encrypt_header_len = 4;/*WEP_IV_LEN*/
1491 case TKIP_ENCRYPTION:
1492 encrypt_header_len = 8;/*TKIP_IV_LEN*/
1494 case AESCCMP_ENCRYPTION:
1495 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
1501 offset = mac_hdr_len + SNAP_SIZE;
1503 offset += encrypt_header_len;
1505 return skb->data + offset;
1508 /*should call before software enc*/
1509 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
1512 struct rtl_priv *rtlpriv = rtl_priv(hw);
1513 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1514 __le16 fc = rtl_get_fc(skb);
1516 const u8 *ether_type_ptr;
1517 const struct iphdr *ip;
1519 if (!ieee80211_is_data(fc))
1522 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
1523 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1525 if (ETH_P_IP == ether_type) {
1526 ip = (struct iphdr *)((u8 *)ether_type_ptr +
1528 if (IPPROTO_UDP == ip->protocol) {
1529 struct udphdr *udp = (struct udphdr *)((u8 *)ip +
1531 if (((((u8 *)udp)[1] == 68) &&
1532 (((u8 *)udp)[3] == 67)) ||
1533 ((((u8 *)udp)[1] == 67) &&
1534 (((u8 *)udp)[3] == 68))) {
1535 /* 68 : UDP BOOTP client
1536 * 67 : UDP BOOTP server
1538 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
1539 DBG_DMESG, "dhcp %s !!\n",
1540 (is_tx) ? "Tx" : "Rx");
1543 setup_special_tx(rtlpriv, ppsc,
1549 } else if (ETH_P_ARP == ether_type) {
1551 setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
1554 } else if (ETH_P_PAE == ether_type) {
1555 /* EAPOL is seens as in-4way */
1556 rtlpriv->btcoexist.btc_info.in_4way = true;
1557 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1559 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1560 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
1563 rtlpriv->ra.is_special_data = true;
1565 ppsc->last_delaylps_stamp_jiffies = jiffies;
1567 setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
1571 } else if (ETH_P_IPV6 == ether_type) {
1572 /* TODO: Handle any IPv6 cases that need special handling.
1573 * For now, always return false
1579 rtlpriv->ra.is_special_data = false;
1582 EXPORT_SYMBOL_GPL(rtl_is_special_data);
1584 void rtl_tx_ackqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
1586 struct rtl_priv *rtlpriv = rtl_priv(hw);
1587 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1589 __skb_queue_tail(&tx_report->queue, skb);
1591 EXPORT_SYMBOL_GPL(rtl_tx_ackqueue);
1593 static void rtl_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1596 struct rtl_priv *rtlpriv = rtl_priv(hw);
1597 struct ieee80211_tx_info *info;
1599 info = IEEE80211_SKB_CB(skb);
1600 ieee80211_tx_info_clear_status(info);
1602 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_LOUD,
1603 "tx report: ack\n");
1604 info->flags |= IEEE80211_TX_STAT_ACK;
1606 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_LOUD,
1607 "tx report: not ack\n");
1608 info->flags &= ~IEEE80211_TX_STAT_ACK;
1610 ieee80211_tx_status_irqsafe(hw, skb);
1613 bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
1616 const u8 *ether_type_ptr;
1617 __le16 fc = rtl_get_fc(skb);
1619 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
1620 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1622 if (ether_type == ETH_P_PAE || ieee80211_is_nullfunc(fc))
1628 static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw,
1629 struct rtlwifi_tx_info *tx_info)
1631 struct rtl_priv *rtlpriv = rtl_priv(hw);
1632 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1635 /* SW_DEFINE[11:8] are reserved (driver fills zeros)
1636 * SW_DEFINE[7:2] are used by driver
1637 * SW_DEFINE[1:0] are reserved for firmware (driver fills zeros)
1639 sn = (atomic_inc_return(&tx_report->sn) & 0x003F) << 2;
1641 tx_report->last_sent_sn = sn;
1642 tx_report->last_sent_time = jiffies;
1644 tx_info->send_time = tx_report->last_sent_time;
1645 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1646 "Send TX-Report sn=0x%X\n", sn);
1651 void rtl_set_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
1652 struct ieee80211_hw *hw, struct rtlwifi_tx_info *tx_info)
1654 if (ptcb_desc->use_spe_rpt) {
1655 u16 sn = rtl_get_tx_report_sn(hw, tx_info);
1657 SET_TX_DESC_SPE_RPT(pdesc, 1);
1658 SET_TX_DESC_SW_DEFINE(pdesc, sn);
1661 EXPORT_SYMBOL_GPL(rtl_set_tx_report);
1663 void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
1665 struct rtl_priv *rtlpriv = rtl_priv(hw);
1666 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1667 struct rtlwifi_tx_info *tx_info;
1668 struct sk_buff_head *queue = &tx_report->queue;
1669 struct sk_buff *skb;
1673 if (rtlpriv->cfg->spec_ver & RTL_SPEC_EXT_C2H) {
1674 sn = GET_TX_REPORT_SN_V2(tmp_buf);
1675 st = GET_TX_REPORT_ST_V2(tmp_buf);
1676 retry = GET_TX_REPORT_RETRY_V2(tmp_buf);
1678 sn = GET_TX_REPORT_SN_V1(tmp_buf);
1679 st = GET_TX_REPORT_ST_V1(tmp_buf);
1680 retry = GET_TX_REPORT_RETRY_V1(tmp_buf);
1683 tx_report->last_recv_sn = sn;
1685 skb_queue_walk(queue, skb) {
1686 tx_info = rtl_tx_skb_cb_info(skb);
1687 if (tx_info->sn == sn) {
1688 skb_unlink(skb, queue);
1689 rtl_tx_status(hw, skb, st == 0);
1693 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1694 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
1697 EXPORT_SYMBOL_GPL(rtl_tx_report_handler);
1699 bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
1701 struct rtl_priv *rtlpriv = rtl_priv(hw);
1702 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1704 if (tx_report->last_sent_sn == tx_report->last_recv_sn)
1707 if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
1708 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
1709 "Check TX-Report timeout!! s_sn=0x%X r_sn=0x%X\n",
1710 tx_report->last_sent_sn, tx_report->last_recv_sn);
1711 return true; /* 3 sec. (timeout) seen as acked */
1717 void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
1719 struct rtl_priv *rtlpriv = rtl_priv(hw);
1722 for (i = 0; i < wait_ms; i++) {
1723 if (rtl_check_tx_report_acked(hw))
1725 usleep_range(1000, 2000);
1726 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1727 "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
1731 u32 rtl_get_hal_edca_param(struct ieee80211_hw *hw,
1732 struct ieee80211_vif *vif,
1733 enum wireless_mode wirelessmode,
1734 struct ieee80211_tx_queue_params *param)
1740 /* AIFS = AIFSN * slot time + SIFS */
1741 switch (wirelessmode) {
1742 case WIRELESS_MODE_A:
1743 case WIRELESS_MODE_N_24G:
1744 case WIRELESS_MODE_N_5G:
1745 case WIRELESS_MODE_AC_5G:
1746 case WIRELESS_MODE_AC_24G:
1750 case WIRELESS_MODE_G:
1751 slottime = (vif->bss_conf.use_short_slot ? 9 : 20);
1757 reg |= (param->txop & 0x7FF) << 16;
1758 reg |= (fls(param->cw_max) & 0xF) << 12;
1759 reg |= (fls(param->cw_min) & 0xF) << 8;
1760 reg |= (param->aifs & 0x0F) * slottime + sifstime;
1764 EXPORT_SYMBOL_GPL(rtl_get_hal_edca_param);
1766 /*********************************************************
1768 * functions called by core.c
1770 *********************************************************/
1771 int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1772 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1774 struct rtl_priv *rtlpriv = rtl_priv(hw);
1775 struct rtl_tid_data *tid_data;
1776 struct rtl_sta_info *sta_entry = NULL;
1781 if (unlikely(tid >= MAX_TID_COUNT))
1784 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1787 tid_data = &sta_entry->tids[tid];
1789 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1790 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1793 tid_data->agg.agg_state = RTL_AGG_START;
1795 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1799 int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1800 struct ieee80211_sta *sta, u16 tid)
1802 struct rtl_priv *rtlpriv = rtl_priv(hw);
1803 struct rtl_sta_info *sta_entry = NULL;
1808 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1809 "on ra = %pM tid = %d\n", sta->addr, tid);
1811 if (unlikely(tid >= MAX_TID_COUNT))
1814 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1815 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
1817 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1821 int rtl_rx_agg_start(struct ieee80211_hw *hw,
1822 struct ieee80211_sta *sta, u16 tid)
1824 struct rtl_priv *rtlpriv = rtl_priv(hw);
1825 struct rtl_tid_data *tid_data;
1826 struct rtl_sta_info *sta_entry = NULL;
1832 if (unlikely(tid >= MAX_TID_COUNT))
1835 if (rtlpriv->cfg->ops->get_btc_status()) {
1836 rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
1843 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1846 tid_data = &sta_entry->tids[tid];
1848 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1849 "on ra = %pM tid = %d\n", sta->addr, tid);
1851 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1855 int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1856 struct ieee80211_sta *sta, u16 tid)
1858 struct rtl_priv *rtlpriv = rtl_priv(hw);
1859 struct rtl_sta_info *sta_entry = NULL;
1864 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1865 "on ra = %pM tid = %d\n", sta->addr, tid);
1867 if (unlikely(tid >= MAX_TID_COUNT))
1870 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1871 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1875 int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1876 struct ieee80211_sta *sta, u16 tid)
1878 struct rtl_priv *rtlpriv = rtl_priv(hw);
1879 struct rtl_sta_info *sta_entry = NULL;
1884 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1885 "on ra = %pM tid = %d\n", sta->addr, tid);
1887 if (unlikely(tid >= MAX_TID_COUNT))
1890 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1891 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
1896 void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
1898 struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
1899 u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0;
1901 if (rtlpriv->cfg->ops->get_btc_status())
1902 btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
1903 &ctrl_agg_size, &agg_size);
1905 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
1906 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
1907 reject_agg, ctrl_agg_size, agg_size);
1909 rtlpriv->hw->max_rx_aggregation_subframes =
1910 (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF);
1912 EXPORT_SYMBOL(rtl_rx_ampdu_apply);
1914 /*********************************************************
1916 * wq & timer callback functions
1918 *********************************************************/
1919 /* this function is used for roaming */
1920 void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1922 struct rtl_priv *rtlpriv = rtl_priv(hw);
1923 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1925 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1928 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1931 /* check if this really is a beacon */
1932 if (!ieee80211_is_beacon(hdr->frame_control) &&
1933 !ieee80211_is_probe_resp(hdr->frame_control))
1936 /* min. beacon length + FCS_LEN */
1937 if (skb->len <= 40 + FCS_LEN)
1940 /* and only beacons from the associated BSSID, please */
1941 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
1944 rtlpriv->link_info.bcn_rx_inperiod++;
1946 EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
1948 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
1950 struct rtl_priv *rtlpriv = rtl_priv(hw);
1951 struct rtl_bssid_entry *entry, *next;
1953 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1954 list_del(&entry->list);
1956 rtlpriv->scan_list.num--;
1960 static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw,
1963 struct rtl_priv *rtlpriv = rtl_priv(hw);
1964 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1965 struct sk_buff_head *queue = &tx_report->queue;
1966 struct sk_buff *skb, *tmp;
1967 struct rtlwifi_tx_info *tx_info;
1969 skb_queue_walk_safe(queue, skb, tmp) {
1970 tx_info = rtl_tx_skb_cb_info(skb);
1972 time_after(tx_info->send_time + HZ, jiffies))
1974 skb_unlink(skb, queue);
1975 rtl_tx_status(hw, skb, false);
1979 void rtl_scan_list_expire(struct ieee80211_hw *hw)
1981 struct rtl_priv *rtlpriv = rtl_priv(hw);
1982 struct rtl_bssid_entry *entry, *next;
1983 unsigned long flags;
1985 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1987 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1989 if (jiffies_to_msecs(jiffies - entry->age) < 180000)
1992 list_del(&entry->list);
1993 rtlpriv->scan_list.num--;
1995 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1996 "BSSID=%pM is expire in scan list (total=%d)\n",
1997 entry->bssid, rtlpriv->scan_list.num);
2001 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
2003 rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
2006 void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
2008 struct rtl_priv *rtlpriv = rtl_priv(hw);
2009 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2010 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2011 unsigned long flags;
2013 struct rtl_bssid_entry *entry;
2014 bool entry_found = false;
2016 /* check if it is scanning */
2017 if (!mac->act_scanning)
2020 /* check if this really is a beacon */
2021 if (!ieee80211_is_beacon(hdr->frame_control) &&
2022 !ieee80211_is_probe_resp(hdr->frame_control))
2025 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
2027 list_for_each_entry(entry, &rtlpriv->scan_list.list, list) {
2028 if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) {
2029 list_del_init(&entry->list);
2031 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
2032 "Update BSSID=%pM to scan list (total=%d)\n",
2033 hdr->addr3, rtlpriv->scan_list.num);
2039 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
2044 memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
2045 rtlpriv->scan_list.num++;
2047 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
2048 "Add BSSID=%pM to scan list (total=%d)\n",
2049 hdr->addr3, rtlpriv->scan_list.num);
2052 entry->age = jiffies;
2054 list_add_tail(&entry->list, &rtlpriv->scan_list.list);
2057 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
2059 EXPORT_SYMBOL(rtl_collect_scan_list);
2061 void rtl_watchdog_wq_callback(void *data)
2063 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
2066 struct ieee80211_hw *hw = rtlworks->hw;
2067 struct rtl_priv *rtlpriv = rtl_priv(hw);
2068 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2069 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2070 bool busytraffic = false;
2071 bool tx_busy_traffic = false;
2072 bool rx_busy_traffic = false;
2073 bool higher_busytraffic = false;
2074 bool higher_busyrxtraffic = false;
2076 u32 rx_cnt_inp4eriod = 0;
2077 u32 tx_cnt_inp4eriod = 0;
2078 u32 aver_rx_cnt_inperiod = 0;
2079 u32 aver_tx_cnt_inperiod = 0;
2080 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
2081 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
2083 if (is_hal_stop(rtlhal))
2086 /* <1> Determine if action frame is allowed */
2087 if (mac->link_state > MAC80211_NOLINK) {
2088 if (mac->cnt_after_linked < 20)
2089 mac->cnt_after_linked++;
2091 mac->cnt_after_linked = 0;
2094 /* <2> to check if traffic busy, if
2095 * busytraffic we don't change channel
2097 if (mac->link_state >= MAC80211_LINKED) {
2099 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
2100 for (idx = 0; idx <= 2; idx++) {
2101 rtlpriv->link_info.num_rx_in4period[idx] =
2102 rtlpriv->link_info.num_rx_in4period[idx + 1];
2103 rtlpriv->link_info.num_tx_in4period[idx] =
2104 rtlpriv->link_info.num_tx_in4period[idx + 1];
2106 rtlpriv->link_info.num_rx_in4period[3] =
2107 rtlpriv->link_info.num_rx_inperiod;
2108 rtlpriv->link_info.num_tx_in4period[3] =
2109 rtlpriv->link_info.num_tx_inperiod;
2110 for (idx = 0; idx <= 3; idx++) {
2112 rtlpriv->link_info.num_rx_in4period[idx];
2114 rtlpriv->link_info.num_tx_in4period[idx];
2116 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
2117 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
2119 /* (2) check traffic busy */
2120 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
2122 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
2123 rx_busy_traffic = true;
2125 tx_busy_traffic = false;
2128 /* Higher Tx/Rx data. */
2129 if (aver_rx_cnt_inperiod > 4000 ||
2130 aver_tx_cnt_inperiod > 4000) {
2131 higher_busytraffic = true;
2133 /* Extremely high Rx data. */
2134 if (aver_rx_cnt_inperiod > 5000)
2135 higher_busyrxtraffic = true;
2138 /* check every tid's tx traffic */
2139 for (tid = 0; tid <= 7; tid++) {
2140 for (idx = 0; idx <= 2; idx++)
2141 rtlpriv->link_info.tidtx_in4period[tid][idx] =
2142 rtlpriv->link_info.tidtx_in4period[tid]
2144 rtlpriv->link_info.tidtx_in4period[tid][3] =
2145 rtlpriv->link_info.tidtx_inperiod[tid];
2147 for (idx = 0; idx <= 3; idx++)
2148 tidtx_inp4eriod[tid] +=
2149 rtlpriv->link_info.tidtx_in4period[tid][idx];
2150 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
2151 if (aver_tidtx_inperiod[tid] > 5000)
2152 rtlpriv->link_info.higher_busytxtraffic[tid] =
2155 rtlpriv->link_info.higher_busytxtraffic[tid] =
2159 /* PS is controlled by coex. */
2160 if (rtlpriv->cfg->ops->get_btc_status() &&
2161 rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
2162 goto label_lps_done;
2164 if (rtlpriv->link_info.num_rx_inperiod +
2165 rtlpriv->link_info.num_tx_inperiod > 8 ||
2166 rtlpriv->link_info.num_rx_inperiod > 2)
2175 rtlpriv->link_info.num_rx_inperiod = 0;
2176 rtlpriv->link_info.num_tx_inperiod = 0;
2177 for (tid = 0; tid <= 7; tid++)
2178 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
2180 rtlpriv->link_info.busytraffic = busytraffic;
2181 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
2182 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
2183 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
2184 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
2186 rtlpriv->stats.txbytesunicast_inperiod =
2187 rtlpriv->stats.txbytesunicast -
2188 rtlpriv->stats.txbytesunicast_last;
2189 rtlpriv->stats.rxbytesunicast_inperiod =
2190 rtlpriv->stats.rxbytesunicast -
2191 rtlpriv->stats.rxbytesunicast_last;
2192 rtlpriv->stats.txbytesunicast_last = rtlpriv->stats.txbytesunicast;
2193 rtlpriv->stats.rxbytesunicast_last = rtlpriv->stats.rxbytesunicast;
2195 rtlpriv->stats.txbytesunicast_inperiod_tp =
2196 (u32)(rtlpriv->stats.txbytesunicast_inperiod * 8 / 2 /
2198 rtlpriv->stats.rxbytesunicast_inperiod_tp =
2199 (u32)(rtlpriv->stats.rxbytesunicast_inperiod * 8 / 2 /
2203 if (!rtlpriv->cfg->mod_params->disable_watchdog)
2204 rtlpriv->cfg->ops->dm_watchdog(hw);
2207 if (mac->link_state == MAC80211_LINKED &&
2208 mac->opmode == NL80211_IFTYPE_STATION) {
2209 if ((rtlpriv->link_info.bcn_rx_inperiod +
2210 rtlpriv->link_info.num_rx_inperiod) == 0) {
2211 rtlpriv->link_info.roam_times++;
2212 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
2213 "AP off for %d s\n",
2214 (rtlpriv->link_info.roam_times * 2));
2216 /* if we can't recv beacon for 10s,
2217 * we should reconnect this AP
2219 if (rtlpriv->link_info.roam_times >= 5) {
2220 pr_err("AP off, try to reconnect now\n");
2221 rtlpriv->link_info.roam_times = 0;
2222 ieee80211_connection_loss(
2223 rtlpriv->mac80211.vif);
2226 rtlpriv->link_info.roam_times = 0;
2230 if (rtlpriv->cfg->ops->get_btc_status())
2231 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
2233 if (rtlpriv->btcoexist.btc_info.in_4way) {
2234 if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
2235 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
2236 rtlpriv->btcoexist.btc_info.in_4way = false;
2239 rtlpriv->link_info.bcn_rx_inperiod = 0;
2242 rtl_scan_list_expire(hw);
2244 /* <7> check ack queue */
2245 rtl_free_entries_from_ack_queue(hw, true);
2248 void rtl_watch_dog_timer_callback(struct timer_list *t)
2250 struct rtl_priv *rtlpriv = from_timer(rtlpriv, t, works.watchdog_timer);
2252 queue_delayed_work(rtlpriv->works.rtl_wq,
2253 &rtlpriv->works.watchdog_wq, 0);
2255 mod_timer(&rtlpriv->works.watchdog_timer,
2256 jiffies + MSECS(RTL_WATCH_DOG_TIME));
2258 void rtl_fwevt_wq_callback(void *data)
2260 struct rtl_works *rtlworks =
2261 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
2262 struct ieee80211_hw *hw = rtlworks->hw;
2263 struct rtl_priv *rtlpriv = rtl_priv(hw);
2265 rtlpriv->cfg->ops->c2h_command_handle(hw);
2268 static void rtl_c2h_content_parsing(struct ieee80211_hw *hw,
2269 struct sk_buff *skb);
2271 static bool rtl_c2h_fast_cmd(struct ieee80211_hw *hw, struct sk_buff *skb)
2273 u8 cmd_id = GET_C2H_CMD_ID(skb->data);
2285 void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
2287 struct rtl_priv *rtlpriv = rtl_priv(hw);
2288 unsigned long flags;
2290 if (rtl_c2h_fast_cmd(hw, skb)) {
2291 rtl_c2h_content_parsing(hw, skb);
2296 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2298 __skb_queue_tail(&rtlpriv->c2hcmd_queue, skb);
2300 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2303 queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
2305 EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
2307 static void rtl_c2h_content_parsing(struct ieee80211_hw *hw,
2308 struct sk_buff *skb)
2310 struct rtl_priv *rtlpriv = rtl_priv(hw);
2311 struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops;
2312 const struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
2313 u8 cmd_id, cmd_seq, cmd_len;
2316 cmd_id = GET_C2H_CMD_ID(skb->data);
2317 cmd_seq = GET_C2H_SEQ(skb->data);
2318 cmd_len = skb->len - C2H_DATA_OFFSET;
2319 cmd_buf = GET_C2H_DATA_PTR(skb->data);
2323 RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "[C2H], C2H_DBG!!\n");
2326 RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
2327 "[C2H], C2H_TXBF!!\n");
2330 rtl_tx_report_handler(hw, cmd_buf, cmd_len);
2333 if (hal_ops->c2h_ra_report_handler)
2334 hal_ops->c2h_ra_report_handler(hw, cmd_buf, cmd_len);
2337 RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
2338 "[C2H], C2H_BT_INFO!!\n");
2339 if (rtlpriv->cfg->ops->get_btc_status())
2340 btc_ops->btc_btinfo_notify(rtlpriv, cmd_buf, cmd_len);
2343 RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
2344 "[C2H], C2H_BT_MP!!\n");
2345 if (rtlpriv->cfg->ops->get_btc_status())
2346 btc_ops->btc_btmpinfo_notify(rtlpriv, cmd_buf, cmd_len);
2349 RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
2350 "[C2H], Unknown packet!! cmd_id(%#X)!\n", cmd_id);
2355 void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
2357 struct rtl_priv *rtlpriv = rtl_priv(hw);
2358 struct sk_buff *skb;
2359 unsigned long flags;
2362 for (i = 0; i < 200; i++) {
2363 /* dequeue a task */
2364 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2366 skb = __skb_dequeue(&rtlpriv->c2hcmd_queue);
2368 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2374 RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG, "C2H rx_desc_shift=%d\n",
2376 RT_PRINT_DATA(rtlpriv, COMP_FW, DBG_DMESG,
2377 "C2H data: ", skb->data, skb->len);
2380 rtl_c2h_content_parsing(hw, skb);
2383 dev_kfree_skb_any(skb);
2387 void rtl_c2hcmd_wq_callback(void *data)
2389 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
2392 struct ieee80211_hw *hw = rtlworks->hw;
2394 rtl_c2hcmd_launcher(hw, 1);
2397 void rtl_easy_concurrent_retrytimer_callback(struct timer_list *t)
2399 struct rtl_priv *rtlpriv =
2400 from_timer(rtlpriv, t, works.dualmac_easyconcurrent_retrytimer);
2401 struct ieee80211_hw *hw = rtlpriv->hw;
2402 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
2404 if (buddy_priv == NULL)
2407 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
2409 /*********************************************************
2411 * frame process functions
2413 *********************************************************/
2414 u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
2416 struct ieee80211_mgmt *mgmt = (void *)data;
2419 pos = (u8 *)mgmt->u.beacon.variable;
2422 if (pos + 2 + pos[1] > end)
2433 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
2434 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
2435 static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
2436 enum ieee80211_smps_mode smps,
2439 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2440 struct sk_buff *skb;
2441 struct ieee80211_mgmt *action_frame;
2443 /* 27 = header + category + action + smps mode */
2444 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
2448 skb_reserve(skb, hw->extra_tx_headroom);
2449 action_frame = skb_put_zero(skb, 27);
2450 memcpy(action_frame->da, da, ETH_ALEN);
2451 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
2452 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2453 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2454 IEEE80211_STYPE_ACTION);
2455 action_frame->u.action.category = WLAN_CATEGORY_HT;
2456 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
2458 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
2459 case IEEE80211_SMPS_NUM_MODES:/* 4 */
2462 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
2463 action_frame->u.action.u.ht_smps.smps_control =
2464 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
2466 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
2467 action_frame->u.action.u.ht_smps.smps_control =
2468 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
2470 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
2471 action_frame->u.action.u.ht_smps.smps_control =
2472 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
2479 int rtl_send_smps_action(struct ieee80211_hw *hw,
2480 struct ieee80211_sta *sta,
2481 enum ieee80211_smps_mode smps)
2483 struct rtl_priv *rtlpriv = rtl_priv(hw);
2484 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2485 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
2486 struct sk_buff *skb = NULL;
2487 struct rtl_tcb_desc tcb_desc;
2488 u8 bssid[ETH_ALEN] = {0};
2490 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
2492 if (rtlpriv->mac80211.act_scanning)
2498 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
2501 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
2504 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
2505 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
2507 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
2509 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
2510 /* this is a type = mgmt * stype = action frame */
2512 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2513 struct rtl_sta_info *sta_entry =
2514 (struct rtl_sta_info *) sta->drv_priv;
2515 sta_entry->mimo_ps = smps;
2516 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */
2518 info->control.rates[0].idx = 0;
2519 info->band = hw->conf.chandef.chan->band;
2520 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
2527 EXPORT_SYMBOL(rtl_send_smps_action);
2529 void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
2531 struct rtl_priv *rtlpriv = rtl_priv(hw);
2532 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2533 enum io_type iotype;
2535 if (!is_hal_stop(rtlhal)) {
2536 switch (operation) {
2537 case SCAN_OPT_BACKUP:
2538 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
2539 rtlpriv->cfg->ops->set_hw_reg(hw,
2543 case SCAN_OPT_RESTORE:
2544 iotype = IO_CMD_RESUME_DM_BY_SCAN;
2545 rtlpriv->cfg->ops->set_hw_reg(hw,
2550 pr_err("Unknown Scan Backup operation.\n");
2555 EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
2557 /* because mac80211 have issues when can receive del ba
2558 * so here we just make a fake del_ba if we receive a ba_req
2559 * but rx_agg was opened to let mac80211 release some ba
2560 * related resources, so please this del_ba for tx
2562 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
2563 u8 *sa, u8 *bssid, u16 tid)
2565 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2566 struct sk_buff *skb;
2567 struct ieee80211_mgmt *action_frame;
2570 /* 27 = header + category + action + smps mode */
2571 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
2575 skb_reserve(skb, hw->extra_tx_headroom);
2576 action_frame = skb_put_zero(skb, 34);
2577 memcpy(action_frame->sa, sa, ETH_ALEN);
2578 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
2579 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2580 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2581 IEEE80211_STYPE_ACTION);
2582 action_frame->u.action.category = WLAN_CATEGORY_BACK;
2583 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
2584 params = (u16)(1 << 11); /* bit 11 initiator */
2585 params |= (u16)(tid << 12); /* bit 15:12 TID number */
2587 action_frame->u.action.u.delba.params = cpu_to_le16(params);
2588 action_frame->u.action.u.delba.reason_code =
2589 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
2594 /*********************************************************
2598 *********************************************************/
2599 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
2600 struct octet_string vendor_ie)
2602 struct rtl_priv *rtlpriv = rtl_priv(hw);
2603 bool matched = false;
2604 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
2605 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
2606 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
2607 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
2608 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
2609 static u8 racap[] = { 0x00, 0x0c, 0x43 };
2610 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
2611 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
2613 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
2614 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
2615 rtlpriv->mac80211.vendor = PEER_ATH;
2617 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
2618 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
2619 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
2620 rtlpriv->mac80211.vendor = PEER_BROAD;
2622 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
2623 rtlpriv->mac80211.vendor = PEER_RAL;
2625 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
2626 rtlpriv->mac80211.vendor = PEER_CISCO;
2628 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
2629 rtlpriv->mac80211.vendor = PEER_MARV;
2636 static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
2639 struct ieee80211_mgmt *mgmt = (void *)data;
2640 struct octet_string vendor_ie;
2643 pos = (u8 *)mgmt->u.beacon.variable;
2646 if (pos[0] == 221) {
2647 vendor_ie.length = pos[1];
2648 vendor_ie.octet = &pos[2];
2649 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
2653 if (pos + 2 + pos[1] > end)
2661 void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
2663 struct rtl_priv *rtlpriv = rtl_priv(hw);
2664 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2665 struct ieee80211_hdr *hdr = (void *)data;
2666 u32 vendor = PEER_UNKNOWN;
2668 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
2669 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
2670 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
2671 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
2672 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
2673 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
2674 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
2675 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
2676 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
2677 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
2678 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
2679 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
2680 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
2681 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
2682 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
2683 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
2685 if (mac->opmode != NL80211_IFTYPE_STATION)
2688 if (mac->link_state == MAC80211_NOLINK) {
2689 mac->vendor = PEER_UNKNOWN;
2693 if (mac->cnt_after_linked > 2)
2696 /* check if this really is a beacon */
2697 if (!ieee80211_is_beacon(hdr->frame_control))
2700 /* min. beacon length + FCS_LEN */
2701 if (len <= 40 + FCS_LEN)
2704 /* and only beacons from the associated BSSID, please */
2705 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
2708 if (rtl_find_221_ie(hw, data, len))
2709 vendor = mac->vendor;
2711 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
2712 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
2713 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
2714 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
2715 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
2716 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
2717 vendor == PEER_ATH) {
2719 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
2720 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
2721 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
2722 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
2723 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
2724 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
2725 vendor == PEER_RAL) {
2726 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
2728 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
2729 vendor == PEER_CISCO) {
2730 vendor = PEER_CISCO;
2731 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
2732 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
2733 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
2734 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
2735 vendor == PEER_BROAD) {
2736 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
2737 vendor = PEER_BROAD;
2738 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
2739 vendor == PEER_MARV) {
2741 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
2744 mac->vendor = vendor;
2746 EXPORT_SYMBOL_GPL(rtl_recognize_peer);
2748 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2749 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2750 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2751 MODULE_LICENSE("GPL");
2752 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2754 struct rtl_global_var rtl_global_var = {};
2755 EXPORT_SYMBOL_GPL(rtl_global_var);
2757 static int __init rtl_core_module_init(void)
2759 BUILD_BUG_ON(TX_PWR_BY_RATE_NUM_RATE < TX_PWR_BY_RATE_NUM_SECTION);
2760 BUILD_BUG_ON(MAX_RATE_SECTION_NUM != MAX_RATE_SECTION);
2761 BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_24G != MAX_RATE_SECTION);
2762 BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_5G != (MAX_RATE_SECTION - 1));
2764 if (rtl_rate_control_register())
2765 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
2768 rtl_debugfs_add_topdir();
2770 /* init some global vars */
2771 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2772 spin_lock_init(&rtl_global_var.glb_list_lock);
2777 static void __exit rtl_core_module_exit(void)
2780 rtl_rate_control_unregister();
2782 /* remove debugfs */
2783 rtl_debugfs_remove_topdir();
2786 module_init(rtl_core_module_init);
2787 module_exit(rtl_core_module_exit);