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
];
173 static void _rtl_init_hw_ht_capab(struct ieee80211_hw
*hw
,
174 struct ieee80211_sta_ht_cap
*ht_cap
)
176 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
177 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
179 ht_cap
->ht_supported
= true;
180 ht_cap
->cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
181 IEEE80211_HT_CAP_SGI_40
|
182 IEEE80211_HT_CAP_SGI_20
|
183 IEEE80211_HT_CAP_DSSSCCK40
| IEEE80211_HT_CAP_MAX_AMSDU
;
185 if (rtlpriv
->rtlhal
.disable_amsdu_8k
)
186 ht_cap
->cap
&= ~IEEE80211_HT_CAP_MAX_AMSDU
;
189 *Maximum length of AMPDU that the STA can receive.
190 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
192 ht_cap
->ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
194 /*Minimum MPDU start spacing , */
195 ht_cap
->ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
197 ht_cap
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
199 /*hw->wiphy->bands[NL80211_BAND_2GHZ]
202 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
203 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
204 *if rx_ant >= 3 rx_mask[2]= 0xff;
205 *if BW_40 rx_mask[4]= 0x01;
206 *highest supported RX rate
208 if (rtlpriv
->dm
.supp_phymode_switch
) {
209 pr_info("Support phy mode switch\n");
211 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
212 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
213 ht_cap
->mcs
.rx_mask
[4] = 0x01;
215 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
217 if (get_rf_type(rtlphy
) == RF_1T2R
||
218 get_rf_type(rtlphy
) == RF_2T2R
) {
219 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
221 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
222 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
223 ht_cap
->mcs
.rx_mask
[4] = 0x01;
225 ht_cap
->mcs
.rx_highest
=
226 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
227 } else if (get_rf_type(rtlphy
) == RF_1T1R
) {
228 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "1T1R\n");
230 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
231 ht_cap
->mcs
.rx_mask
[1] = 0x00;
232 ht_cap
->mcs
.rx_mask
[4] = 0x01;
234 ht_cap
->mcs
.rx_highest
=
235 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7
);
240 static void _rtl_init_hw_vht_capab(struct ieee80211_hw
*hw
,
241 struct ieee80211_sta_vht_cap
*vht_cap
)
243 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
244 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
246 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
||
247 rtlhal
->hw_type
== HARDWARE_TYPE_RTL8822BE
) {
250 vht_cap
->vht_supported
= true;
252 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
|
253 IEEE80211_VHT_CAP_SHORT_GI_80
|
254 IEEE80211_VHT_CAP_TXSTBC
|
255 IEEE80211_VHT_CAP_RXSTBC_1
|
256 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
257 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
258 IEEE80211_VHT_CAP_HTC_VHT
|
259 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
|
260 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN
|
261 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN
|
264 mcs_map
= IEEE80211_VHT_MCS_SUPPORT_0_9
<< 0 |
265 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 2 |
266 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 4 |
267 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 6 |
268 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 8 |
269 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 10 |
270 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 12 |
271 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 14;
273 vht_cap
->vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
274 vht_cap
->vht_mcs
.rx_highest
=
275 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9
);
276 vht_cap
->vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
277 vht_cap
->vht_mcs
.tx_highest
=
278 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9
);
279 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
282 vht_cap
->vht_supported
= true;
284 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
|
285 IEEE80211_VHT_CAP_SHORT_GI_80
|
286 IEEE80211_VHT_CAP_TXSTBC
|
287 IEEE80211_VHT_CAP_RXSTBC_1
|
288 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
289 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
290 IEEE80211_VHT_CAP_HTC_VHT
|
291 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
|
292 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN
|
293 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN
|
296 mcs_map
= IEEE80211_VHT_MCS_SUPPORT_0_9
<< 0 |
297 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 2 |
298 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 4 |
299 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 6 |
300 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 8 |
301 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 10 |
302 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 12 |
303 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 14;
305 vht_cap
->vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
306 vht_cap
->vht_mcs
.rx_highest
=
307 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9
);
308 vht_cap
->vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
309 vht_cap
->vht_mcs
.tx_highest
=
310 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9
);
314 static void _rtl_init_mac80211(struct ieee80211_hw
*hw
)
316 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
317 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
318 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
319 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
320 struct ieee80211_supported_band
*sband
;
322 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&&
323 rtlhal
->bandset
== BAND_ON_BOTH
) {
325 /* <1> use mac->bands as mem for hw->wiphy->bands */
326 sband
= &rtlmac
->bands
[NL80211_BAND_2GHZ
];
328 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
329 * to default value(1T1R)
331 memcpy(&rtlmac
->bands
[NL80211_BAND_2GHZ
], &rtl_band_2ghz
,
332 sizeof(struct ieee80211_supported_band
));
334 /* <3> init ht cap base on ant_num */
335 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
337 /* <4> set mac->sband to wiphy->sband */
338 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = sband
;
341 /* <1> use mac->bands as mem for hw->wiphy->bands */
342 sband
= &rtlmac
->bands
[NL80211_BAND_5GHZ
];
344 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
345 * to default value(1T1R)
347 memcpy(&rtlmac
->bands
[NL80211_BAND_5GHZ
], &rtl_band_5ghz
,
348 sizeof(struct ieee80211_supported_band
));
350 /* <3> init ht cap base on ant_num */
351 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
353 _rtl_init_hw_vht_capab(hw
, &sband
->vht_cap
);
354 /* <4> set mac->sband to wiphy->sband */
355 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = sband
;
357 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
358 /* <1> use mac->bands as mem for hw->wiphy->bands */
359 sband
= &rtlmac
->bands
[NL80211_BAND_2GHZ
];
361 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
362 * to default value(1T1R)
364 memcpy(&rtlmac
->bands
[NL80211_BAND_2GHZ
],
366 sizeof(struct ieee80211_supported_band
));
368 /* <3> init ht cap base on ant_num */
369 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
371 /* <4> set mac->sband to wiphy->sband */
372 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = sband
;
373 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
374 /* <1> use mac->bands as mem for hw->wiphy->bands */
375 sband
= &rtlmac
->bands
[NL80211_BAND_5GHZ
];
377 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
378 * 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
, CONNECTION_MONITOR
);
400 ieee80211_hw_set(hw
, MFP_CAPABLE
);
401 ieee80211_hw_set(hw
, REPORTS_TX_ACK_STATUS
);
402 ieee80211_hw_set(hw
, SUPPORTS_TX_FRAG
);
403 ieee80211_hw_set(hw
, SUPPORT_FAST_XMIT
);
404 ieee80211_hw_set(hw
, SUPPORTS_AMSDU_IN_AMPDU
);
406 /* swlps or hwlps has been set in diff chip in init_sw_vars */
407 if (rtlpriv
->psc
.swctrl_lps
) {
408 ieee80211_hw_set(hw
, SUPPORTS_PS
);
409 ieee80211_hw_set(hw
, PS_NULLFUNC_STACK
);
411 if (rtlpriv
->psc
.fwctrl_lps
) {
412 ieee80211_hw_set(hw
, SUPPORTS_PS
);
413 ieee80211_hw_set(hw
, SUPPORTS_DYNAMIC_PS
);
415 hw
->wiphy
->interface_modes
=
416 BIT(NL80211_IFTYPE_AP
) |
417 BIT(NL80211_IFTYPE_STATION
) |
418 BIT(NL80211_IFTYPE_ADHOC
) |
419 BIT(NL80211_IFTYPE_MESH_POINT
) |
420 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
421 BIT(NL80211_IFTYPE_P2P_GO
);
422 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
424 hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
426 hw
->wiphy
->rts_threshold
= 2347;
429 hw
->extra_tx_headroom
= RTL_TX_HEADER_SIZE
;
431 /* TODO: Correct this value for our hw */
432 hw
->max_listen_interval
= MAX_LISTEN_INTERVAL
;
433 hw
->max_rate_tries
= MAX_RATE_TRIES
;
434 /* hw->max_rates = 1; */
435 hw
->sta_data_size
= sizeof(struct rtl_sta_info
);
437 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
439 if (rtlpriv
->psc
.wo_wlan_mode
) {
440 if (rtlpriv
->psc
.wo_wlan_mode
& WAKE_ON_MAGIC_PACKET
)
441 rtlpriv
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
;
442 if (rtlpriv
->psc
.wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) {
443 rtlpriv
->wowlan
.n_patterns
=
444 MAX_SUPPORT_WOL_PATTERN_NUM
;
445 rtlpriv
->wowlan
.pattern_min_len
= MIN_WOL_PATTERN_SIZE
;
446 rtlpriv
->wowlan
.pattern_max_len
= MAX_WOL_PATTERN_SIZE
;
448 hw
->wiphy
->wowlan
= &rtlpriv
->wowlan
;
452 /* <6> mac address */
453 if (is_valid_ether_addr(rtlefuse
->dev_addr
)) {
454 SET_IEEE80211_PERM_ADDR(hw
, rtlefuse
->dev_addr
);
456 u8 rtlmac1
[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
458 get_random_bytes((rtlmac1
+ (ETH_ALEN
- 1)), 1);
459 SET_IEEE80211_PERM_ADDR(hw
, rtlmac1
);
463 static void _rtl_init_deferred_work(struct ieee80211_hw
*hw
)
465 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
468 timer_setup(&rtlpriv
->works
.watchdog_timer
,
469 rtl_watch_dog_timer_callback
, 0);
470 timer_setup(&rtlpriv
->works
.dualmac_easyconcurrent_retrytimer
,
471 rtl_easy_concurrent_retrytimer_callback
, 0);
473 rtlpriv
->works
.hw
= hw
;
474 rtlpriv
->works
.rtl_wq
= alloc_workqueue("%s", 0, 0, rtlpriv
->cfg
->name
);
475 INIT_DELAYED_WORK(&rtlpriv
->works
.watchdog_wq
,
476 (void *)rtl_watchdog_wq_callback
);
477 INIT_DELAYED_WORK(&rtlpriv
->works
.ips_nic_off_wq
,
478 (void *)rtl_ips_nic_off_wq_callback
);
479 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_work
,
480 (void *)rtl_swlps_wq_callback
);
481 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_rfon_wq
,
482 (void *)rtl_swlps_rfon_wq_callback
);
483 INIT_DELAYED_WORK(&rtlpriv
->works
.fwevt_wq
,
484 (void *)rtl_fwevt_wq_callback
);
485 INIT_DELAYED_WORK(&rtlpriv
->works
.c2hcmd_wq
,
486 (void *)rtl_c2hcmd_wq_callback
);
489 void rtl_deinit_deferred_work(struct ieee80211_hw
*hw
)
491 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
493 del_timer_sync(&rtlpriv
->works
.watchdog_timer
);
495 cancel_delayed_work(&rtlpriv
->works
.watchdog_wq
);
496 cancel_delayed_work(&rtlpriv
->works
.ips_nic_off_wq
);
497 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
498 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
499 cancel_delayed_work(&rtlpriv
->works
.fwevt_wq
);
500 cancel_delayed_work(&rtlpriv
->works
.c2hcmd_wq
);
503 void rtl_init_rfkill(struct ieee80211_hw
*hw
)
505 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
511 /*set init state to on */
512 rtlpriv
->rfkill
.rfkill_state
= true;
513 wiphy_rfkill_set_hw_state(hw
->wiphy
, 0);
515 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
518 pr_info("rtlwifi: wireless switch is %s\n",
519 rtlpriv
->rfkill
.rfkill_state
? "on" : "off");
521 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
523 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
524 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
527 wiphy_rfkill_start_polling(hw
->wiphy
);
530 void rtl_deinit_rfkill(struct ieee80211_hw
*hw
)
532 wiphy_rfkill_stop_polling(hw
->wiphy
);
535 int rtl_init_core(struct ieee80211_hw
*hw
)
537 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
538 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
540 /* <1> init mac80211 */
541 _rtl_init_mac80211(hw
);
544 /* <2> rate control register */
545 hw
->rate_control_algorithm
= "rtl_rc";
548 * <3> init CRDA must come after init
549 * mac80211 hw in _rtl_init_mac80211.
551 if (rtl_regd_init(hw
, rtl_reg_notifier
)) {
552 pr_err("REGD init failed\n");
557 mutex_init(&rtlpriv
->locks
.conf_mutex
);
558 mutex_init(&rtlpriv
->locks
.ips_mutex
);
559 mutex_init(&rtlpriv
->locks
.lps_mutex
);
560 spin_lock_init(&rtlpriv
->locks
.irq_th_lock
);
561 spin_lock_init(&rtlpriv
->locks
.h2c_lock
);
562 spin_lock_init(&rtlpriv
->locks
.rf_ps_lock
);
563 spin_lock_init(&rtlpriv
->locks
.rf_lock
);
564 spin_lock_init(&rtlpriv
->locks
.waitq_lock
);
565 spin_lock_init(&rtlpriv
->locks
.entry_list_lock
);
566 spin_lock_init(&rtlpriv
->locks
.c2hcmd_lock
);
567 spin_lock_init(&rtlpriv
->locks
.scan_list_lock
);
568 spin_lock_init(&rtlpriv
->locks
.cck_and_rw_pagea_lock
);
569 spin_lock_init(&rtlpriv
->locks
.fw_ps_lock
);
570 spin_lock_init(&rtlpriv
->locks
.iqk_lock
);
572 INIT_LIST_HEAD(&rtlpriv
->entry_list
);
573 INIT_LIST_HEAD(&rtlpriv
->c2hcmd_list
);
574 INIT_LIST_HEAD(&rtlpriv
->scan_list
.list
);
576 rtlmac
->link_state
= MAC80211_NOLINK
;
578 /* <6> init deferred work */
579 _rtl_init_deferred_work(hw
);
584 static void rtl_free_entries_from_scan_list(struct ieee80211_hw
*hw
);
586 void rtl_deinit_core(struct ieee80211_hw
*hw
)
588 rtl_c2hcmd_launcher(hw
, 0);
589 rtl_free_entries_from_scan_list(hw
);
592 void rtl_init_rx_config(struct ieee80211_hw
*hw
)
594 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
595 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
597 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*)&mac
->rx_conf
);
600 /*********************************************************
602 * tx information functions
604 *********************************************************/
605 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw
*hw
,
606 struct rtl_tcb_desc
*tcb_desc
,
607 struct ieee80211_tx_info
*info
)
609 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
610 u8 rate_flag
= info
->control
.rates
[0].flags
;
612 tcb_desc
->use_shortpreamble
= false;
614 /* 1M can only use Long Preamble. 11B spec */
615 if (tcb_desc
->hw_rate
== rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE1M
])
617 else if (rate_flag
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
618 tcb_desc
->use_shortpreamble
= true;
621 static void _rtl_query_shortgi(struct ieee80211_hw
*hw
,
622 struct ieee80211_sta
*sta
,
623 struct rtl_tcb_desc
*tcb_desc
,
624 struct ieee80211_tx_info
*info
)
626 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
627 u8 rate_flag
= info
->control
.rates
[0].flags
;
628 u8 sgi_40
= 0, sgi_20
= 0, bw_40
= 0;
629 u8 sgi_80
= 0, bw_80
= 0;
631 tcb_desc
->use_shortgi
= false;
636 sgi_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
;
637 sgi_20
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
;
638 sgi_80
= sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SHORT_GI_80
;
640 if (!sta
->ht_cap
.ht_supported
&& !sta
->vht_cap
.vht_supported
)
643 if (!sgi_40
&& !sgi_20
)
646 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
649 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
650 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
651 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
652 bw_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
653 bw_80
= sta
->vht_cap
.vht_supported
;
658 tcb_desc
->use_shortgi
= true;
660 tcb_desc
->use_shortgi
= false;
663 tcb_desc
->use_shortgi
= true;
664 else if (!bw_40
&& sgi_20
)
665 tcb_desc
->use_shortgi
= true;
668 if (!(rate_flag
& IEEE80211_TX_RC_SHORT_GI
))
669 tcb_desc
->use_shortgi
= false;
672 static void _rtl_query_protection_mode(struct ieee80211_hw
*hw
,
673 struct rtl_tcb_desc
*tcb_desc
,
674 struct ieee80211_tx_info
*info
)
676 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
677 u8 rate_flag
= info
->control
.rates
[0].flags
;
679 /* Common Settings */
680 tcb_desc
->rts_stbc
= false;
681 tcb_desc
->cts_enable
= false;
682 tcb_desc
->rts_sc
= 0;
683 tcb_desc
->rts_bw
= false;
684 tcb_desc
->rts_use_shortpreamble
= false;
685 tcb_desc
->rts_use_shortgi
= false;
687 if (rate_flag
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
688 /* Use CTS-to-SELF in protection mode. */
689 tcb_desc
->rts_enable
= true;
690 tcb_desc
->cts_enable
= true;
691 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
692 } else if (rate_flag
& IEEE80211_TX_RC_USE_RTS_CTS
) {
693 /* Use RTS-CTS in protection mode. */
694 tcb_desc
->rts_enable
= true;
695 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
699 u8
rtl_mrate_idx_to_arfr_id(
700 struct ieee80211_hw
*hw
, u8 rate_index
,
701 enum wireless_mode wirelessmode
)
703 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
704 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
707 switch (rate_index
) {
708 case RATR_INX_WIRELESS_NGB
:
709 if (rtlphy
->rf_type
== RF_1T1R
)
710 ret
= RATEID_IDX_BGN_40M_1SS
;
712 ret
= RATEID_IDX_BGN_40M_2SS
;
714 case RATR_INX_WIRELESS_N
:
715 case RATR_INX_WIRELESS_NG
:
716 if (rtlphy
->rf_type
== RF_1T1R
)
717 ret
= RATEID_IDX_GN_N1SS
;
719 ret
= RATEID_IDX_GN_N2SS
;
721 case RATR_INX_WIRELESS_NB
:
722 if (rtlphy
->rf_type
== RF_1T1R
)
723 ret
= RATEID_IDX_BGN_20M_1SS_BN
;
725 ret
= RATEID_IDX_BGN_20M_2SS_BN
;
727 case RATR_INX_WIRELESS_GB
:
730 case RATR_INX_WIRELESS_G
:
733 case RATR_INX_WIRELESS_B
:
736 case RATR_INX_WIRELESS_MC
:
737 if (wirelessmode
== WIRELESS_MODE_B
||
738 wirelessmode
== WIRELESS_MODE_G
||
739 wirelessmode
== WIRELESS_MODE_N_24G
||
740 wirelessmode
== WIRELESS_MODE_AC_24G
)
745 case RATR_INX_WIRELESS_AC_5N
:
746 if (rtlphy
->rf_type
== RF_1T1R
)
747 ret
= RATEID_IDX_VHT_1SS
;
749 ret
= RATEID_IDX_VHT_2SS
;
751 case RATR_INX_WIRELESS_AC_24N
:
752 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
753 if (rtlphy
->rf_type
== RF_1T1R
)
754 ret
= RATEID_IDX_VHT_1SS
;
756 ret
= RATEID_IDX_VHT_2SS
;
758 if (rtlphy
->rf_type
== RF_1T1R
)
759 ret
= RATEID_IDX_MIX1
;
761 ret
= RATEID_IDX_MIX2
;
765 ret
= RATEID_IDX_BGN_40M_2SS
;
771 static void _rtl_txrate_selectmode(struct ieee80211_hw
*hw
,
772 struct ieee80211_sta
*sta
,
773 struct rtl_tcb_desc
*tcb_desc
)
775 #define SET_RATE_ID(rate_id) \
776 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
777 rtl_mrate_idx_to_arfr_id(hw, rate_id, \
778 (sta_entry ? sta_entry->wireless_mode : \
779 WIRELESS_MODE_G)) : \
782 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
783 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
784 struct rtl_sta_info
*sta_entry
= NULL
;
785 u8 ratr_index
= SET_RATE_ID(RATR_INX_WIRELESS_MC
);
788 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
789 ratr_index
= sta_entry
->ratr_index
;
791 if (!tcb_desc
->disable_ratefallback
|| !tcb_desc
->use_driver_rate
) {
792 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
793 tcb_desc
->ratr_index
= 0;
794 } else if (mac
->opmode
== NL80211_IFTYPE_ADHOC
||
795 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
796 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
) {
798 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE2M
];
799 tcb_desc
->use_driver_rate
= 1;
800 tcb_desc
->ratr_index
=
801 SET_RATE_ID(RATR_INX_WIRELESS_MC
);
803 tcb_desc
->ratr_index
= ratr_index
;
805 } else if (mac
->opmode
== NL80211_IFTYPE_AP
) {
806 tcb_desc
->ratr_index
= ratr_index
;
810 if (rtlpriv
->dm
.useramask
) {
811 tcb_desc
->ratr_index
= ratr_index
;
812 /* TODO we will differentiate adhoc and station future */
813 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
814 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
815 tcb_desc
->mac_id
= 0;
818 (rtlpriv
->cfg
->spec_ver
& RTL_SPEC_NEW_RATEID
))
819 ; /* use sta_entry->ratr_index */
820 else if (mac
->mode
== WIRELESS_MODE_AC_5G
)
821 tcb_desc
->ratr_index
=
822 SET_RATE_ID(RATR_INX_WIRELESS_AC_5N
);
823 else if (mac
->mode
== WIRELESS_MODE_AC_24G
)
824 tcb_desc
->ratr_index
=
825 SET_RATE_ID(RATR_INX_WIRELESS_AC_24N
);
826 else if (mac
->mode
== WIRELESS_MODE_N_24G
)
827 tcb_desc
->ratr_index
=
828 SET_RATE_ID(RATR_INX_WIRELESS_NGB
);
829 else if (mac
->mode
== WIRELESS_MODE_N_5G
)
830 tcb_desc
->ratr_index
=
831 SET_RATE_ID(RATR_INX_WIRELESS_NG
);
832 else if (mac
->mode
& WIRELESS_MODE_G
)
833 tcb_desc
->ratr_index
=
834 SET_RATE_ID(RATR_INX_WIRELESS_GB
);
835 else if (mac
->mode
& WIRELESS_MODE_B
)
836 tcb_desc
->ratr_index
=
837 SET_RATE_ID(RATR_INX_WIRELESS_B
);
838 else if (mac
->mode
& WIRELESS_MODE_A
)
839 tcb_desc
->ratr_index
=
840 SET_RATE_ID(RATR_INX_WIRELESS_G
);
842 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
843 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
846 tcb_desc
->mac_id
= sta
->aid
+ 1;
848 tcb_desc
->mac_id
= 1;
850 tcb_desc
->mac_id
= 0;
857 static void _rtl_query_bandwidth_mode(struct ieee80211_hw
*hw
,
858 struct ieee80211_sta
*sta
,
859 struct rtl_tcb_desc
*tcb_desc
)
861 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
862 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
864 tcb_desc
->packet_bw
= false;
867 if (mac
->opmode
== NL80211_IFTYPE_AP
||
868 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
869 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
870 if (!(sta
->ht_cap
.ht_supported
) ||
871 !(sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
873 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
874 if (!mac
->bw_40
|| !(sta
->ht_cap
.ht_supported
))
877 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
)
880 /*use legency rate, shall use 20MHz */
881 if (tcb_desc
->hw_rate
<= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
])
884 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_20_40
;
886 if (rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8812AE
||
887 rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8821AE
||
888 (rtlpriv
->cfg
->spec_ver
& RTL_SPEC_SUPPORT_VHT
)) {
889 if (mac
->opmode
== NL80211_IFTYPE_AP
||
890 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
891 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
892 if (!(sta
->vht_cap
.vht_supported
))
894 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
896 !(sta
->vht_cap
.vht_supported
))
899 if (tcb_desc
->hw_rate
<=
900 rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
])
902 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_80
;
906 static u8
_rtl_get_vht_highest_n_rate(struct ieee80211_hw
*hw
,
907 struct ieee80211_sta
*sta
)
909 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
910 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
912 u16 tx_mcs_map
= le16_to_cpu(sta
->vht_cap
.vht_mcs
.tx_mcs_map
);
914 if ((get_rf_type(rtlphy
) == RF_2T2R
) &&
915 (tx_mcs_map
& 0x000c) != 0x000c) {
916 if ((tx_mcs_map
& 0x000c) >> 2 ==
917 IEEE80211_VHT_MCS_SUPPORT_0_7
)
919 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS7
];
920 else if ((tx_mcs_map
& 0x000c) >> 2 ==
921 IEEE80211_VHT_MCS_SUPPORT_0_8
)
923 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS8
];
926 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
928 if ((tx_mcs_map
& 0x0003) ==
929 IEEE80211_VHT_MCS_SUPPORT_0_7
)
931 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS7
];
932 else if ((tx_mcs_map
& 0x0003) ==
933 IEEE80211_VHT_MCS_SUPPORT_0_8
)
935 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS8
];
938 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
944 static u8
_rtl_get_highest_n_rate(struct ieee80211_hw
*hw
,
945 struct ieee80211_sta
*sta
)
947 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
948 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
951 if (get_rf_type(rtlphy
) == RF_2T2R
&&
952 sta
->ht_cap
.mcs
.rx_mask
[1] != 0)
953 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
];
955 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS7
];
960 /* mac80211's rate_idx is like this:
962 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
965 * (rx_status->flag & RX_FLAG_HT) = 0,
966 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
969 * (rx_status->flag & RX_FLAG_HT) = 1,
970 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
972 * 5G band:rx_status->band == NL80211_BAND_5GHZ
974 * (rx_status->flag & RX_FLAG_HT) = 0,
975 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
978 * (rx_status->flag & RX_FLAG_HT) = 1,
979 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
982 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
983 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
985 int rtlwifi_rate_mapping(struct ieee80211_hw
*hw
, bool isht
, bool isvht
,
992 case DESC_RATEVHT1SS_MCS0
:
995 case DESC_RATEVHT1SS_MCS1
:
998 case DESC_RATEVHT1SS_MCS2
:
1001 case DESC_RATEVHT1SS_MCS3
:
1004 case DESC_RATEVHT1SS_MCS4
:
1007 case DESC_RATEVHT1SS_MCS5
:
1010 case DESC_RATEVHT1SS_MCS6
:
1013 case DESC_RATEVHT1SS_MCS7
:
1016 case DESC_RATEVHT1SS_MCS8
:
1019 case DESC_RATEVHT1SS_MCS9
:
1022 case DESC_RATEVHT2SS_MCS0
:
1025 case DESC_RATEVHT2SS_MCS1
:
1028 case DESC_RATEVHT2SS_MCS2
:
1031 case DESC_RATEVHT2SS_MCS3
:
1034 case DESC_RATEVHT2SS_MCS4
:
1037 case DESC_RATEVHT2SS_MCS5
:
1040 case DESC_RATEVHT2SS_MCS6
:
1043 case DESC_RATEVHT2SS_MCS7
:
1046 case DESC_RATEVHT2SS_MCS8
:
1049 case DESC_RATEVHT2SS_MCS9
:
1059 if (hw
->conf
.chandef
.chan
->band
== NL80211_BAND_2GHZ
) {
1060 switch (desc_rate
) {
1102 switch (desc_rate
) {
1133 switch (desc_rate
) {
1164 case DESC_RATEMCS10
:
1167 case DESC_RATEMCS11
:
1170 case DESC_RATEMCS12
:
1173 case DESC_RATEMCS13
:
1176 case DESC_RATEMCS14
:
1179 case DESC_RATEMCS15
:
1190 static u8
_rtl_get_tx_hw_rate(struct ieee80211_hw
*hw
,
1191 struct ieee80211_tx_info
*info
)
1193 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1194 struct ieee80211_tx_rate
*r
= &info
->status
.rates
[0];
1195 struct ieee80211_rate
*txrate
;
1198 if (r
->flags
& IEEE80211_TX_RC_MCS
) {
1200 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
] - 15 +
1202 } else if (r
->flags
& IEEE80211_TX_RC_VHT_MCS
) {
1203 /* VHT MCS0-9, NSS */
1204 if (ieee80211_rate_get_vht_nss(r
) == 2)
1205 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
1207 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
1209 hw_value
= hw_value
- 9 + ieee80211_rate_get_vht_mcs(r
);
1212 txrate
= ieee80211_get_tx_rate(hw
, info
);
1215 hw_value
= txrate
->hw_value
;
1219 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
&&
1220 hw_value
< rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE6M
])
1221 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE6M
];
1226 void rtl_get_tcb_desc(struct ieee80211_hw
*hw
,
1227 struct ieee80211_tx_info
*info
,
1228 struct ieee80211_sta
*sta
,
1229 struct sk_buff
*skb
, struct rtl_tcb_desc
*tcb_desc
)
1231 #define SET_RATE_ID(rate_id) \
1232 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
1233 rtl_mrate_idx_to_arfr_id(hw, rate_id, \
1234 (sta_entry ? sta_entry->wireless_mode : \
1235 WIRELESS_MODE_G)) : \
1238 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1239 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
1240 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
1241 struct rtl_sta_info
*sta_entry
=
1242 (sta
? (struct rtl_sta_info
*)sta
->drv_priv
: NULL
);
1244 __le16 fc
= rtl_get_fc(skb
);
1246 tcb_desc
->hw_rate
= _rtl_get_tx_hw_rate(hw
, info
);
1248 if (rtl_is_tx_report_skb(hw
, skb
))
1249 tcb_desc
->use_spe_rpt
= 1;
1251 if (ieee80211_is_data(fc
)) {
1253 *we set data rate INX 0
1254 *in rtl_rc.c if skb is special data or
1255 *mgt which need low data rate.
1259 *So tcb_desc->hw_rate is just used for
1260 *special data and mgt frames
1262 if (info
->control
.rates
[0].idx
== 0 ||
1263 ieee80211_is_nullfunc(fc
)) {
1264 tcb_desc
->use_driver_rate
= true;
1265 tcb_desc
->ratr_index
=
1266 SET_RATE_ID(RATR_INX_WIRELESS_MC
);
1268 tcb_desc
->disable_ratefallback
= 1;
1270 /* because hw will never use hw_rate
1271 * when tcb_desc->use_driver_rate = false
1272 * so we never set highest N rate here,
1273 * and N rate will all be controlled by FW
1274 * when tcb_desc->use_driver_rate = false
1276 if (sta
&& sta
->vht_cap
.vht_supported
) {
1278 _rtl_get_vht_highest_n_rate(hw
, sta
);
1280 if (sta
&& sta
->ht_cap
.ht_supported
) {
1282 _rtl_get_highest_n_rate(hw
, sta
);
1284 if (rtlmac
->mode
== WIRELESS_MODE_B
) {
1286 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE11M
];
1289 rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
];
1295 if (is_multicast_ether_addr(hdr
->addr1
))
1296 tcb_desc
->multicast
= 1;
1297 else if (is_broadcast_ether_addr(hdr
->addr1
))
1298 tcb_desc
->broadcast
= 1;
1300 _rtl_txrate_selectmode(hw
, sta
, tcb_desc
);
1301 _rtl_query_bandwidth_mode(hw
, sta
, tcb_desc
);
1302 _rtl_qurey_shortpreamble_mode(hw
, tcb_desc
, info
);
1303 _rtl_query_shortgi(hw
, sta
, tcb_desc
, info
);
1304 _rtl_query_protection_mode(hw
, tcb_desc
, info
);
1306 tcb_desc
->use_driver_rate
= true;
1307 tcb_desc
->ratr_index
= SET_RATE_ID(RATR_INX_WIRELESS_MC
);
1308 tcb_desc
->disable_ratefallback
= 1;
1309 tcb_desc
->mac_id
= 0;
1310 tcb_desc
->packet_bw
= false;
1315 bool rtl_tx_mgmt_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1317 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1318 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1319 __le16 fc
= rtl_get_fc(skb
);
1321 if (rtlpriv
->dm
.supp_phymode_switch
&&
1322 mac
->link_state
< MAC80211_LINKED
&&
1323 (ieee80211_is_auth(fc
) || ieee80211_is_probe_req(fc
))) {
1324 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1325 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1327 if (ieee80211_is_auth(fc
)) {
1328 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
, "MAC80211_LINKING\n");
1330 mac
->link_state
= MAC80211_LINKING
;
1332 rtlpriv
->phy
.need_iqk
= true;
1337 struct sk_buff
*rtl_make_del_ba(struct ieee80211_hw
*hw
, u8
*sa
,
1338 u8
*bssid
, u16 tid
);
1340 static void process_agg_start(struct ieee80211_hw
*hw
,
1341 struct ieee80211_hdr
*hdr
, u16 tid
)
1343 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1344 struct ieee80211_rx_status rx_status
= { 0 };
1345 struct sk_buff
*skb_delba
= NULL
;
1347 skb_delba
= rtl_make_del_ba(hw
, hdr
->addr2
, hdr
->addr3
, tid
);
1349 rx_status
.freq
= hw
->conf
.chandef
.chan
->center_freq
;
1350 rx_status
.band
= hw
->conf
.chandef
.chan
->band
;
1351 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1352 rx_status
.flag
|= RX_FLAG_MACTIME_START
;
1353 rx_status
.rate_idx
= 0;
1354 rx_status
.signal
= 50 + 10;
1355 memcpy(IEEE80211_SKB_RXCB(skb_delba
),
1356 &rx_status
, sizeof(rx_status
));
1357 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1361 ieee80211_rx_irqsafe(hw
, skb_delba
);
1365 bool rtl_action_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
1367 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1368 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
1369 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1370 __le16 fc
= rtl_get_fc(skb
);
1371 u8
*act
= (u8
*)(((u8
*)skb
->data
+ MAC80211_3ADDR_LEN
));
1374 if (!ieee80211_is_action(fc
))
1383 if (mac
->act_scanning
)
1386 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1387 "%s ACT_ADDBAREQ From :%pM\n",
1388 is_tx
? "Tx" : "Rx", hdr
->addr2
);
1389 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "req\n",
1390 skb
->data
, skb
->len
);
1392 struct ieee80211_sta
*sta
= NULL
;
1393 struct rtl_sta_info
*sta_entry
= NULL
;
1394 struct rtl_tid_data
*tid_data
;
1395 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1396 u16 capab
= 0, tid
= 0;
1399 sta
= rtl_find_sta(hw
, hdr
->addr3
);
1401 RT_TRACE(rtlpriv
, COMP_SEND
| COMP_RECV
,
1402 DBG_DMESG
, "sta is NULL\n");
1408 (struct rtl_sta_info
*)sta
->drv_priv
;
1414 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1416 IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1417 if (tid
>= MAX_TID_COUNT
) {
1421 tid_data
= &sta_entry
->tids
[tid
];
1422 if (tid_data
->agg
.rx_agg_state
==
1424 process_agg_start(hw
, hdr
, tid
);
1429 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1430 "%s ACT_ADDBARSP From :%pM\n",
1431 is_tx
? "Tx" : "Rx", hdr
->addr2
);
1434 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1435 "ACT_ADDBADEL From :%pM\n", hdr
->addr2
);
1446 static void setup_special_tx(struct rtl_priv
*rtlpriv
, struct rtl_ps_ctl
*ppsc
,
1449 struct ieee80211_hw
*hw
= rtlpriv
->hw
;
1451 rtlpriv
->ra
.is_special_data
= true;
1452 if (rtlpriv
->cfg
->ops
->get_btc_status())
1453 rtlpriv
->btcoexist
.btc_ops
->btc_special_packet_notify(
1456 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1459 static const u8
*rtl_skb_ether_type_ptr(struct ieee80211_hw
*hw
,
1460 struct sk_buff
*skb
, bool is_enc
)
1462 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1463 u8 mac_hdr_len
= ieee80211_get_hdrlen_from_skb(skb
);
1464 u8 encrypt_header_len
= 0;
1467 switch (rtlpriv
->sec
.pairwise_enc_algorithm
) {
1468 case WEP40_ENCRYPTION
:
1469 case WEP104_ENCRYPTION
:
1470 encrypt_header_len
= 4;/*WEP_IV_LEN*/
1472 case TKIP_ENCRYPTION
:
1473 encrypt_header_len
= 8;/*TKIP_IV_LEN*/
1475 case AESCCMP_ENCRYPTION
:
1476 encrypt_header_len
= 8;/*CCMP_HDR_LEN;*/
1482 offset
= mac_hdr_len
+ SNAP_SIZE
;
1484 offset
+= encrypt_header_len
;
1486 return skb
->data
+ offset
;
1489 /*should call before software enc*/
1490 u8
rtl_is_special_data(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
,
1493 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1494 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1495 __le16 fc
= rtl_get_fc(skb
);
1497 const u8
*ether_type_ptr
;
1498 const struct iphdr
*ip
;
1500 if (!ieee80211_is_data(fc
))
1503 ether_type_ptr
= rtl_skb_ether_type_ptr(hw
, skb
, is_enc
);
1504 ether_type
= be16_to_cpup((__be16
*)ether_type_ptr
);
1506 if (ether_type
== ETH_P_IP
) {
1507 ip
= (struct iphdr
*)((u8
*)ether_type_ptr
+
1509 if (ip
->protocol
== IPPROTO_UDP
) {
1510 struct udphdr
*udp
= (struct udphdr
*)((u8
*)ip
+
1512 if (((((u8
*)udp
)[1] == 68) &&
1513 (((u8
*)udp
)[3] == 67)) ||
1514 ((((u8
*)udp
)[1] == 67) &&
1515 (((u8
*)udp
)[3] == 68))) {
1516 /* 68 : UDP BOOTP client
1517 * 67 : UDP BOOTP server
1519 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
),
1520 DBG_DMESG
, "dhcp %s !!\n",
1521 (is_tx
) ? "Tx" : "Rx");
1524 setup_special_tx(rtlpriv
, ppsc
,
1530 } else if (ether_type
== ETH_P_ARP
) {
1532 setup_special_tx(rtlpriv
, ppsc
, PACKET_ARP
);
1535 } else if (ether_type
== ETH_P_PAE
) {
1536 /* EAPOL is seen as in-4way */
1537 rtlpriv
->btcoexist
.btc_info
.in_4way
= true;
1538 rtlpriv
->btcoexist
.btc_info
.in_4way_ts
= jiffies
;
1539 rtlpriv
->btcoexist
.btc_info
.in_4way_ts
= jiffies
;
1541 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1542 "802.1X %s EAPOL pkt!!\n", (is_tx
) ? "Tx" : "Rx");
1545 rtlpriv
->ra
.is_special_data
= true;
1547 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1549 setup_special_tx(rtlpriv
, ppsc
, PACKET_EAPOL
);
1553 } else if (ether_type
== ETH_P_IPV6
) {
1554 /* TODO: Handle any IPv6 cases that need special handling.
1555 * For now, always return false
1561 rtlpriv
->ra
.is_special_data
= false;
1565 bool rtl_is_tx_report_skb(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1568 const u8
*ether_type_ptr
;
1570 ether_type_ptr
= rtl_skb_ether_type_ptr(hw
, skb
, true);
1571 ether_type
= be16_to_cpup((__be16
*)ether_type_ptr
);
1574 if (ether_type
== ETH_P_PAE
)
1580 static u16
rtl_get_tx_report_sn(struct ieee80211_hw
*hw
)
1582 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1583 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1587 * SW_DEFINE[11:8] are reserved (driver fills zeros)
1588 * SW_DEFINE[7:2] are used by driver
1589 * SW_DEFINE[1:0] are reserved for firmware (driver fills zeros)
1591 sn
= (atomic_inc_return(&tx_report
->sn
) & 0x003F) << 2;
1593 tx_report
->last_sent_sn
= sn
;
1594 tx_report
->last_sent_time
= jiffies
;
1596 RT_TRACE(rtlpriv
, COMP_TX_REPORT
, DBG_DMESG
,
1597 "Send TX-Report sn=0x%X\n", sn
);
1602 void rtl_get_tx_report(struct rtl_tcb_desc
*ptcb_desc
, u8
*pdesc
,
1603 struct ieee80211_hw
*hw
)
1605 if (ptcb_desc
->use_spe_rpt
) {
1606 u16 sn
= rtl_get_tx_report_sn(hw
);
1608 SET_TX_DESC_SPE_RPT(pdesc
, 1);
1609 SET_TX_DESC_SW_DEFINE(pdesc
, sn
);
1613 void rtl_tx_report_handler(struct ieee80211_hw
*hw
, u8
*tmp_buf
, u8 c2h_cmd_len
)
1615 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1616 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1620 if (rtlpriv
->cfg
->spec_ver
& RTL_SPEC_NEW_FW_C2H
) {
1622 st
= tmp_buf
[7] & 0xC0;
1623 retry
= tmp_buf
[8] & 0x3F;
1625 sn
= ((tmp_buf
[7] & 0x0F) << 8) | tmp_buf
[6];
1626 st
= tmp_buf
[0] & 0xC0;
1627 retry
= tmp_buf
[2] & 0x3F;
1630 tx_report
->last_recv_sn
= sn
;
1632 RT_TRACE(rtlpriv
, COMP_TX_REPORT
, DBG_DMESG
,
1633 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
1637 bool rtl_check_tx_report_acked(struct ieee80211_hw
*hw
)
1639 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1640 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1642 if (tx_report
->last_sent_sn
== tx_report
->last_recv_sn
)
1645 if (time_before(tx_report
->last_sent_time
+ 3 * HZ
, jiffies
)) {
1646 RT_TRACE(rtlpriv
, COMP_TX_REPORT
, DBG_WARNING
,
1647 "Check TX-Report timeout!! s_sn=0x%X r_sn=0x%X\n",
1648 tx_report
->last_sent_sn
, tx_report
->last_recv_sn
);
1649 return true; /* 3 sec. (timeout) seen as acked */
1655 void rtl_wait_tx_report_acked(struct ieee80211_hw
*hw
, u32 wait_ms
)
1657 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1660 for (i
= 0; i
< wait_ms
; i
++) {
1661 if (rtl_check_tx_report_acked(hw
))
1663 usleep_range(1000, 2000);
1664 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1665 "Wait 1ms (%d/%d) to disable key.\n", i
, wait_ms
);
1669 u32
rtl_get_hal_edca_param(struct ieee80211_hw
*hw
,
1670 struct ieee80211_vif
*vif
,
1671 enum wireless_mode wirelessmode
,
1672 struct ieee80211_tx_queue_params
*param
)
1678 /* AIFS = AIFSN * slot time + SIFS */
1679 switch (wirelessmode
) {
1680 case WIRELESS_MODE_A
:
1681 case WIRELESS_MODE_N_24G
:
1682 case WIRELESS_MODE_N_5G
:
1683 case WIRELESS_MODE_AC_5G
:
1684 case WIRELESS_MODE_AC_24G
:
1688 case WIRELESS_MODE_G
:
1689 slottime
= (vif
->bss_conf
.use_short_slot
? 9 : 20);
1695 reg
|= (param
->txop
& 0x7FF) << 16;
1696 reg
|= (fls(param
->cw_max
) & 0xF) << 12;
1697 reg
|= (fls(param
->cw_min
) & 0xF) << 8;
1698 reg
|= (param
->aifs
& 0x0F) * slottime
+ sifstime
;
1703 /*********************************************************
1705 * functions called by core.c
1707 *********************************************************/
1708 int rtl_tx_agg_start(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1709 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
1711 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1712 struct rtl_tid_data
*tid_data
;
1713 struct rtl_sta_info
*sta_entry
= NULL
;
1718 if (unlikely(tid
>= MAX_TID_COUNT
))
1721 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1724 tid_data
= &sta_entry
->tids
[tid
];
1726 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1727 "on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1728 tid_data
->seq_number
);
1730 *ssn
= tid_data
->seq_number
;
1731 tid_data
->agg
.agg_state
= RTL_AGG_START
;
1733 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1737 int rtl_tx_agg_stop(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1738 struct ieee80211_sta
*sta
, u16 tid
)
1740 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1741 struct rtl_tid_data
*tid_data
;
1742 struct rtl_sta_info
*sta_entry
= NULL
;
1747 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1748 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1750 if (unlikely(tid
>= MAX_TID_COUNT
))
1753 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1754 tid_data
= &sta_entry
->tids
[tid
];
1755 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_STOP
;
1757 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1761 int rtl_rx_agg_start(struct ieee80211_hw
*hw
,
1762 struct ieee80211_sta
*sta
, u16 tid
)
1764 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1765 struct rtl_tid_data
*tid_data
;
1766 struct rtl_sta_info
*sta_entry
= NULL
;
1772 if (unlikely(tid
>= MAX_TID_COUNT
))
1775 if (rtlpriv
->cfg
->ops
->get_btc_status()) {
1776 rtlpriv
->btcoexist
.btc_ops
->btc_get_ampdu_cfg(rtlpriv
,
1783 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1786 tid_data
= &sta_entry
->tids
[tid
];
1788 RT_TRACE(rtlpriv
, COMP_RECV
, DBG_DMESG
,
1789 "on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1790 tid_data
->seq_number
);
1792 tid_data
->agg
.rx_agg_state
= RTL_RX_AGG_START
;
1796 int rtl_rx_agg_stop(struct ieee80211_hw
*hw
,
1797 struct ieee80211_sta
*sta
, u16 tid
)
1799 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1800 struct rtl_sta_info
*sta_entry
= NULL
;
1805 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1806 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1808 if (unlikely(tid
>= MAX_TID_COUNT
))
1811 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1812 sta_entry
->tids
[tid
].agg
.rx_agg_state
= RTL_RX_AGG_STOP
;
1817 int rtl_tx_agg_oper(struct ieee80211_hw
*hw
,
1818 struct ieee80211_sta
*sta
, u16 tid
)
1820 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1821 struct rtl_sta_info
*sta_entry
= NULL
;
1826 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1827 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1829 if (unlikely(tid
>= MAX_TID_COUNT
))
1832 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1833 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_OPERATIONAL
;
1838 void rtl_rx_ampdu_apply(struct rtl_priv
*rtlpriv
)
1840 struct rtl_btc_ops
*btc_ops
= rtlpriv
->btcoexist
.btc_ops
;
1841 u8 reject_agg
= 0, ctrl_agg_size
= 0, agg_size
= 0;
1843 if (rtlpriv
->cfg
->ops
->get_btc_status())
1844 btc_ops
->btc_get_ampdu_cfg(rtlpriv
, &reject_agg
,
1845 &ctrl_agg_size
, &agg_size
);
1847 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1848 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
1849 reject_agg
, ctrl_agg_size
, agg_size
);
1851 rtlpriv
->hw
->max_rx_aggregation_subframes
=
1852 (ctrl_agg_size
? agg_size
: IEEE80211_MAX_AMPDU_BUF
);
1855 /*********************************************************
1857 * wq & timer callback functions
1859 *********************************************************/
1860 /* this function is used for roaming */
1861 void rtl_beacon_statistic(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1863 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1864 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1866 if (rtlpriv
->mac80211
.opmode
!= NL80211_IFTYPE_STATION
)
1869 if (rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
)
1872 /* check if this really is a beacon */
1873 if (!ieee80211_is_beacon(hdr
->frame_control
) &&
1874 !ieee80211_is_probe_resp(hdr
->frame_control
))
1877 /* min. beacon length + FCS_LEN */
1878 if (skb
->len
<= 40 + FCS_LEN
)
1881 /* and only beacons from the associated BSSID, please */
1882 if (!ether_addr_equal(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
1885 rtlpriv
->link_info
.bcn_rx_inperiod
++;
1888 static void rtl_free_entries_from_scan_list(struct ieee80211_hw
*hw
)
1890 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1891 struct rtl_bssid_entry
*entry
, *next
;
1893 list_for_each_entry_safe(entry
, next
, &rtlpriv
->scan_list
.list
, list
) {
1894 list_del(&entry
->list
);
1896 rtlpriv
->scan_list
.num
--;
1900 void rtl_scan_list_expire(struct ieee80211_hw
*hw
)
1902 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1903 struct rtl_bssid_entry
*entry
, *next
;
1904 unsigned long flags
;
1906 spin_lock_irqsave(&rtlpriv
->locks
.scan_list_lock
, flags
);
1908 list_for_each_entry_safe(entry
, next
, &rtlpriv
->scan_list
.list
, list
) {
1910 if (jiffies_to_msecs(jiffies
- entry
->age
) < 180000)
1913 list_del(&entry
->list
);
1914 rtlpriv
->scan_list
.num
--;
1916 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1917 "BSSID=%pM is expire in scan list (total=%d)\n",
1918 entry
->bssid
, rtlpriv
->scan_list
.num
);
1922 spin_unlock_irqrestore(&rtlpriv
->locks
.scan_list_lock
, flags
);
1924 rtlpriv
->btcoexist
.btc_info
.ap_num
= rtlpriv
->scan_list
.num
;
1927 void rtl_collect_scan_list(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1929 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1930 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1931 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1932 unsigned long flags
;
1934 struct rtl_bssid_entry
*entry
;
1935 bool entry_found
= false;
1937 /* check if it is scanning */
1938 if (!mac
->act_scanning
)
1941 /* check if this really is a beacon */
1942 if (!ieee80211_is_beacon(hdr
->frame_control
) &&
1943 !ieee80211_is_probe_resp(hdr
->frame_control
))
1946 spin_lock_irqsave(&rtlpriv
->locks
.scan_list_lock
, flags
);
1948 list_for_each_entry(entry
, &rtlpriv
->scan_list
.list
, list
) {
1949 if (memcmp(entry
->bssid
, hdr
->addr3
, ETH_ALEN
) == 0) {
1950 list_del_init(&entry
->list
);
1952 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1953 "Update BSSID=%pM to scan list (total=%d)\n",
1954 hdr
->addr3
, rtlpriv
->scan_list
.num
);
1960 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
1965 memcpy(entry
->bssid
, hdr
->addr3
, ETH_ALEN
);
1966 rtlpriv
->scan_list
.num
++;
1968 RT_TRACE(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1969 "Add BSSID=%pM to scan list (total=%d)\n",
1970 hdr
->addr3
, rtlpriv
->scan_list
.num
);
1973 entry
->age
= jiffies
;
1975 list_add_tail(&entry
->list
, &rtlpriv
->scan_list
.list
);
1978 spin_unlock_irqrestore(&rtlpriv
->locks
.scan_list_lock
, flags
);
1981 void rtl_watchdog_wq_callback(void *data
)
1983 struct rtl_works
*rtlworks
= container_of_dwork_rtl(data
,
1986 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1987 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1988 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1989 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1990 bool busytraffic
= false;
1991 bool tx_busy_traffic
= false;
1992 bool rx_busy_traffic
= false;
1993 bool higher_busytraffic
= false;
1994 bool higher_busyrxtraffic
= false;
1996 u32 rx_cnt_inp4eriod
= 0;
1997 u32 tx_cnt_inp4eriod
= 0;
1998 u32 aver_rx_cnt_inperiod
= 0;
1999 u32 aver_tx_cnt_inperiod
= 0;
2000 u32 aver_tidtx_inperiod
[MAX_TID_COUNT
] = {0};
2001 u32 tidtx_inp4eriod
[MAX_TID_COUNT
] = {0};
2003 if (is_hal_stop(rtlhal
))
2006 /* <1> Determine if action frame is allowed */
2007 if (mac
->link_state
> MAC80211_NOLINK
) {
2008 if (mac
->cnt_after_linked
< 20)
2009 mac
->cnt_after_linked
++;
2011 mac
->cnt_after_linked
= 0;
2014 /* <2> to check if traffic busy, if
2015 * busytraffic we don't change channel
2017 if (mac
->link_state
>= MAC80211_LINKED
) {
2018 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
2019 for (idx
= 0; idx
<= 2; idx
++) {
2020 rtlpriv
->link_info
.num_rx_in4period
[idx
] =
2021 rtlpriv
->link_info
.num_rx_in4period
[idx
+ 1];
2022 rtlpriv
->link_info
.num_tx_in4period
[idx
] =
2023 rtlpriv
->link_info
.num_tx_in4period
[idx
+ 1];
2025 rtlpriv
->link_info
.num_rx_in4period
[3] =
2026 rtlpriv
->link_info
.num_rx_inperiod
;
2027 rtlpriv
->link_info
.num_tx_in4period
[3] =
2028 rtlpriv
->link_info
.num_tx_inperiod
;
2029 for (idx
= 0; idx
<= 3; idx
++) {
2031 rtlpriv
->link_info
.num_rx_in4period
[idx
];
2033 rtlpriv
->link_info
.num_tx_in4period
[idx
];
2035 aver_rx_cnt_inperiod
= rx_cnt_inp4eriod
/ 4;
2036 aver_tx_cnt_inperiod
= tx_cnt_inp4eriod
/ 4;
2038 /* (2) check traffic busy */
2039 if (aver_rx_cnt_inperiod
> 100 || aver_tx_cnt_inperiod
> 100) {
2041 if (aver_rx_cnt_inperiod
> aver_tx_cnt_inperiod
)
2042 rx_busy_traffic
= true;
2044 tx_busy_traffic
= false;
2047 /* Higher Tx/Rx data. */
2048 if (aver_rx_cnt_inperiod
> 4000 ||
2049 aver_tx_cnt_inperiod
> 4000) {
2050 higher_busytraffic
= true;
2052 /* Extremely high Rx data. */
2053 if (aver_rx_cnt_inperiod
> 5000)
2054 higher_busyrxtraffic
= true;
2057 /* check every tid's tx traffic */
2058 for (tid
= 0; tid
<= 7; tid
++) {
2059 for (idx
= 0; idx
<= 2; idx
++)
2060 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
] =
2061 rtlpriv
->link_info
.tidtx_in4period
[tid
]
2063 rtlpriv
->link_info
.tidtx_in4period
[tid
][3] =
2064 rtlpriv
->link_info
.tidtx_inperiod
[tid
];
2066 for (idx
= 0; idx
<= 3; idx
++)
2067 tidtx_inp4eriod
[tid
] +=
2068 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
];
2069 aver_tidtx_inperiod
[tid
] = tidtx_inp4eriod
[tid
] / 4;
2070 if (aver_tidtx_inperiod
[tid
] > 5000)
2071 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
2074 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
2078 /* PS is controlled by coex. */
2079 if (rtlpriv
->cfg
->ops
->get_btc_status() &&
2080 rtlpriv
->btcoexist
.btc_ops
->btc_is_bt_ctrl_lps(rtlpriv
))
2081 goto label_lps_done
;
2083 if (rtlpriv
->link_info
.num_rx_inperiod
+
2084 rtlpriv
->link_info
.num_tx_inperiod
> 8 ||
2085 rtlpriv
->link_info
.num_rx_inperiod
> 2)
2094 rtlpriv
->link_info
.num_rx_inperiod
= 0;
2095 rtlpriv
->link_info
.num_tx_inperiod
= 0;
2096 for (tid
= 0; tid
<= 7; tid
++)
2097 rtlpriv
->link_info
.tidtx_inperiod
[tid
] = 0;
2099 rtlpriv
->link_info
.busytraffic
= busytraffic
;
2100 rtlpriv
->link_info
.higher_busytraffic
= higher_busytraffic
;
2101 rtlpriv
->link_info
.rx_busy_traffic
= rx_busy_traffic
;
2102 rtlpriv
->link_info
.tx_busy_traffic
= tx_busy_traffic
;
2103 rtlpriv
->link_info
.higher_busyrxtraffic
= higher_busyrxtraffic
;
2105 rtlpriv
->stats
.txbytesunicast_inperiod
=
2106 rtlpriv
->stats
.txbytesunicast
-
2107 rtlpriv
->stats
.txbytesunicast_last
;
2108 rtlpriv
->stats
.rxbytesunicast_inperiod
=
2109 rtlpriv
->stats
.rxbytesunicast
-
2110 rtlpriv
->stats
.rxbytesunicast_last
;
2111 rtlpriv
->stats
.txbytesunicast_last
= rtlpriv
->stats
.txbytesunicast
;
2112 rtlpriv
->stats
.rxbytesunicast_last
= rtlpriv
->stats
.rxbytesunicast
;
2114 rtlpriv
->stats
.txbytesunicast_inperiod_tp
=
2115 (u32
)(rtlpriv
->stats
.txbytesunicast_inperiod
* 8 / 2 /
2117 rtlpriv
->stats
.rxbytesunicast_inperiod_tp
=
2118 (u32
)(rtlpriv
->stats
.rxbytesunicast_inperiod
* 8 / 2 /
2122 if (!rtlpriv
->cfg
->mod_params
->disable_watchdog
)
2123 rtlpriv
->cfg
->ops
->dm_watchdog(hw
);
2126 if (mac
->link_state
== MAC80211_LINKED
&&
2127 mac
->opmode
== NL80211_IFTYPE_STATION
) {
2128 if ((rtlpriv
->link_info
.bcn_rx_inperiod
+
2129 rtlpriv
->link_info
.num_rx_inperiod
) == 0) {
2130 rtlpriv
->link_info
.roam_times
++;
2131 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_DMESG
,
2132 "AP off for %d s\n",
2133 (rtlpriv
->link_info
.roam_times
* 2));
2135 /* if we can't recv beacon for 10s,
2136 * we should reconnect this AP
2138 if (rtlpriv
->link_info
.roam_times
>= 5) {
2139 pr_err("AP off, try to reconnect now\n");
2140 rtlpriv
->link_info
.roam_times
= 0;
2141 ieee80211_connection_loss(
2142 rtlpriv
->mac80211
.vif
);
2145 rtlpriv
->link_info
.roam_times
= 0;
2149 if (rtlpriv
->cfg
->ops
->get_btc_status())
2150 rtlpriv
->btcoexist
.btc_ops
->btc_periodical(rtlpriv
);
2152 if (rtlpriv
->btcoexist
.btc_info
.in_4way
) {
2153 if (time_after(jiffies
, rtlpriv
->btcoexist
.btc_info
.in_4way_ts
+
2154 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME
)))
2155 rtlpriv
->btcoexist
.btc_info
.in_4way
= false;
2158 rtlpriv
->link_info
.bcn_rx_inperiod
= 0;
2161 rtl_scan_list_expire(hw
);
2164 void rtl_watch_dog_timer_callback(struct timer_list
*t
)
2166 struct rtl_priv
*rtlpriv
= from_timer(rtlpriv
, t
, works
.watchdog_timer
);
2168 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
2169 &rtlpriv
->works
.watchdog_wq
, 0);
2171 mod_timer(&rtlpriv
->works
.watchdog_timer
,
2172 jiffies
+ MSECS(RTL_WATCH_DOG_TIME
));
2175 void rtl_fwevt_wq_callback(void *data
)
2177 struct rtl_works
*rtlworks
=
2178 container_of_dwork_rtl(data
, struct rtl_works
, fwevt_wq
);
2179 struct ieee80211_hw
*hw
= rtlworks
->hw
;
2180 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2182 rtlpriv
->cfg
->ops
->c2h_command_handle(hw
);
2185 void rtl_c2hcmd_enqueue(struct ieee80211_hw
*hw
, u8 tag
, u8 len
, u8
*val
)
2187 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2188 unsigned long flags
;
2189 struct rtl_c2hcmd
*c2hcmd
;
2191 c2hcmd
= kmalloc(sizeof(*c2hcmd
),
2192 in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
);
2197 c2hcmd
->val
= kmalloc(len
,
2198 in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
);
2206 memcpy(c2hcmd
->val
, val
, len
);
2209 spin_lock_irqsave(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2211 list_add_tail(&c2hcmd
->list
, &rtlpriv
->c2hcmd_list
);
2213 spin_unlock_irqrestore(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2216 queue_delayed_work(rtlpriv
->works
.rtl_wq
, &rtlpriv
->works
.c2hcmd_wq
, 0);
2224 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_WARNING
,
2225 "C2H cmd enqueue fail.\n");
2228 void rtl_c2hcmd_launcher(struct ieee80211_hw
*hw
, int exec
)
2230 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2231 unsigned long flags
;
2232 struct rtl_c2hcmd
*c2hcmd
;
2235 for (i
= 0; i
< 200; i
++) {
2236 /* dequeue a task */
2237 spin_lock_irqsave(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2239 c2hcmd
= list_first_entry_or_null(&rtlpriv
->c2hcmd_list
,
2240 struct rtl_c2hcmd
, list
);
2243 list_del(&c2hcmd
->list
);
2245 spin_unlock_irqrestore(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2251 if (rtlpriv
->cfg
->ops
->c2h_content_parsing
&& exec
)
2252 rtlpriv
->cfg
->ops
->c2h_content_parsing(hw
,
2253 c2hcmd
->tag
, c2hcmd
->len
, c2hcmd
->val
);
2262 void rtl_c2hcmd_wq_callback(void *data
)
2264 struct rtl_works
*rtlworks
= container_of_dwork_rtl(data
,
2267 struct ieee80211_hw
*hw
= rtlworks
->hw
;
2269 rtl_c2hcmd_launcher(hw
, 1);
2272 void rtl_easy_concurrent_retrytimer_callback(struct timer_list
*t
)
2274 struct rtl_priv
*rtlpriv
=
2275 from_timer(rtlpriv
, t
, works
.dualmac_easyconcurrent_retrytimer
);
2276 struct ieee80211_hw
*hw
= rtlpriv
->hw
;
2277 struct rtl_priv
*buddy_priv
= rtlpriv
->buddy_priv
;
2282 rtlpriv
->cfg
->ops
->dualmac_easy_concurrent(hw
);
2285 /*********************************************************
2287 * frame process functions
2289 *********************************************************/
2290 u8
*rtl_find_ie(u8
*data
, unsigned int len
, u8 ie
)
2292 struct ieee80211_mgmt
*mgmt
= (void *)data
;
2295 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
2298 if (pos
+ 2 + pos
[1] > end
)
2309 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
2310 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
2311 static struct sk_buff
*rtl_make_smps_action(struct ieee80211_hw
*hw
,
2312 enum ieee80211_smps_mode smps
,
2315 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2316 struct sk_buff
*skb
;
2317 struct ieee80211_mgmt
*action_frame
;
2319 /* 27 = header + category + action + smps mode */
2320 skb
= dev_alloc_skb(27 + hw
->extra_tx_headroom
);
2324 skb_reserve(skb
, hw
->extra_tx_headroom
);
2325 action_frame
= skb_put_zero(skb
, 27);
2326 memcpy(action_frame
->da
, da
, ETH_ALEN
);
2327 memcpy(action_frame
->sa
, rtlefuse
->dev_addr
, ETH_ALEN
);
2328 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
2329 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2330 IEEE80211_STYPE_ACTION
);
2331 action_frame
->u
.action
.category
= WLAN_CATEGORY_HT
;
2332 action_frame
->u
.action
.u
.ht_smps
.action
= WLAN_HT_ACTION_SMPS
;
2334 case IEEE80211_SMPS_AUTOMATIC
:/* 0 */
2335 case IEEE80211_SMPS_NUM_MODES
:/* 4 */
2338 case IEEE80211_SMPS_OFF
:/* 1 */ /*MIMO_PS_NOLIMIT*/
2339 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
2340 WLAN_HT_SMPS_CONTROL_DISABLED
;/* 0 */
2342 case IEEE80211_SMPS_STATIC
:/* 2 */ /*MIMO_PS_STATIC*/
2343 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
2344 WLAN_HT_SMPS_CONTROL_STATIC
;/* 1 */
2346 case IEEE80211_SMPS_DYNAMIC
:/* 3 */ /*MIMO_PS_DYNAMIC*/
2347 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
2348 WLAN_HT_SMPS_CONTROL_DYNAMIC
;/* 3 */
2355 int rtl_send_smps_action(struct ieee80211_hw
*hw
,
2356 struct ieee80211_sta
*sta
,
2357 enum ieee80211_smps_mode smps
)
2359 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2360 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2361 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2362 struct sk_buff
*skb
= NULL
;
2363 struct rtl_tcb_desc tcb_desc
;
2364 u8 bssid
[ETH_ALEN
] = {0};
2366 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
2368 if (rtlpriv
->mac80211
.act_scanning
)
2374 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
2377 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
2380 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_AP
)
2381 memcpy(bssid
, rtlpriv
->efuse
.dev_addr
, ETH_ALEN
);
2383 memcpy(bssid
, rtlpriv
->mac80211
.bssid
, ETH_ALEN
);
2385 skb
= rtl_make_smps_action(hw
, smps
, sta
->addr
, bssid
);
2386 /* this is a type = mgmt * stype = action frame */
2388 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2389 struct rtl_sta_info
*sta_entry
=
2390 (struct rtl_sta_info
*)sta
->drv_priv
;
2391 sta_entry
->mimo_ps
= smps
;
2392 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */
2394 info
->control
.rates
[0].idx
= 0;
2395 info
->band
= hw
->conf
.chandef
.chan
->band
;
2396 rtlpriv
->intf_ops
->adapter_tx(hw
, sta
, skb
, &tcb_desc
);
2404 void rtl_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
2406 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2407 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2408 enum io_type iotype
;
2410 if (!is_hal_stop(rtlhal
)) {
2411 switch (operation
) {
2412 case SCAN_OPT_BACKUP
:
2413 iotype
= IO_CMD_PAUSE_DM_BY_SCAN
;
2414 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
2418 case SCAN_OPT_RESTORE
:
2419 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
2420 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
2425 pr_err("Unknown Scan Backup operation.\n");
2431 /* because mac80211 have issues when can receive del ba
2432 * so here we just make a fake del_ba if we receive a ba_req
2433 * but rx_agg was opened to let mac80211 release some ba
2434 * related resources, so please this del_ba for tx
2436 struct sk_buff
*rtl_make_del_ba(struct ieee80211_hw
*hw
,
2437 u8
*sa
, u8
*bssid
, u16 tid
)
2439 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2440 struct sk_buff
*skb
;
2441 struct ieee80211_mgmt
*action_frame
;
2444 /* 27 = header + category + action + smps mode */
2445 skb
= dev_alloc_skb(34 + hw
->extra_tx_headroom
);
2449 skb_reserve(skb
, hw
->extra_tx_headroom
);
2450 action_frame
= skb_put_zero(skb
, 34);
2451 memcpy(action_frame
->sa
, sa
, ETH_ALEN
);
2452 memcpy(action_frame
->da
, rtlefuse
->dev_addr
, ETH_ALEN
);
2453 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
2454 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2455 IEEE80211_STYPE_ACTION
);
2456 action_frame
->u
.action
.category
= WLAN_CATEGORY_BACK
;
2457 action_frame
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
2458 params
= (u16
)(1 << 11); /* bit 11 initiator */
2459 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
2461 action_frame
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
2462 action_frame
->u
.action
.u
.delba
.reason_code
=
2463 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT
);
2468 bool rtl_check_beacon_key(struct ieee80211_hw
*hw
, void *data
, unsigned int len
)
2470 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2471 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2472 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2473 struct ieee80211_hdr
*hdr
= data
;
2474 struct ieee80211_ht_cap
*ht_cap_ie
;
2475 struct ieee80211_ht_operation
*ht_oper_ie
= NULL
;
2476 struct rtl_beacon_keys bcn_key
= {};
2477 struct rtl_beacon_keys
*cur_bcn_key
;
2485 if (mac
->opmode
!= NL80211_IFTYPE_STATION
)
2488 /* check if this really is a beacon*/
2489 if (!ieee80211_is_beacon(hdr
->frame_control
))
2492 /* min. beacon length + FCS_LEN */
2493 if (len
<= 40 + FCS_LEN
)
2496 cur_bcn_key
= &mac
->cur_beacon_keys
;
2498 if (rtlpriv
->mac80211
.link_state
== MAC80211_NOLINK
) {
2499 if (cur_bcn_key
->valid
) {
2500 cur_bcn_key
->valid
= false;
2501 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_LOUD
,
2502 "Reset cur_beacon_keys.valid to false!\n");
2507 /* and only beacons from the associated BSSID, please */
2508 if (!ether_addr_equal(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
2511 /***** Parsing DS Param IE ******/
2512 ds_param
= rtl_find_ie(data
, len
- FCS_LEN
, WLAN_EID_DS_PARAMS
);
2514 if (ds_param
&& !(ds_param
[1] < sizeof(*ds_param
))) {
2515 ds_param_len
= ds_param
[1];
2516 bcn_key
.bcn_channel
= ds_param
[2];
2521 /***** Parsing HT Cap. IE ******/
2522 ht_cap
= rtl_find_ie(data
, len
- FCS_LEN
, WLAN_EID_HT_CAPABILITY
);
2524 if (ht_cap
&& !(ht_cap
[1] < sizeof(*ht_cap
))) {
2525 ht_cap_len
= ht_cap
[1];
2526 ht_cap_ie
= (struct ieee80211_ht_cap
*)&ht_cap
[2];
2527 bcn_key
.ht_cap_info
= ht_cap_ie
->cap_info
;
2532 /***** Parsing HT Info. IE ******/
2533 ht_oper
= rtl_find_ie(data
, len
- FCS_LEN
, WLAN_EID_HT_OPERATION
);
2535 if (ht_oper
&& !(ht_oper
[1] < sizeof(*ht_oper
))) {
2536 ht_oper_len
= ht_oper
[1];
2537 ht_oper_ie
= (struct ieee80211_ht_operation
*)&ht_oper
[2];
2542 /* update bcn_key */
2544 if (!ds_param
&& ht_oper
&& ht_oper_ie
)
2545 bcn_key
.bcn_channel
= ht_oper_ie
->primary_chan
;
2547 if (ht_oper
&& ht_oper_ie
)
2548 bcn_key
.ht_info_infos_0_sco
= ht_oper_ie
->ht_param
& 0x03;
2550 bcn_key
.valid
= true;
2552 /* update cur_beacon_keys or compare beacon key */
2553 if (rtlpriv
->mac80211
.link_state
!= MAC80211_LINKED
&&
2554 rtlpriv
->mac80211
.link_state
!= MAC80211_LINKED_SCANNING
)
2557 if (!cur_bcn_key
->valid
) {
2558 /* update cur_beacon_keys */
2559 memcpy(cur_bcn_key
, &bcn_key
, sizeof(bcn_key
));
2560 cur_bcn_key
->valid
= true;
2562 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_LOUD
,
2563 "Beacon key update!ch=%d, ht_cap_info=0x%x, sco=0x%x\n",
2564 cur_bcn_key
->bcn_channel
,
2565 cur_bcn_key
->ht_cap_info
,
2566 cur_bcn_key
->ht_info_infos_0_sco
);
2570 /* compare beacon key */
2571 if (!memcmp(cur_bcn_key
, &bcn_key
, sizeof(bcn_key
))) {
2572 /* same beacon key */
2573 mac
->new_beacon_cnt
= 0;
2577 if (cur_bcn_key
->bcn_channel
== bcn_key
.bcn_channel
&&
2578 cur_bcn_key
->ht_cap_info
== bcn_key
.ht_cap_info
) {
2579 /* Beacon HT info IE, secondary channel offset check */
2581 if (cur_bcn_key
->ht_info_infos_0_sco
>
2582 bcn_key
.ht_info_infos_0_sco
) {
2583 /* Not a new beacon */
2584 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2585 "Beacon BW change! sco:0x%x -> 0x%x\n",
2586 cur_bcn_key
->ht_info_infos_0_sco
,
2587 bcn_key
.ht_info_infos_0_sco
);
2589 cur_bcn_key
->ht_info_infos_0_sco
=
2590 bcn_key
.ht_info_infos_0_sco
;
2593 if (rtlphy
->max_ht_chan_bw
>= HT_CHANNEL_WIDTH_20_40
) {
2594 /* Not a new beacon */
2595 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2596 "Beacon BW change! sco:0x%x -> 0x%x\n",
2597 cur_bcn_key
->ht_info_infos_0_sco
,
2598 bcn_key
.ht_info_infos_0_sco
);
2600 cur_bcn_key
->ht_info_infos_0_sco
=
2601 bcn_key
.ht_info_infos_0_sco
;
2603 mac
->new_beacon_cnt
++;
2607 mac
->new_beacon_cnt
++;
2610 if (mac
->new_beacon_cnt
== 1) {
2611 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2612 "Get new beacon.\n");
2613 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2614 "Cur : ch=%d, ht_cap=0x%x, sco=0x%x\n",
2615 cur_bcn_key
->bcn_channel
,
2616 cur_bcn_key
->ht_cap_info
,
2617 cur_bcn_key
->ht_info_infos_0_sco
);
2618 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2619 "New RX : ch=%d, ht_cap=0x%x, sco=0x%x\n",
2620 bcn_key
.bcn_channel
,
2621 bcn_key
.ht_cap_info
,
2622 bcn_key
.ht_info_infos_0_sco
);
2624 } else if (mac
->new_beacon_cnt
> 1) {
2625 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2626 "new beacon cnt: %d\n",
2627 mac
->new_beacon_cnt
);
2630 if (mac
->new_beacon_cnt
> 3) {
2631 ieee80211_connection_loss(rtlpriv
->mac80211
.vif
);
2632 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2633 "new beacon cnt >3, disconnect !\n");
2641 /*********************************************************
2645 *********************************************************/
2646 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw
*hw
,
2647 struct octet_string vendor_ie
)
2649 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2650 bool matched
= false;
2651 static u8 athcap_1
[] = { 0x00, 0x03, 0x7F };
2652 static u8 athcap_2
[] = { 0x00, 0x13, 0x74 };
2653 static u8 broadcap_1
[] = { 0x00, 0x10, 0x18 };
2654 static u8 broadcap_2
[] = { 0x00, 0x0a, 0xf7 };
2655 static u8 broadcap_3
[] = { 0x00, 0x05, 0xb5 };
2656 static u8 racap
[] = { 0x00, 0x0c, 0x43 };
2657 static u8 ciscocap
[] = { 0x00, 0x40, 0x96 };
2658 static u8 marvcap
[] = { 0x00, 0x50, 0x43 };
2660 if (memcmp(vendor_ie
.octet
, athcap_1
, 3) == 0 ||
2661 memcmp(vendor_ie
.octet
, athcap_2
, 3) == 0) {
2662 rtlpriv
->mac80211
.vendor
= PEER_ATH
;
2664 } else if (memcmp(vendor_ie
.octet
, broadcap_1
, 3) == 0 ||
2665 memcmp(vendor_ie
.octet
, broadcap_2
, 3) == 0 ||
2666 memcmp(vendor_ie
.octet
, broadcap_3
, 3) == 0) {
2667 rtlpriv
->mac80211
.vendor
= PEER_BROAD
;
2669 } else if (memcmp(vendor_ie
.octet
, racap
, 3) == 0) {
2670 rtlpriv
->mac80211
.vendor
= PEER_RAL
;
2672 } else if (memcmp(vendor_ie
.octet
, ciscocap
, 3) == 0) {
2673 rtlpriv
->mac80211
.vendor
= PEER_CISCO
;
2675 } else if (memcmp(vendor_ie
.octet
, marvcap
, 3) == 0) {
2676 rtlpriv
->mac80211
.vendor
= PEER_MARV
;
2683 static bool rtl_find_221_ie(struct ieee80211_hw
*hw
, u8
*data
,
2686 struct ieee80211_mgmt
*mgmt
= (void *)data
;
2687 struct octet_string vendor_ie
;
2690 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
2693 if (pos
[0] == 221) {
2694 vendor_ie
.length
= pos
[1];
2695 vendor_ie
.octet
= &pos
[2];
2696 if (rtl_chk_vendor_ouisub(hw
, vendor_ie
))
2700 if (pos
+ 2 + pos
[1] > end
)
2708 void rtl_recognize_peer(struct ieee80211_hw
*hw
, u8
*data
, unsigned int len
)
2710 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2711 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2712 struct ieee80211_hdr
*hdr
= (void *)data
;
2713 u32 vendor
= PEER_UNKNOWN
;
2715 static u8 ap3_1
[3] = { 0x00, 0x14, 0xbf };
2716 static u8 ap3_2
[3] = { 0x00, 0x1a, 0x70 };
2717 static u8 ap3_3
[3] = { 0x00, 0x1d, 0x7e };
2718 static u8 ap4_1
[3] = { 0x00, 0x90, 0xcc };
2719 static u8 ap4_2
[3] = { 0x00, 0x0e, 0x2e };
2720 static u8 ap4_3
[3] = { 0x00, 0x18, 0x02 };
2721 static u8 ap4_4
[3] = { 0x00, 0x17, 0x3f };
2722 static u8 ap4_5
[3] = { 0x00, 0x1c, 0xdf };
2723 static u8 ap5_1
[3] = { 0x00, 0x1c, 0xf0 };
2724 static u8 ap5_2
[3] = { 0x00, 0x21, 0x91 };
2725 static u8 ap5_3
[3] = { 0x00, 0x24, 0x01 };
2726 static u8 ap5_4
[3] = { 0x00, 0x15, 0xe9 };
2727 static u8 ap5_5
[3] = { 0x00, 0x17, 0x9A };
2728 static u8 ap5_6
[3] = { 0x00, 0x18, 0xE7 };
2729 static u8 ap6_1
[3] = { 0x00, 0x17, 0x94 };
2730 static u8 ap7_1
[3] = { 0x00, 0x14, 0xa4 };
2732 if (mac
->opmode
!= NL80211_IFTYPE_STATION
)
2735 if (mac
->link_state
== MAC80211_NOLINK
) {
2736 mac
->vendor
= PEER_UNKNOWN
;
2740 if (mac
->cnt_after_linked
> 2)
2743 /* check if this really is a beacon */
2744 if (!ieee80211_is_beacon(hdr
->frame_control
))
2747 /* min. beacon length + FCS_LEN */
2748 if (len
<= 40 + FCS_LEN
)
2751 /* and only beacons from the associated BSSID, please */
2752 if (!ether_addr_equal_64bits(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
2755 if (rtl_find_221_ie(hw
, data
, len
))
2756 vendor
= mac
->vendor
;
2758 if ((memcmp(mac
->bssid
, ap5_1
, 3) == 0) ||
2759 (memcmp(mac
->bssid
, ap5_2
, 3) == 0) ||
2760 (memcmp(mac
->bssid
, ap5_3
, 3) == 0) ||
2761 (memcmp(mac
->bssid
, ap5_4
, 3) == 0) ||
2762 (memcmp(mac
->bssid
, ap5_5
, 3) == 0) ||
2763 (memcmp(mac
->bssid
, ap5_6
, 3) == 0) ||
2764 vendor
== PEER_ATH
) {
2766 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>ath find\n");
2767 } else if ((memcmp(mac
->bssid
, ap4_4
, 3) == 0) ||
2768 (memcmp(mac
->bssid
, ap4_5
, 3) == 0) ||
2769 (memcmp(mac
->bssid
, ap4_1
, 3) == 0) ||
2770 (memcmp(mac
->bssid
, ap4_2
, 3) == 0) ||
2771 (memcmp(mac
->bssid
, ap4_3
, 3) == 0) ||
2772 vendor
== PEER_RAL
) {
2773 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>ral find\n");
2775 } else if (memcmp(mac
->bssid
, ap6_1
, 3) == 0 ||
2776 vendor
== PEER_CISCO
) {
2777 vendor
= PEER_CISCO
;
2778 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>cisco find\n");
2779 } else if ((memcmp(mac
->bssid
, ap3_1
, 3) == 0) ||
2780 (memcmp(mac
->bssid
, ap3_2
, 3) == 0) ||
2781 (memcmp(mac
->bssid
, ap3_3
, 3) == 0) ||
2782 vendor
== PEER_BROAD
) {
2783 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>broad find\n");
2784 vendor
= PEER_BROAD
;
2785 } else if (memcmp(mac
->bssid
, ap7_1
, 3) == 0 ||
2786 vendor
== PEER_MARV
) {
2788 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>marv find\n");
2791 mac
->vendor
= vendor
;
2794 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2795 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2796 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2797 MODULE_LICENSE("GPL");
2798 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2800 struct rtl_global_var rtl_global_var
= {};
2802 int rtl_core_module_init(void)
2804 if (rtl_rate_control_register())
2805 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
2808 rtl_debugfs_add_topdir();
2810 /* init some global vars */
2811 INIT_LIST_HEAD(&rtl_global_var
.glb_priv_list
);
2812 spin_lock_init(&rtl_global_var
.glb_list_lock
);
2817 void rtl_core_module_exit(void)
2820 rtl_rate_control_unregister();
2822 /* remove debugfs */
2823 rtl_debugfs_remove_topdir();