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 = IEEE80211_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 = IEEE80211_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[IEEE80211_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 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
211 "Support phy mode switch\n");
213 ht_cap->mcs.rx_mask[0] = 0xFF;
214 ht_cap->mcs.rx_mask[1] = 0xFF;
215 ht_cap->mcs.rx_mask[4] = 0x01;
217 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
219 if (get_rf_type(rtlphy) == RF_1T2R ||
220 get_rf_type(rtlphy) == RF_2T2R) {
221 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
223 ht_cap->mcs.rx_mask[0] = 0xFF;
224 ht_cap->mcs.rx_mask[1] = 0xFF;
225 ht_cap->mcs.rx_mask[4] = 0x01;
227 ht_cap->mcs.rx_highest =
228 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
229 } else if (get_rf_type(rtlphy) == RF_1T1R) {
230 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
232 ht_cap->mcs.rx_mask[0] = 0xFF;
233 ht_cap->mcs.rx_mask[1] = 0x00;
234 ht_cap->mcs.rx_mask[4] = 0x01;
236 ht_cap->mcs.rx_highest =
237 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
242 static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
243 struct ieee80211_sta_vht_cap *vht_cap)
245 struct rtl_priv *rtlpriv = rtl_priv(hw);
246 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
248 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
251 vht_cap->vht_supported = true;
253 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
254 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
255 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
256 IEEE80211_VHT_CAP_SHORT_GI_80 |
257 IEEE80211_VHT_CAP_TXSTBC |
258 IEEE80211_VHT_CAP_RXSTBC_1 |
259 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
260 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
261 IEEE80211_VHT_CAP_HTC_VHT |
262 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
263 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
264 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
267 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
268 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
269 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
270 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
271 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
272 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
273 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
274 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
276 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
277 vht_cap->vht_mcs.rx_highest =
278 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
279 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
280 vht_cap->vht_mcs.tx_highest =
281 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
282 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
285 vht_cap->vht_supported = true;
287 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
288 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
289 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
290 IEEE80211_VHT_CAP_SHORT_GI_80 |
291 IEEE80211_VHT_CAP_TXSTBC |
292 IEEE80211_VHT_CAP_RXSTBC_1 |
293 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
294 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
295 IEEE80211_VHT_CAP_HTC_VHT |
296 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
297 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
298 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
301 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
302 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
303 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
304 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
305 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
306 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
307 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
308 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
310 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
311 vht_cap->vht_mcs.rx_highest =
312 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
313 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
314 vht_cap->vht_mcs.tx_highest =
315 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
319 static void _rtl_init_mac80211(struct ieee80211_hw *hw)
321 struct rtl_priv *rtlpriv = rtl_priv(hw);
322 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
323 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
324 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
325 struct ieee80211_supported_band *sband;
327 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
328 rtlhal->bandset == BAND_ON_BOTH) {
330 /* <1> use mac->bands as mem for hw->wiphy->bands */
331 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
333 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
334 * to default value(1T1R) */
335 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
336 sizeof(struct ieee80211_supported_band));
338 /* <3> init ht cap base on ant_num */
339 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
341 /* <4> set mac->sband to wiphy->sband */
342 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
345 /* <1> use mac->bands as mem for hw->wiphy->bands */
346 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
348 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
349 * to default value(1T1R) */
350 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
351 sizeof(struct ieee80211_supported_band));
353 /* <3> init ht cap base on ant_num */
354 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
356 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
357 /* <4> set mac->sband to wiphy->sband */
358 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
360 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
361 /* <1> use mac->bands as mem for hw->wiphy->bands */
362 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
364 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
365 * to default value(1T1R) */
366 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
368 sizeof(struct ieee80211_supported_band));
370 /* <3> init ht cap base on ant_num */
371 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
373 /* <4> set mac->sband to wiphy->sband */
374 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
375 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
376 /* <1> use mac->bands as mem for hw->wiphy->bands */
377 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
379 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
380 * to default value(1T1R) */
381 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
383 sizeof(struct ieee80211_supported_band));
385 /* <3> init ht cap base on ant_num */
386 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
388 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
389 /* <4> set mac->sband to wiphy->sband */
390 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
392 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n",
393 rtlhal->current_bandtype);
396 /* <5> set hw caps */
397 hw->flags = IEEE80211_HW_SIGNAL_DBM |
398 IEEE80211_HW_RX_INCLUDES_FCS |
399 IEEE80211_HW_AMPDU_AGGREGATION |
400 IEEE80211_HW_CONNECTION_MONITOR |
401 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
402 IEEE80211_HW_MFP_CAPABLE |
403 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
405 /* swlps or hwlps has been set in diff chip in init_sw_vars */
406 if (rtlpriv->psc.swctrl_lps)
407 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
408 IEEE80211_HW_PS_NULLFUNC_STACK |
409 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
411 hw->wiphy->interface_modes =
412 BIT(NL80211_IFTYPE_AP) |
413 BIT(NL80211_IFTYPE_STATION) |
414 BIT(NL80211_IFTYPE_ADHOC) |
415 BIT(NL80211_IFTYPE_MESH_POINT) |
416 BIT(NL80211_IFTYPE_P2P_CLIENT) |
417 BIT(NL80211_IFTYPE_P2P_GO);
418 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
420 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
422 hw->wiphy->rts_threshold = 2347;
425 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
427 /* TODO: Correct this value for our hw */
428 /* TODO: define these hard code value */
429 hw->max_listen_interval = 10;
430 hw->max_rate_tries = 4;
431 /* hw->max_rates = 1; */
432 hw->sta_data_size = sizeof(struct rtl_sta_info);
434 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
436 if (rtlpriv->psc.wo_wlan_mode) {
437 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
438 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
439 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
440 rtlpriv->wowlan.n_patterns =
441 MAX_SUPPORT_WOL_PATTERN_NUM;
442 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
443 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
445 hw->wiphy->wowlan = &rtlpriv->wowlan;
449 /* <6> mac address */
450 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
451 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
453 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
454 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
455 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
459 static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
461 struct rtl_priv *rtlpriv = rtl_priv(hw);
464 setup_timer(&rtlpriv->works.watchdog_timer,
465 rtl_watch_dog_timer_callback, (unsigned long)hw);
466 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
467 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
469 rtlpriv->works.hw = hw;
470 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
471 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
472 (void *)rtl_watchdog_wq_callback);
473 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
474 (void *)rtl_ips_nic_off_wq_callback);
475 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
476 (void *)rtl_swlps_wq_callback);
477 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
478 (void *)rtl_swlps_rfon_wq_callback);
479 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
480 (void *)rtl_fwevt_wq_callback);
484 void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
486 struct rtl_priv *rtlpriv = rtl_priv(hw);
488 del_timer_sync(&rtlpriv->works.watchdog_timer);
490 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
491 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
492 cancel_delayed_work(&rtlpriv->works.ps_work);
493 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
494 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
496 EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
498 void rtl_init_rfkill(struct ieee80211_hw *hw)
500 struct rtl_priv *rtlpriv = rtl_priv(hw);
506 /*set init state to on */
507 rtlpriv->rfkill.rfkill_state = true;
508 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
510 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
513 pr_info("rtlwifi: wireless switch is %s\n",
514 rtlpriv->rfkill.rfkill_state ? "on" : "off");
516 rtlpriv->rfkill.rfkill_state = radio_state;
518 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
519 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
522 wiphy_rfkill_start_polling(hw->wiphy);
524 EXPORT_SYMBOL(rtl_init_rfkill);
526 void rtl_deinit_rfkill(struct ieee80211_hw *hw)
528 wiphy_rfkill_stop_polling(hw->wiphy);
530 EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
532 int rtl_init_core(struct ieee80211_hw *hw)
534 struct rtl_priv *rtlpriv = rtl_priv(hw);
535 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
537 /* <1> init mac80211 */
538 _rtl_init_mac80211(hw);
541 /* <2> rate control register */
542 hw->rate_control_algorithm = "rtl_rc";
545 * <3> init CRDA must come after init
546 * mac80211 hw in _rtl_init_mac80211.
548 if (rtl_regd_init(hw, rtl_reg_notifier)) {
549 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n");
554 mutex_init(&rtlpriv->locks.conf_mutex);
555 spin_lock_init(&rtlpriv->locks.ips_lock);
556 spin_lock_init(&rtlpriv->locks.irq_th_lock);
557 spin_lock_init(&rtlpriv->locks.h2c_lock);
558 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
559 spin_lock_init(&rtlpriv->locks.rf_lock);
560 spin_lock_init(&rtlpriv->locks.waitq_lock);
561 spin_lock_init(&rtlpriv->locks.entry_list_lock);
562 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
563 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
564 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
565 spin_lock_init(&rtlpriv->locks.lps_lock);
566 spin_lock_init(&rtlpriv->locks.iqk_lock);
568 INIT_LIST_HEAD(&rtlpriv->entry_list);
570 rtlmac->link_state = MAC80211_NOLINK;
572 /* <6> init deferred work */
573 _rtl_init_deferred_work(hw);
577 EXPORT_SYMBOL_GPL(rtl_init_core);
579 void rtl_deinit_core(struct ieee80211_hw *hw)
582 EXPORT_SYMBOL_GPL(rtl_deinit_core);
584 void rtl_init_rx_config(struct ieee80211_hw *hw)
586 struct rtl_priv *rtlpriv = rtl_priv(hw);
587 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
589 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
591 EXPORT_SYMBOL_GPL(rtl_init_rx_config);
593 /*********************************************************
595 * tx information functions
597 *********************************************************/
598 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
599 struct rtl_tcb_desc *tcb_desc,
600 struct ieee80211_tx_info *info)
602 struct rtl_priv *rtlpriv = rtl_priv(hw);
603 u8 rate_flag = info->control.rates[0].flags;
605 tcb_desc->use_shortpreamble = false;
607 /* 1M can only use Long Preamble. 11B spec */
608 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
610 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
611 tcb_desc->use_shortpreamble = true;
616 static void _rtl_query_shortgi(struct ieee80211_hw *hw,
617 struct ieee80211_sta *sta,
618 struct rtl_tcb_desc *tcb_desc,
619 struct ieee80211_tx_info *info)
621 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
622 u8 rate_flag = info->control.rates[0].flags;
623 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
624 u8 sgi_80 = 0, bw_80 = 0;
625 tcb_desc->use_shortgi = false;
630 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
631 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
632 sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
634 if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
637 if (!sgi_40 && !sgi_20)
640 if (mac->opmode == NL80211_IFTYPE_STATION) {
643 } else if (mac->opmode == NL80211_IFTYPE_AP ||
644 mac->opmode == NL80211_IFTYPE_ADHOC ||
645 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
646 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
647 bw_80 = sta->vht_cap.vht_supported;
652 tcb_desc->use_shortgi = true;
654 tcb_desc->use_shortgi = false;
657 tcb_desc->use_shortgi = true;
658 else if (!bw_40 && sgi_20)
659 tcb_desc->use_shortgi = true;
662 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
663 tcb_desc->use_shortgi = false;
666 static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
667 struct rtl_tcb_desc *tcb_desc,
668 struct ieee80211_tx_info *info)
670 struct rtl_priv *rtlpriv = rtl_priv(hw);
671 u8 rate_flag = info->control.rates[0].flags;
673 /* Common Settings */
674 tcb_desc->rts_stbc = false;
675 tcb_desc->cts_enable = false;
676 tcb_desc->rts_sc = 0;
677 tcb_desc->rts_bw = false;
678 tcb_desc->rts_use_shortpreamble = false;
679 tcb_desc->rts_use_shortgi = false;
681 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
682 /* Use CTS-to-SELF in protection mode. */
683 tcb_desc->rts_enable = true;
684 tcb_desc->cts_enable = true;
685 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
686 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
687 /* Use RTS-CTS in protection mode. */
688 tcb_desc->rts_enable = true;
689 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
693 static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
694 struct ieee80211_sta *sta,
695 struct rtl_tcb_desc *tcb_desc)
697 struct rtl_priv *rtlpriv = rtl_priv(hw);
698 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
699 struct rtl_sta_info *sta_entry = NULL;
703 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
704 ratr_index = sta_entry->ratr_index;
706 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
707 if (mac->opmode == NL80211_IFTYPE_STATION) {
708 tcb_desc->ratr_index = 0;
709 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
710 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
711 if (tcb_desc->multicast || tcb_desc->broadcast) {
713 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
714 tcb_desc->use_driver_rate = 1;
715 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
717 tcb_desc->ratr_index = ratr_index;
719 } else if (mac->opmode == NL80211_IFTYPE_AP) {
720 tcb_desc->ratr_index = ratr_index;
724 if (rtlpriv->dm.useramask) {
725 tcb_desc->ratr_index = ratr_index;
726 /* TODO we will differentiate adhoc and station future */
727 if (mac->opmode == NL80211_IFTYPE_STATION ||
728 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
729 tcb_desc->mac_id = 0;
731 if (mac->mode == WIRELESS_MODE_AC_5G)
732 tcb_desc->ratr_index =
733 RATR_INX_WIRELESS_AC_5N;
734 else if (mac->mode == WIRELESS_MODE_AC_24G)
735 tcb_desc->ratr_index =
736 RATR_INX_WIRELESS_AC_24N;
737 else if (mac->mode == WIRELESS_MODE_N_24G)
738 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
739 else if (mac->mode == WIRELESS_MODE_N_5G)
740 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
741 else if (mac->mode & WIRELESS_MODE_G)
742 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
743 else if (mac->mode & WIRELESS_MODE_B)
744 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
745 else if (mac->mode & WIRELESS_MODE_A)
746 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
748 } else if (mac->opmode == NL80211_IFTYPE_AP ||
749 mac->opmode == NL80211_IFTYPE_ADHOC) {
752 tcb_desc->mac_id = sta->aid + 1;
754 tcb_desc->mac_id = 1;
756 tcb_desc->mac_id = 0;
762 static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
763 struct ieee80211_sta *sta,
764 struct rtl_tcb_desc *tcb_desc)
766 struct rtl_priv *rtlpriv = rtl_priv(hw);
767 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
769 tcb_desc->packet_bw = false;
772 if (mac->opmode == NL80211_IFTYPE_AP ||
773 mac->opmode == NL80211_IFTYPE_ADHOC ||
774 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
775 if (!(sta->ht_cap.ht_supported) ||
776 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
778 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
779 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
782 if (tcb_desc->multicast || tcb_desc->broadcast)
785 /*use legency rate, shall use 20MHz */
786 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
789 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
791 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
792 rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
793 if (mac->opmode == NL80211_IFTYPE_AP ||
794 mac->opmode == NL80211_IFTYPE_ADHOC ||
795 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
796 if (!(sta->vht_cap.vht_supported))
798 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
800 !(sta->vht_cap.vht_supported))
803 if (tcb_desc->hw_rate <=
804 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
806 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
810 static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
811 struct ieee80211_sta *sta)
813 struct rtl_priv *rtlpriv = rtl_priv(hw);
814 struct rtl_phy *rtlphy = &(rtlpriv->phy);
816 u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
818 if ((get_rf_type(rtlphy) == RF_2T2R) &&
819 (tx_mcs_map & 0x000c) != 0x000c) {
820 if ((tx_mcs_map & 0x000c) >> 2 ==
821 IEEE80211_VHT_MCS_SUPPORT_0_7)
823 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
824 else if ((tx_mcs_map & 0x000c) >> 2 ==
825 IEEE80211_VHT_MCS_SUPPORT_0_8)
827 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
830 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
832 if ((tx_mcs_map & 0x0003) ==
833 IEEE80211_VHT_MCS_SUPPORT_0_7)
835 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
836 else if ((tx_mcs_map & 0x0003) ==
837 IEEE80211_VHT_MCS_SUPPORT_0_8)
839 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
842 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
848 static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
849 struct ieee80211_sta *sta)
851 struct rtl_priv *rtlpriv = rtl_priv(hw);
852 struct rtl_phy *rtlphy = &rtlpriv->phy;
855 if ((get_rf_type(rtlphy) == RF_2T2R) &&
856 (sta->ht_cap.mcs.rx_mask[1] != 0))
857 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
859 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
864 /* mac80211's rate_idx is like this:
866 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
869 * (rx_status->flag & RX_FLAG_HT) = 0,
870 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
873 * (rx_status->flag & RX_FLAG_HT) = 1,
874 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
876 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
878 * (rx_status->flag & RX_FLAG_HT) = 0,
879 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
882 * (rx_status->flag & RX_FLAG_HT) = 1,
883 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
886 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
887 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
889 int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
896 case DESC_RATEVHT1SS_MCS0:
899 case DESC_RATEVHT1SS_MCS1:
902 case DESC_RATEVHT1SS_MCS2:
905 case DESC_RATEVHT1SS_MCS3:
908 case DESC_RATEVHT1SS_MCS4:
911 case DESC_RATEVHT1SS_MCS5:
914 case DESC_RATEVHT1SS_MCS6:
917 case DESC_RATEVHT1SS_MCS7:
920 case DESC_RATEVHT1SS_MCS8:
923 case DESC_RATEVHT1SS_MCS9:
926 case DESC_RATEVHT2SS_MCS0:
929 case DESC_RATEVHT2SS_MCS1:
932 case DESC_RATEVHT2SS_MCS2:
935 case DESC_RATEVHT2SS_MCS3:
938 case DESC_RATEVHT2SS_MCS4:
941 case DESC_RATEVHT2SS_MCS5:
944 case DESC_RATEVHT2SS_MCS6:
947 case DESC_RATEVHT2SS_MCS7:
950 case DESC_RATEVHT2SS_MCS8:
953 case DESC_RATEVHT2SS_MCS9:
963 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
1006 switch (desc_rate) {
1037 switch (desc_rate) {
1068 case DESC_RATEMCS10:
1071 case DESC_RATEMCS11:
1074 case DESC_RATEMCS12:
1077 case DESC_RATEMCS13:
1080 case DESC_RATEMCS14:
1083 case DESC_RATEMCS15:
1093 EXPORT_SYMBOL(rtlwifi_rate_mapping);
1095 void rtl_get_tcb_desc(struct ieee80211_hw *hw,
1096 struct ieee80211_tx_info *info,
1097 struct ieee80211_sta *sta,
1098 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
1100 struct rtl_priv *rtlpriv = rtl_priv(hw);
1101 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
1102 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1103 struct ieee80211_rate *txrate;
1104 __le16 fc = rtl_get_fc(skb);
1106 txrate = ieee80211_get_tx_rate(hw, info);
1108 tcb_desc->hw_rate = txrate->hw_value;
1110 if (ieee80211_is_data(fc)) {
1112 *we set data rate INX 0
1113 *in rtl_rc.c if skb is special data or
1114 *mgt which need low data rate.
1118 *So tcb_desc->hw_rate is just used for
1119 *special data and mgt frames
1121 if (info->control.rates[0].idx == 0 ||
1122 ieee80211_is_nullfunc(fc)) {
1123 tcb_desc->use_driver_rate = true;
1124 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
1126 tcb_desc->disable_ratefallback = 1;
1129 *because hw will nerver use hw_rate
1130 *when tcb_desc->use_driver_rate = false
1131 *so we never set highest N rate here,
1132 *and N rate will all be controlled by FW
1133 *when tcb_desc->use_driver_rate = false
1135 if (sta && sta->vht_cap.vht_supported) {
1137 _rtl_get_vht_highest_n_rate(hw, sta);
1139 if (sta && (sta->ht_cap.ht_supported)) {
1141 _rtl_get_highest_n_rate(hw, sta);
1143 if (rtlmac->mode == WIRELESS_MODE_B) {
1145 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
1148 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
1154 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
1155 tcb_desc->multicast = 1;
1156 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
1157 tcb_desc->broadcast = 1;
1159 _rtl_txrate_selectmode(hw, sta, tcb_desc);
1160 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
1161 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
1162 _rtl_query_shortgi(hw, sta, tcb_desc, info);
1163 _rtl_query_protection_mode(hw, tcb_desc, info);
1165 tcb_desc->use_driver_rate = true;
1166 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
1167 tcb_desc->disable_ratefallback = 1;
1168 tcb_desc->mac_id = 0;
1169 tcb_desc->packet_bw = false;
1172 EXPORT_SYMBOL(rtl_get_tcb_desc);
1174 bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
1176 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1177 struct rtl_priv *rtlpriv = rtl_priv(hw);
1178 __le16 fc = rtl_get_fc(skb);
1180 if (rtlpriv->dm.supp_phymode_switch &&
1181 mac->link_state < MAC80211_LINKED &&
1182 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
1183 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1184 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1186 if (ieee80211_is_auth(fc)) {
1187 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
1190 mac->link_state = MAC80211_LINKING;
1192 rtlpriv->phy.need_iqk = true;
1198 EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
1200 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
1201 u8 *bssid, u16 tid);
1203 static void process_agg_start(struct ieee80211_hw *hw,
1204 struct ieee80211_hdr *hdr, u16 tid)
1206 struct rtl_priv *rtlpriv = rtl_priv(hw);
1207 struct ieee80211_rx_status rx_status = { 0 };
1208 struct sk_buff *skb_delba = NULL;
1210 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
1212 rx_status.freq = hw->conf.chandef.chan->center_freq;
1213 rx_status.band = hw->conf.chandef.chan->band;
1214 rx_status.flag |= RX_FLAG_DECRYPTED;
1215 rx_status.flag |= RX_FLAG_MACTIME_START;
1216 rx_status.rate_idx = 0;
1217 rx_status.signal = 50 + 10;
1218 memcpy(IEEE80211_SKB_RXCB(skb_delba),
1219 &rx_status, sizeof(rx_status));
1220 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1224 ieee80211_rx_irqsafe(hw, skb_delba);
1228 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1230 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1231 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1232 struct rtl_priv *rtlpriv = rtl_priv(hw);
1233 __le16 fc = rtl_get_fc(skb);
1234 u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
1237 if (!ieee80211_is_action(fc))
1246 if (mac->act_scanning)
1249 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1250 "%s ACT_ADDBAREQ From :%pM\n",
1251 is_tx ? "Tx" : "Rx", hdr->addr2);
1252 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
1253 skb->data, skb->len);
1255 struct ieee80211_sta *sta = NULL;
1256 struct rtl_sta_info *sta_entry = NULL;
1257 struct rtl_tid_data *tid_data;
1258 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1259 u16 capab = 0, tid = 0;
1262 sta = rtl_find_sta(hw, hdr->addr3);
1264 RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
1265 DBG_DMESG, "sta is NULL\n");
1271 (struct rtl_sta_info *)sta->drv_priv;
1277 le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1279 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1280 tid_data = &sta_entry->tids[tid];
1281 if (tid_data->agg.rx_agg_state ==
1283 process_agg_start(hw, hdr, tid);
1288 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1289 "%s ACT_ADDBARSP From :%pM\n",
1290 is_tx ? "Tx" : "Rx", hdr->addr2);
1293 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1294 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
1304 EXPORT_SYMBOL_GPL(rtl_action_proc);
1306 static void setup_arp_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc)
1308 rtlpriv->ra.is_special_data = true;
1309 if (rtlpriv->cfg->ops->get_btc_status())
1310 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
1312 rtlpriv->enter_ps = false;
1313 schedule_work(&rtlpriv->works.lps_change_work);
1314 ppsc->last_delaylps_stamp_jiffies = jiffies;
1317 /*should call before software enc*/
1318 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
1321 struct rtl_priv *rtlpriv = rtl_priv(hw);
1322 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1323 __le16 fc = rtl_get_fc(skb);
1325 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1326 u8 encrypt_header_len = 0;
1328 const struct iphdr *ip;
1330 if (!ieee80211_is_data(fc))
1333 switch (rtlpriv->sec.pairwise_enc_algorithm) {
1334 case WEP40_ENCRYPTION:
1335 case WEP104_ENCRYPTION:
1336 encrypt_header_len = 4;/*WEP_IV_LEN*/
1338 case TKIP_ENCRYPTION:
1339 encrypt_header_len = 8;/*TKIP_IV_LEN*/
1341 case AESCCMP_ENCRYPTION:
1342 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
1348 offset = mac_hdr_len + SNAP_SIZE;
1350 offset += encrypt_header_len;
1351 ether_type = be16_to_cpup((__be16 *)(skb->data + offset));
1353 if (ETH_P_IP == ether_type) {
1354 ip = (struct iphdr *)((u8 *)skb->data + offset +
1356 if (IPPROTO_UDP == ip->protocol) {
1357 struct udphdr *udp = (struct udphdr *)((u8 *)ip +
1359 if (((((u8 *)udp)[1] == 68) &&
1360 (((u8 *)udp)[3] == 67)) ||
1361 ((((u8 *)udp)[1] == 67) &&
1362 (((u8 *)udp)[3] == 68))) {
1363 /* 68 : UDP BOOTP client
1364 * 67 : UDP BOOTP server
1366 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
1367 DBG_DMESG, "dhcp %s !!\n",
1368 (is_tx) ? "Tx" : "Rx");
1371 setup_arp_tx(rtlpriv, ppsc);
1375 } else if (ETH_P_ARP == ether_type) {
1377 setup_arp_tx(rtlpriv, ppsc);
1380 } else if (ETH_P_PAE == ether_type) {
1381 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1382 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
1385 rtlpriv->ra.is_special_data = true;
1386 rtlpriv->enter_ps = false;
1387 schedule_work(&rtlpriv->works.lps_change_work);
1388 ppsc->last_delaylps_stamp_jiffies = jiffies;
1392 } else if (ETH_P_IPV6 == ether_type) {
1393 /* TODO: Handle any IPv6 cases that need special handling.
1394 * For now, always return false
1400 rtlpriv->ra.is_special_data = false;
1403 EXPORT_SYMBOL_GPL(rtl_is_special_data);
1405 /*********************************************************
1407 * functions called by core.c
1409 *********************************************************/
1410 int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1411 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1413 struct rtl_priv *rtlpriv = rtl_priv(hw);
1414 struct rtl_tid_data *tid_data;
1415 struct rtl_sta_info *sta_entry = NULL;
1420 if (unlikely(tid >= MAX_TID_COUNT))
1423 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1426 tid_data = &sta_entry->tids[tid];
1428 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1429 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1430 tid_data->seq_number);
1432 *ssn = tid_data->seq_number;
1433 tid_data->agg.agg_state = RTL_AGG_START;
1435 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1439 int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1440 struct ieee80211_sta *sta, u16 tid)
1442 struct rtl_priv *rtlpriv = rtl_priv(hw);
1443 struct rtl_tid_data *tid_data;
1444 struct rtl_sta_info *sta_entry = NULL;
1449 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1450 "on ra = %pM tid = %d\n", sta->addr, tid);
1452 if (unlikely(tid >= MAX_TID_COUNT))
1455 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1456 tid_data = &sta_entry->tids[tid];
1457 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
1459 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1463 int rtl_rx_agg_start(struct ieee80211_hw *hw,
1464 struct ieee80211_sta *sta, u16 tid)
1466 struct rtl_priv *rtlpriv = rtl_priv(hw);
1467 struct rtl_tid_data *tid_data;
1468 struct rtl_sta_info *sta_entry = NULL;
1473 if (unlikely(tid >= MAX_TID_COUNT))
1476 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1479 tid_data = &sta_entry->tids[tid];
1481 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1482 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1483 tid_data->seq_number);
1485 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1489 int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1490 struct ieee80211_sta *sta, u16 tid)
1492 struct rtl_priv *rtlpriv = rtl_priv(hw);
1493 struct rtl_sta_info *sta_entry = NULL;
1498 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1499 "on ra = %pM tid = %d\n", sta->addr, tid);
1501 if (unlikely(tid >= MAX_TID_COUNT))
1504 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1505 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1509 int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1510 struct ieee80211_sta *sta, u16 tid)
1512 struct rtl_priv *rtlpriv = rtl_priv(hw);
1513 struct rtl_sta_info *sta_entry = NULL;
1518 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1519 "on ra = %pM tid = %d\n", sta->addr, tid);
1521 if (unlikely(tid >= MAX_TID_COUNT))
1524 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1525 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
1530 /*********************************************************
1532 * wq & timer callback functions
1534 *********************************************************/
1535 /* this function is used for roaming */
1536 void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1538 struct rtl_priv *rtlpriv = rtl_priv(hw);
1539 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1541 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1544 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1547 /* check if this really is a beacon */
1548 if (!ieee80211_is_beacon(hdr->frame_control) &&
1549 !ieee80211_is_probe_resp(hdr->frame_control))
1552 /* min. beacon length + FCS_LEN */
1553 if (skb->len <= 40 + FCS_LEN)
1556 /* and only beacons from the associated BSSID, please */
1557 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
1560 rtlpriv->link_info.bcn_rx_inperiod++;
1562 EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
1564 void rtl_watchdog_wq_callback(void *data)
1566 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1569 struct ieee80211_hw *hw = rtlworks->hw;
1570 struct rtl_priv *rtlpriv = rtl_priv(hw);
1571 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1572 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1573 bool busytraffic = false;
1574 bool tx_busy_traffic = false;
1575 bool rx_busy_traffic = false;
1576 bool higher_busytraffic = false;
1577 bool higher_busyrxtraffic = false;
1579 u32 rx_cnt_inp4eriod = 0;
1580 u32 tx_cnt_inp4eriod = 0;
1581 u32 aver_rx_cnt_inperiod = 0;
1582 u32 aver_tx_cnt_inperiod = 0;
1583 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1584 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
1586 if (is_hal_stop(rtlhal))
1589 /* <1> Determine if action frame is allowed */
1590 if (mac->link_state > MAC80211_NOLINK) {
1591 if (mac->cnt_after_linked < 20)
1592 mac->cnt_after_linked++;
1594 mac->cnt_after_linked = 0;
1597 /* <2> to check if traffic busy, if
1598 * busytraffic we don't change channel
1600 if (mac->link_state >= MAC80211_LINKED) {
1602 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1603 for (idx = 0; idx <= 2; idx++) {
1604 rtlpriv->link_info.num_rx_in4period[idx] =
1605 rtlpriv->link_info.num_rx_in4period[idx + 1];
1606 rtlpriv->link_info.num_tx_in4period[idx] =
1607 rtlpriv->link_info.num_tx_in4period[idx + 1];
1609 rtlpriv->link_info.num_rx_in4period[3] =
1610 rtlpriv->link_info.num_rx_inperiod;
1611 rtlpriv->link_info.num_tx_in4period[3] =
1612 rtlpriv->link_info.num_tx_inperiod;
1613 for (idx = 0; idx <= 3; idx++) {
1615 rtlpriv->link_info.num_rx_in4period[idx];
1617 rtlpriv->link_info.num_tx_in4period[idx];
1619 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1620 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1622 /* (2) check traffic busy */
1623 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
1625 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1626 rx_busy_traffic = true;
1628 tx_busy_traffic = false;
1631 /* Higher Tx/Rx data. */
1632 if (aver_rx_cnt_inperiod > 4000 ||
1633 aver_tx_cnt_inperiod > 4000) {
1634 higher_busytraffic = true;
1636 /* Extremely high Rx data. */
1637 if (aver_rx_cnt_inperiod > 5000)
1638 higher_busyrxtraffic = true;
1641 /* check every tid's tx traffic */
1642 for (tid = 0; tid <= 7; tid++) {
1643 for (idx = 0; idx <= 2; idx++)
1644 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1645 rtlpriv->link_info.tidtx_in4period[tid]
1647 rtlpriv->link_info.tidtx_in4period[tid][3] =
1648 rtlpriv->link_info.tidtx_inperiod[tid];
1650 for (idx = 0; idx <= 3; idx++)
1651 tidtx_inp4eriod[tid] +=
1652 rtlpriv->link_info.tidtx_in4period[tid][idx];
1653 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1654 if (aver_tidtx_inperiod[tid] > 5000)
1655 rtlpriv->link_info.higher_busytxtraffic[tid] =
1658 rtlpriv->link_info.higher_busytxtraffic[tid] =
1662 if (((rtlpriv->link_info.num_rx_inperiod +
1663 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1664 (rtlpriv->link_info.num_rx_inperiod > 2))
1670 rtlpriv->link_info.num_rx_inperiod = 0;
1671 rtlpriv->link_info.num_tx_inperiod = 0;
1672 for (tid = 0; tid <= 7; tid++)
1673 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
1675 rtlpriv->link_info.busytraffic = busytraffic;
1676 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
1677 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1678 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
1679 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
1682 if (!rtlpriv->cfg->mod_params->disable_watchdog)
1683 rtlpriv->cfg->ops->dm_watchdog(hw);
1686 if (mac->link_state == MAC80211_LINKED &&
1687 mac->opmode == NL80211_IFTYPE_STATION) {
1688 if ((rtlpriv->link_info.bcn_rx_inperiod +
1689 rtlpriv->link_info.num_rx_inperiod) == 0) {
1690 rtlpriv->link_info.roam_times++;
1691 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1692 "AP off for %d s\n",
1693 (rtlpriv->link_info.roam_times * 2));
1695 /* if we can't recv beacon for 10s,
1696 * we should reconnect this AP
1698 if (rtlpriv->link_info.roam_times >= 5) {
1699 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1700 "AP off, try to reconnect now\n");
1701 rtlpriv->link_info.roam_times = 0;
1702 ieee80211_connection_loss(
1703 rtlpriv->mac80211.vif);
1706 rtlpriv->link_info.roam_times = 0;
1710 if (rtlpriv->cfg->ops->get_btc_status())
1711 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
1713 rtlpriv->link_info.bcn_rx_inperiod = 0;
1716 void rtl_watch_dog_timer_callback(unsigned long data)
1718 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1719 struct rtl_priv *rtlpriv = rtl_priv(hw);
1721 queue_delayed_work(rtlpriv->works.rtl_wq,
1722 &rtlpriv->works.watchdog_wq, 0);
1724 mod_timer(&rtlpriv->works.watchdog_timer,
1725 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1727 void rtl_fwevt_wq_callback(void *data)
1729 struct rtl_works *rtlworks =
1730 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
1731 struct ieee80211_hw *hw = rtlworks->hw;
1732 struct rtl_priv *rtlpriv = rtl_priv(hw);
1734 rtlpriv->cfg->ops->c2h_command_handle(hw);
1736 void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
1738 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1739 struct rtl_priv *rtlpriv = rtl_priv(hw);
1740 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
1742 if (buddy_priv == NULL)
1745 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
1747 /*********************************************************
1749 * frame process functions
1751 *********************************************************/
1752 u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1754 struct ieee80211_mgmt *mgmt = (void *)data;
1757 pos = (u8 *)mgmt->u.beacon.variable;
1760 if (pos + 2 + pos[1] > end)
1771 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1772 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1773 static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
1774 enum ieee80211_smps_mode smps,
1777 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1778 struct sk_buff *skb;
1779 struct ieee80211_mgmt *action_frame;
1781 /* 27 = header + category + action + smps mode */
1782 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1786 skb_reserve(skb, hw->extra_tx_headroom);
1787 action_frame = (void *)skb_put(skb, 27);
1788 memset(action_frame, 0, 27);
1789 memcpy(action_frame->da, da, ETH_ALEN);
1790 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1791 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1792 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1793 IEEE80211_STYPE_ACTION);
1794 action_frame->u.action.category = WLAN_CATEGORY_HT;
1795 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1797 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1798 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1800 /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
1801 * According to Kernel Code, here is right.
1803 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1804 action_frame->u.action.u.ht_smps.smps_control =
1805 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1807 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1808 action_frame->u.action.u.ht_smps.smps_control =
1809 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1811 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1812 action_frame->u.action.u.ht_smps.smps_control =
1813 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1820 int rtl_send_smps_action(struct ieee80211_hw *hw,
1821 struct ieee80211_sta *sta,
1822 enum ieee80211_smps_mode smps)
1824 struct rtl_priv *rtlpriv = rtl_priv(hw);
1825 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1826 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1827 struct sk_buff *skb = NULL;
1828 struct rtl_tcb_desc tcb_desc;
1829 u8 bssid[ETH_ALEN] = {0};
1831 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1833 if (rtlpriv->mac80211.act_scanning)
1839 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1842 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1845 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
1846 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
1848 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
1850 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
1851 /* this is a type = mgmt * stype = action frame */
1853 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1854 struct rtl_sta_info *sta_entry =
1855 (struct rtl_sta_info *) sta->drv_priv;
1856 sta_entry->mimo_ps = smps;
1857 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
1859 info->control.rates[0].idx = 0;
1860 info->band = hw->conf.chandef.chan->band;
1861 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
1868 EXPORT_SYMBOL(rtl_send_smps_action);
1870 void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
1872 struct rtl_priv *rtlpriv = rtl_priv(hw);
1873 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1874 enum io_type iotype;
1876 if (!is_hal_stop(rtlhal)) {
1877 switch (operation) {
1878 case SCAN_OPT_BACKUP:
1879 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
1880 rtlpriv->cfg->ops->set_hw_reg(hw,
1884 case SCAN_OPT_RESTORE:
1885 iotype = IO_CMD_RESUME_DM_BY_SCAN;
1886 rtlpriv->cfg->ops->set_hw_reg(hw,
1891 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1892 "Unknown Scan Backup operation.\n");
1897 EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
1899 /* because mac80211 have issues when can receive del ba
1900 * so here we just make a fake del_ba if we receive a ba_req
1901 * but rx_agg was opened to let mac80211 release some ba
1902 * related resources, so please this del_ba for tx
1904 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
1905 u8 *sa, u8 *bssid, u16 tid)
1907 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1908 struct sk_buff *skb;
1909 struct ieee80211_mgmt *action_frame;
1912 /* 27 = header + category + action + smps mode */
1913 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
1917 skb_reserve(skb, hw->extra_tx_headroom);
1918 action_frame = (void *)skb_put(skb, 34);
1919 memset(action_frame, 0, 34);
1920 memcpy(action_frame->sa, sa, ETH_ALEN);
1921 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
1922 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1923 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1924 IEEE80211_STYPE_ACTION);
1925 action_frame->u.action.category = WLAN_CATEGORY_BACK;
1926 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1927 params = (u16)(1 << 11); /* bit 11 initiator */
1928 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1930 action_frame->u.action.u.delba.params = cpu_to_le16(params);
1931 action_frame->u.action.u.delba.reason_code =
1932 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
1937 /*********************************************************
1941 *********************************************************/
1942 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
1943 struct octet_string vendor_ie)
1945 struct rtl_priv *rtlpriv = rtl_priv(hw);
1946 bool matched = false;
1947 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1948 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1949 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1950 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1951 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1952 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1953 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1954 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1956 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1957 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1958 rtlpriv->mac80211.vendor = PEER_ATH;
1960 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1961 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1962 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1963 rtlpriv->mac80211.vendor = PEER_BROAD;
1965 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1966 rtlpriv->mac80211.vendor = PEER_RAL;
1968 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1969 rtlpriv->mac80211.vendor = PEER_CISCO;
1971 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1972 rtlpriv->mac80211.vendor = PEER_MARV;
1979 static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
1982 struct ieee80211_mgmt *mgmt = (void *)data;
1983 struct octet_string vendor_ie;
1986 pos = (u8 *)mgmt->u.beacon.variable;
1989 if (pos[0] == 221) {
1990 vendor_ie.length = pos[1];
1991 vendor_ie.octet = &pos[2];
1992 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1996 if (pos + 2 + pos[1] > end)
2004 void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
2006 struct rtl_priv *rtlpriv = rtl_priv(hw);
2007 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2008 struct ieee80211_hdr *hdr = (void *)data;
2009 u32 vendor = PEER_UNKNOWN;
2011 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
2012 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
2013 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
2014 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
2015 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
2016 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
2017 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
2018 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
2019 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
2020 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
2021 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
2022 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
2023 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
2024 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
2025 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
2026 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
2028 if (mac->opmode != NL80211_IFTYPE_STATION)
2031 if (mac->link_state == MAC80211_NOLINK) {
2032 mac->vendor = PEER_UNKNOWN;
2036 if (mac->cnt_after_linked > 2)
2039 /* check if this really is a beacon */
2040 if (!ieee80211_is_beacon(hdr->frame_control))
2043 /* min. beacon length + FCS_LEN */
2044 if (len <= 40 + FCS_LEN)
2047 /* and only beacons from the associated BSSID, please */
2048 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
2051 if (rtl_find_221_ie(hw, data, len))
2052 vendor = mac->vendor;
2054 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
2055 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
2056 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
2057 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
2058 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
2059 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
2060 vendor == PEER_ATH) {
2062 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
2063 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
2064 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
2065 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
2066 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
2067 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
2068 vendor == PEER_RAL) {
2069 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
2071 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
2072 vendor == PEER_CISCO) {
2073 vendor = PEER_CISCO;
2074 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
2075 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
2076 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
2077 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
2078 vendor == PEER_BROAD) {
2079 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
2080 vendor = PEER_BROAD;
2081 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
2082 vendor == PEER_MARV) {
2084 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
2087 mac->vendor = vendor;
2089 EXPORT_SYMBOL_GPL(rtl_recognize_peer);
2091 /*********************************************************
2095 *********************************************************/
2096 static ssize_t rtl_show_debug_level(struct device *d,
2097 struct device_attribute *attr, char *buf)
2099 struct ieee80211_hw *hw = dev_get_drvdata(d);
2100 struct rtl_priv *rtlpriv = rtl_priv(hw);
2102 return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
2105 static ssize_t rtl_store_debug_level(struct device *d,
2106 struct device_attribute *attr,
2107 const char *buf, size_t count)
2109 struct ieee80211_hw *hw = dev_get_drvdata(d);
2110 struct rtl_priv *rtlpriv = rtl_priv(hw);
2114 ret = kstrtoul(buf, 0, &val);
2116 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
2117 "%s is not in hex or decimal form.\n", buf);
2119 rtlpriv->dbg.global_debuglevel = val;
2120 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
2122 rtlpriv->dbg.global_debuglevel);
2125 return strnlen(buf, count);
2128 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2129 rtl_show_debug_level, rtl_store_debug_level);
2131 static struct attribute *rtl_sysfs_entries[] = {
2133 &dev_attr_debug_level.attr,
2139 * "name" is folder name witch will be
2140 * put in device directory like :
2141 * sys/devices/pci0000:00/0000:00:1c.4/
2142 * 0000:06:00.0/rtl_sysfs
2144 struct attribute_group rtl_attribute_group = {
2146 .attrs = rtl_sysfs_entries,
2148 EXPORT_SYMBOL_GPL(rtl_attribute_group);
2150 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2151 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2152 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2153 MODULE_LICENSE("GPL");
2154 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2156 struct rtl_global_var rtl_global_var = {};
2157 EXPORT_SYMBOL_GPL(rtl_global_var);
2159 static int __init rtl_core_module_init(void)
2161 if (rtl_rate_control_register())
2162 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
2164 /* init some global vars */
2165 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2166 spin_lock_init(&rtl_global_var.glb_list_lock);
2171 static void __exit rtl_core_module_exit(void)
2174 rtl_rate_control_unregister();
2177 module_init(rtl_core_module_init);
2178 module_exit(rtl_core_module_exit);