1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
35 #include <linux/module.h>
36 #include <linux/udp.h>
39 *NOTICE!!!: This file will be very big, we should
40 *keep it clear under following roles:
42 *This file include following parts, so, if you add new
43 *functions into this file, please check which part it
44 *should includes. or check if you should add new part
47 *1) mac80211 init functions
48 *2) tx information functions
49 *3) functions called by core.c
50 *4) wq & timer callback functions
51 *5) frame process functions
58 /*********************************************************
60 * mac80211 init functions
62 *********************************************************/
63 static struct ieee80211_channel rtl_channeltable_2g
[] = {
64 {.center_freq
= 2412, .hw_value
= 1,},
65 {.center_freq
= 2417, .hw_value
= 2,},
66 {.center_freq
= 2422, .hw_value
= 3,},
67 {.center_freq
= 2427, .hw_value
= 4,},
68 {.center_freq
= 2432, .hw_value
= 5,},
69 {.center_freq
= 2437, .hw_value
= 6,},
70 {.center_freq
= 2442, .hw_value
= 7,},
71 {.center_freq
= 2447, .hw_value
= 8,},
72 {.center_freq
= 2452, .hw_value
= 9,},
73 {.center_freq
= 2457, .hw_value
= 10,},
74 {.center_freq
= 2462, .hw_value
= 11,},
75 {.center_freq
= 2467, .hw_value
= 12,},
76 {.center_freq
= 2472, .hw_value
= 13,},
77 {.center_freq
= 2484, .hw_value
= 14,},
80 static struct ieee80211_channel rtl_channeltable_5g
[] = {
81 {.center_freq
= 5180, .hw_value
= 36,},
82 {.center_freq
= 5200, .hw_value
= 40,},
83 {.center_freq
= 5220, .hw_value
= 44,},
84 {.center_freq
= 5240, .hw_value
= 48,},
85 {.center_freq
= 5260, .hw_value
= 52,},
86 {.center_freq
= 5280, .hw_value
= 56,},
87 {.center_freq
= 5300, .hw_value
= 60,},
88 {.center_freq
= 5320, .hw_value
= 64,},
89 {.center_freq
= 5500, .hw_value
= 100,},
90 {.center_freq
= 5520, .hw_value
= 104,},
91 {.center_freq
= 5540, .hw_value
= 108,},
92 {.center_freq
= 5560, .hw_value
= 112,},
93 {.center_freq
= 5580, .hw_value
= 116,},
94 {.center_freq
= 5600, .hw_value
= 120,},
95 {.center_freq
= 5620, .hw_value
= 124,},
96 {.center_freq
= 5640, .hw_value
= 128,},
97 {.center_freq
= 5660, .hw_value
= 132,},
98 {.center_freq
= 5680, .hw_value
= 136,},
99 {.center_freq
= 5700, .hw_value
= 140,},
100 {.center_freq
= 5745, .hw_value
= 149,},
101 {.center_freq
= 5765, .hw_value
= 153,},
102 {.center_freq
= 5785, .hw_value
= 157,},
103 {.center_freq
= 5805, .hw_value
= 161,},
104 {.center_freq
= 5825, .hw_value
= 165,},
107 static struct ieee80211_rate rtl_ratetable_2g
[] = {
108 {.bitrate
= 10, .hw_value
= 0x00,},
109 {.bitrate
= 20, .hw_value
= 0x01,},
110 {.bitrate
= 55, .hw_value
= 0x02,},
111 {.bitrate
= 110, .hw_value
= 0x03,},
112 {.bitrate
= 60, .hw_value
= 0x04,},
113 {.bitrate
= 90, .hw_value
= 0x05,},
114 {.bitrate
= 120, .hw_value
= 0x06,},
115 {.bitrate
= 180, .hw_value
= 0x07,},
116 {.bitrate
= 240, .hw_value
= 0x08,},
117 {.bitrate
= 360, .hw_value
= 0x09,},
118 {.bitrate
= 480, .hw_value
= 0x0a,},
119 {.bitrate
= 540, .hw_value
= 0x0b,},
122 static struct ieee80211_rate rtl_ratetable_5g
[] = {
123 {.bitrate
= 60, .hw_value
= 0x04,},
124 {.bitrate
= 90, .hw_value
= 0x05,},
125 {.bitrate
= 120, .hw_value
= 0x06,},
126 {.bitrate
= 180, .hw_value
= 0x07,},
127 {.bitrate
= 240, .hw_value
= 0x08,},
128 {.bitrate
= 360, .hw_value
= 0x09,},
129 {.bitrate
= 480, .hw_value
= 0x0a,},
130 {.bitrate
= 540, .hw_value
= 0x0b,},
133 static const struct ieee80211_supported_band rtl_band_2ghz
= {
134 .band
= NL80211_BAND_2GHZ
,
136 .channels
= rtl_channeltable_2g
,
137 .n_channels
= ARRAY_SIZE(rtl_channeltable_2g
),
139 .bitrates
= rtl_ratetable_2g
,
140 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_2g
),
145 static struct ieee80211_supported_band rtl_band_5ghz
= {
146 .band
= NL80211_BAND_5GHZ
,
148 .channels
= rtl_channeltable_5g
,
149 .n_channels
= ARRAY_SIZE(rtl_channeltable_5g
),
151 .bitrates
= rtl_ratetable_5g
,
152 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_5g
),
157 static const u8 tid_to_ac
[] = {
158 2, /* IEEE80211_AC_BE */
159 3, /* IEEE80211_AC_BK */
160 3, /* IEEE80211_AC_BK */
161 2, /* IEEE80211_AC_BE */
162 1, /* IEEE80211_AC_VI */
163 1, /* IEEE80211_AC_VI */
164 0, /* IEEE80211_AC_VO */
165 0, /* IEEE80211_AC_VO */
168 u8
rtl_tid_to_ac(u8 tid
)
170 return tid_to_ac
[tid
];
172 EXPORT_SYMBOL_GPL(rtl_tid_to_ac
);
174 static void _rtl_init_hw_ht_capab(struct ieee80211_hw
*hw
,
175 struct ieee80211_sta_ht_cap
*ht_cap
)
177 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
178 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
180 ht_cap
->ht_supported
= true;
181 ht_cap
->cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
182 IEEE80211_HT_CAP_SGI_40
|
183 IEEE80211_HT_CAP_SGI_20
|
184 IEEE80211_HT_CAP_DSSSCCK40
| IEEE80211_HT_CAP_MAX_AMSDU
;
186 if (rtlpriv
->rtlhal
.disable_amsdu_8k
)
187 ht_cap
->cap
&= ~IEEE80211_HT_CAP_MAX_AMSDU
;
190 *Maximum length of AMPDU that the STA can receive.
191 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
193 ht_cap
->ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
195 /*Minimum MPDU start spacing , */
196 ht_cap
->ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
198 ht_cap
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
200 /*hw->wiphy->bands[NL80211_BAND_2GHZ]
203 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
204 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
205 *if rx_ant >= 3 rx_mask[2]= 0xff;
206 *if BW_40 rx_mask[4]= 0x01;
207 *highest supported RX rate
209 if (rtlpriv
->dm
.supp_phymode_switch
) {
210 pr_info("Support phy mode switch\n");
212 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
213 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
214 ht_cap
->mcs
.rx_mask
[4] = 0x01;
216 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
218 if (get_rf_type(rtlphy
) == RF_1T2R
||
219 get_rf_type(rtlphy
) == RF_2T2R
) {
220 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
222 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
223 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
224 ht_cap
->mcs
.rx_mask
[4] = 0x01;
226 ht_cap
->mcs
.rx_highest
=
227 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
228 } else if (get_rf_type(rtlphy
) == RF_1T1R
) {
229 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "1T1R\n");
231 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
232 ht_cap
->mcs
.rx_mask
[1] = 0x00;
233 ht_cap
->mcs
.rx_mask
[4] = 0x01;
235 ht_cap
->mcs
.rx_highest
=
236 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7
);
241 static void _rtl_init_hw_vht_capab(struct ieee80211_hw
*hw
,
242 struct ieee80211_sta_vht_cap
*vht_cap
)
244 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
245 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
247 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
250 vht_cap
->vht_supported
= true;
252 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895
|
253 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991
|
254 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
|
255 IEEE80211_VHT_CAP_SHORT_GI_80
|
256 IEEE80211_VHT_CAP_TXSTBC
|
257 IEEE80211_VHT_CAP_RXSTBC_1
|
258 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
259 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
260 IEEE80211_VHT_CAP_HTC_VHT
|
261 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
|
262 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN
|
263 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN
|
266 mcs_map
= IEEE80211_VHT_MCS_SUPPORT_0_9
<< 0 |
267 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 2 |
268 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 4 |
269 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 6 |
270 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 8 |
271 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 10 |
272 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 12 |
273 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 14;
275 vht_cap
->vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
276 vht_cap
->vht_mcs
.rx_highest
=
277 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9
);
278 vht_cap
->vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
279 vht_cap
->vht_mcs
.tx_highest
=
280 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9
);
281 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
284 vht_cap
->vht_supported
= true;
286 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895
|
287 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991
|
288 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
|
289 IEEE80211_VHT_CAP_SHORT_GI_80
|
290 IEEE80211_VHT_CAP_TXSTBC
|
291 IEEE80211_VHT_CAP_RXSTBC_1
|
292 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
293 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
294 IEEE80211_VHT_CAP_HTC_VHT
|
295 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
|
296 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN
|
297 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN
|
300 mcs_map
= IEEE80211_VHT_MCS_SUPPORT_0_9
<< 0 |
301 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 2 |
302 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 4 |
303 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 6 |
304 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 8 |
305 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 10 |
306 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 12 |
307 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 14;
309 vht_cap
->vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
310 vht_cap
->vht_mcs
.rx_highest
=
311 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9
);
312 vht_cap
->vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
313 vht_cap
->vht_mcs
.tx_highest
=
314 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9
);
318 static void _rtl_init_mac80211(struct ieee80211_hw
*hw
)
320 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
321 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
322 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
323 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
324 struct ieee80211_supported_band
*sband
;
326 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&&
327 rtlhal
->bandset
== BAND_ON_BOTH
) {
329 /* <1> use mac->bands as mem for hw->wiphy->bands */
330 sband
= &(rtlmac
->bands
[NL80211_BAND_2GHZ
]);
332 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
333 * to default value(1T1R) */
334 memcpy(&(rtlmac
->bands
[NL80211_BAND_2GHZ
]), &rtl_band_2ghz
,
335 sizeof(struct ieee80211_supported_band
));
337 /* <3> init ht cap base on ant_num */
338 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
340 /* <4> set mac->sband to wiphy->sband */
341 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = sband
;
344 /* <1> use mac->bands as mem for hw->wiphy->bands */
345 sband
= &(rtlmac
->bands
[NL80211_BAND_5GHZ
]);
347 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
348 * to default value(1T1R) */
349 memcpy(&(rtlmac
->bands
[NL80211_BAND_5GHZ
]), &rtl_band_5ghz
,
350 sizeof(struct ieee80211_supported_band
));
352 /* <3> init ht cap base on ant_num */
353 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
355 _rtl_init_hw_vht_capab(hw
, &sband
->vht_cap
);
356 /* <4> set mac->sband to wiphy->sband */
357 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = sband
;
359 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
360 /* <1> use mac->bands as mem for hw->wiphy->bands */
361 sband
= &(rtlmac
->bands
[NL80211_BAND_2GHZ
]);
363 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
364 * to default value(1T1R) */
365 memcpy(&(rtlmac
->bands
[NL80211_BAND_2GHZ
]),
367 sizeof(struct ieee80211_supported_band
));
369 /* <3> init ht cap base on ant_num */
370 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
372 /* <4> set mac->sband to wiphy->sband */
373 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = sband
;
374 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
375 /* <1> use mac->bands as mem for hw->wiphy->bands */
376 sband
= &(rtlmac
->bands
[NL80211_BAND_5GHZ
]);
378 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
379 * to default value(1T1R) */
380 memcpy(&(rtlmac
->bands
[NL80211_BAND_5GHZ
]),
382 sizeof(struct ieee80211_supported_band
));
384 /* <3> init ht cap base on ant_num */
385 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
387 _rtl_init_hw_vht_capab(hw
, &sband
->vht_cap
);
388 /* <4> set mac->sband to wiphy->sband */
389 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = sband
;
391 pr_err("Err BAND %d\n",
392 rtlhal
->current_bandtype
);
395 /* <5> set hw caps */
396 ieee80211_hw_set(hw
, SIGNAL_DBM
);
397 ieee80211_hw_set(hw
, RX_INCLUDES_FCS
);
398 ieee80211_hw_set(hw
, AMPDU_AGGREGATION
);
399 ieee80211_hw_set(hw
, CONNECTION_MONITOR
);
400 ieee80211_hw_set(hw
, MFP_CAPABLE
);
401 ieee80211_hw_set(hw
, REPORTS_TX_ACK_STATUS
);
403 /* swlps or hwlps has been set in diff chip in init_sw_vars */
404 if (rtlpriv
->psc
.swctrl_lps
) {
405 ieee80211_hw_set(hw
, SUPPORTS_PS
);
406 ieee80211_hw_set(hw
, PS_NULLFUNC_STACK
);
408 hw
->wiphy
->interface_modes
=
409 BIT(NL80211_IFTYPE_AP
) |
410 BIT(NL80211_IFTYPE_STATION
) |
411 BIT(NL80211_IFTYPE_ADHOC
) |
412 BIT(NL80211_IFTYPE_MESH_POINT
) |
413 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
414 BIT(NL80211_IFTYPE_P2P_GO
);
415 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
417 hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
419 hw
->wiphy
->rts_threshold
= 2347;
422 hw
->extra_tx_headroom
= RTL_TX_HEADER_SIZE
;
424 /* TODO: Correct this value for our hw */
425 /* TODO: define these hard code value */
426 hw
->max_listen_interval
= 10;
427 hw
->max_rate_tries
= 4;
428 /* hw->max_rates = 1; */
429 hw
->sta_data_size
= sizeof(struct rtl_sta_info
);
431 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
433 if (rtlpriv
->psc
.wo_wlan_mode
) {
434 if (rtlpriv
->psc
.wo_wlan_mode
& WAKE_ON_MAGIC_PACKET
)
435 rtlpriv
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
;
436 if (rtlpriv
->psc
.wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) {
437 rtlpriv
->wowlan
.n_patterns
=
438 MAX_SUPPORT_WOL_PATTERN_NUM
;
439 rtlpriv
->wowlan
.pattern_min_len
= MIN_WOL_PATTERN_SIZE
;
440 rtlpriv
->wowlan
.pattern_max_len
= MAX_WOL_PATTERN_SIZE
;
442 hw
->wiphy
->wowlan
= &rtlpriv
->wowlan
;
446 /* <6> mac address */
447 if (is_valid_ether_addr(rtlefuse
->dev_addr
)) {
448 SET_IEEE80211_PERM_ADDR(hw
, rtlefuse
->dev_addr
);
450 u8 rtlmac1
[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
451 get_random_bytes((rtlmac1
+ (ETH_ALEN
- 1)), 1);
452 SET_IEEE80211_PERM_ADDR(hw
, rtlmac1
);
456 static void _rtl_init_deferred_work(struct ieee80211_hw
*hw
)
458 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
461 setup_timer(&rtlpriv
->works
.watchdog_timer
,
462 rtl_watch_dog_timer_callback
, (unsigned long)hw
);
463 setup_timer(&rtlpriv
->works
.dualmac_easyconcurrent_retrytimer
,
464 rtl_easy_concurrent_retrytimer_callback
, (unsigned long)hw
);
466 rtlpriv
->works
.hw
= hw
;
467 rtlpriv
->works
.rtl_wq
= alloc_workqueue("%s", 0, 0, rtlpriv
->cfg
->name
);
468 INIT_DELAYED_WORK(&rtlpriv
->works
.watchdog_wq
,
469 (void *)rtl_watchdog_wq_callback
);
470 INIT_DELAYED_WORK(&rtlpriv
->works
.ips_nic_off_wq
,
471 (void *)rtl_ips_nic_off_wq_callback
);
472 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_work
,
473 (void *)rtl_swlps_wq_callback
);
474 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_rfon_wq
,
475 (void *)rtl_swlps_rfon_wq_callback
);
476 INIT_DELAYED_WORK(&rtlpriv
->works
.fwevt_wq
,
477 (void *)rtl_fwevt_wq_callback
);
478 INIT_DELAYED_WORK(&rtlpriv
->works
.c2hcmd_wq
,
479 (void *)rtl_c2hcmd_wq_callback
);
483 void rtl_deinit_deferred_work(struct ieee80211_hw
*hw
)
485 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
487 del_timer_sync(&rtlpriv
->works
.watchdog_timer
);
489 cancel_delayed_work(&rtlpriv
->works
.watchdog_wq
);
490 cancel_delayed_work(&rtlpriv
->works
.ips_nic_off_wq
);
491 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
492 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
493 cancel_delayed_work(&rtlpriv
->works
.fwevt_wq
);
494 cancel_delayed_work(&rtlpriv
->works
.c2hcmd_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 pr_err("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
.c2hcmd_lock
);
563 spin_lock_init(&rtlpriv
->locks
.cck_and_rw_pagea_lock
);
564 spin_lock_init(&rtlpriv
->locks
.check_sendpkt_lock
);
565 spin_lock_init(&rtlpriv
->locks
.fw_ps_lock
);
566 spin_lock_init(&rtlpriv
->locks
.lps_lock
);
567 spin_lock_init(&rtlpriv
->locks
.iqk_lock
);
569 INIT_LIST_HEAD(&rtlpriv
->entry_list
);
570 INIT_LIST_HEAD(&rtlpriv
->c2hcmd_list
);
572 rtlmac
->link_state
= MAC80211_NOLINK
;
574 /* <6> init deferred work */
575 _rtl_init_deferred_work(hw
);
579 EXPORT_SYMBOL_GPL(rtl_init_core
);
581 void rtl_deinit_core(struct ieee80211_hw
*hw
)
583 rtl_c2hcmd_launcher(hw
, 0);
585 EXPORT_SYMBOL_GPL(rtl_deinit_core
);
587 void rtl_init_rx_config(struct ieee80211_hw
*hw
)
589 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
590 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
592 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*) (&mac
->rx_conf
));
594 EXPORT_SYMBOL_GPL(rtl_init_rx_config
);
596 /*********************************************************
598 * tx information functions
600 *********************************************************/
601 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw
*hw
,
602 struct rtl_tcb_desc
*tcb_desc
,
603 struct ieee80211_tx_info
*info
)
605 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
606 u8 rate_flag
= info
->control
.rates
[0].flags
;
608 tcb_desc
->use_shortpreamble
= false;
610 /* 1M can only use Long Preamble. 11B spec */
611 if (tcb_desc
->hw_rate
== rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE1M
])
613 else if (rate_flag
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
614 tcb_desc
->use_shortpreamble
= true;
619 static void _rtl_query_shortgi(struct ieee80211_hw
*hw
,
620 struct ieee80211_sta
*sta
,
621 struct rtl_tcb_desc
*tcb_desc
,
622 struct ieee80211_tx_info
*info
)
624 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
625 u8 rate_flag
= info
->control
.rates
[0].flags
;
626 u8 sgi_40
= 0, sgi_20
= 0, bw_40
= 0;
627 u8 sgi_80
= 0, bw_80
= 0;
628 tcb_desc
->use_shortgi
= false;
633 sgi_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
;
634 sgi_20
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
;
635 sgi_80
= sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SHORT_GI_80
;
637 if ((!sta
->ht_cap
.ht_supported
) && (!sta
->vht_cap
.vht_supported
))
640 if (!sgi_40
&& !sgi_20
)
643 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
646 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
647 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
648 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
649 bw_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
650 bw_80
= sta
->vht_cap
.vht_supported
;
655 tcb_desc
->use_shortgi
= true;
657 tcb_desc
->use_shortgi
= false;
660 tcb_desc
->use_shortgi
= true;
661 else if (!bw_40
&& sgi_20
)
662 tcb_desc
->use_shortgi
= true;
665 if (!(rate_flag
& IEEE80211_TX_RC_SHORT_GI
))
666 tcb_desc
->use_shortgi
= false;
669 static void _rtl_query_protection_mode(struct ieee80211_hw
*hw
,
670 struct rtl_tcb_desc
*tcb_desc
,
671 struct ieee80211_tx_info
*info
)
673 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
674 u8 rate_flag
= info
->control
.rates
[0].flags
;
676 /* Common Settings */
677 tcb_desc
->rts_stbc
= false;
678 tcb_desc
->cts_enable
= false;
679 tcb_desc
->rts_sc
= 0;
680 tcb_desc
->rts_bw
= false;
681 tcb_desc
->rts_use_shortpreamble
= false;
682 tcb_desc
->rts_use_shortgi
= false;
684 if (rate_flag
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
685 /* Use CTS-to-SELF in protection mode. */
686 tcb_desc
->rts_enable
= true;
687 tcb_desc
->cts_enable
= true;
688 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
689 } else if (rate_flag
& IEEE80211_TX_RC_USE_RTS_CTS
) {
690 /* Use RTS-CTS in protection mode. */
691 tcb_desc
->rts_enable
= true;
692 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
696 static void _rtl_txrate_selectmode(struct ieee80211_hw
*hw
,
697 struct ieee80211_sta
*sta
,
698 struct rtl_tcb_desc
*tcb_desc
)
700 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
701 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
702 struct rtl_sta_info
*sta_entry
= NULL
;
706 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
707 ratr_index
= sta_entry
->ratr_index
;
709 if (!tcb_desc
->disable_ratefallback
|| !tcb_desc
->use_driver_rate
) {
710 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
711 tcb_desc
->ratr_index
= 0;
712 } else if (mac
->opmode
== NL80211_IFTYPE_ADHOC
||
713 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
714 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
) {
716 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE2M
];
717 tcb_desc
->use_driver_rate
= 1;
718 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
720 tcb_desc
->ratr_index
= ratr_index
;
722 } else if (mac
->opmode
== NL80211_IFTYPE_AP
) {
723 tcb_desc
->ratr_index
= ratr_index
;
727 if (rtlpriv
->dm
.useramask
) {
728 tcb_desc
->ratr_index
= ratr_index
;
729 /* TODO we will differentiate adhoc and station future */
730 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
731 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
732 tcb_desc
->mac_id
= 0;
734 if (mac
->mode
== WIRELESS_MODE_AC_5G
)
735 tcb_desc
->ratr_index
=
736 RATR_INX_WIRELESS_AC_5N
;
737 else if (mac
->mode
== WIRELESS_MODE_AC_24G
)
738 tcb_desc
->ratr_index
=
739 RATR_INX_WIRELESS_AC_24N
;
740 else if (mac
->mode
== WIRELESS_MODE_N_24G
)
741 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NGB
;
742 else if (mac
->mode
== WIRELESS_MODE_N_5G
)
743 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NG
;
744 else if (mac
->mode
& WIRELESS_MODE_G
)
745 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_GB
;
746 else if (mac
->mode
& WIRELESS_MODE_B
)
747 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_B
;
748 else if (mac
->mode
& WIRELESS_MODE_A
)
749 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_G
;
751 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
752 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
755 tcb_desc
->mac_id
= sta
->aid
+ 1;
757 tcb_desc
->mac_id
= 1;
759 tcb_desc
->mac_id
= 0;
765 static void _rtl_query_bandwidth_mode(struct ieee80211_hw
*hw
,
766 struct ieee80211_sta
*sta
,
767 struct rtl_tcb_desc
*tcb_desc
)
769 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
770 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
772 tcb_desc
->packet_bw
= false;
775 if (mac
->opmode
== NL80211_IFTYPE_AP
||
776 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
777 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
778 if (!(sta
->ht_cap
.ht_supported
) ||
779 !(sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
781 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
782 if (!mac
->bw_40
|| !(sta
->ht_cap
.ht_supported
))
785 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
)
788 /*use legency rate, shall use 20MHz */
789 if (tcb_desc
->hw_rate
<= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
])
792 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_20_40
;
794 if (rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8812AE
||
795 rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8821AE
) {
796 if (mac
->opmode
== NL80211_IFTYPE_AP
||
797 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
798 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
799 if (!(sta
->vht_cap
.vht_supported
))
801 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
803 !(sta
->vht_cap
.vht_supported
))
806 if (tcb_desc
->hw_rate
<=
807 rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
])
809 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_80
;
813 static u8
_rtl_get_vht_highest_n_rate(struct ieee80211_hw
*hw
,
814 struct ieee80211_sta
*sta
)
816 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
817 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
819 u16 tx_mcs_map
= le16_to_cpu(sta
->vht_cap
.vht_mcs
.tx_mcs_map
);
821 if ((get_rf_type(rtlphy
) == RF_2T2R
) &&
822 (tx_mcs_map
& 0x000c) != 0x000c) {
823 if ((tx_mcs_map
& 0x000c) >> 2 ==
824 IEEE80211_VHT_MCS_SUPPORT_0_7
)
826 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS7
];
827 else if ((tx_mcs_map
& 0x000c) >> 2 ==
828 IEEE80211_VHT_MCS_SUPPORT_0_8
)
830 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
833 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
835 if ((tx_mcs_map
& 0x0003) ==
836 IEEE80211_VHT_MCS_SUPPORT_0_7
)
838 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS7
];
839 else if ((tx_mcs_map
& 0x0003) ==
840 IEEE80211_VHT_MCS_SUPPORT_0_8
)
842 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
845 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
851 static u8
_rtl_get_highest_n_rate(struct ieee80211_hw
*hw
,
852 struct ieee80211_sta
*sta
)
854 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
855 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
858 if ((get_rf_type(rtlphy
) == RF_2T2R
) &&
859 (sta
->ht_cap
.mcs
.rx_mask
[1] != 0))
860 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
];
862 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS7
];
867 /* mac80211's rate_idx is like this:
869 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
872 * (rx_status->flag & RX_FLAG_HT) = 0,
873 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
876 * (rx_status->flag & RX_FLAG_HT) = 1,
877 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
879 * 5G band:rx_status->band == NL80211_BAND_5GHZ
881 * (rx_status->flag & RX_FLAG_HT) = 0,
882 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
885 * (rx_status->flag & RX_FLAG_HT) = 1,
886 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
889 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
890 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
892 int rtlwifi_rate_mapping(struct ieee80211_hw
*hw
, bool isht
, bool isvht
,
899 case DESC_RATEVHT1SS_MCS0
:
902 case DESC_RATEVHT1SS_MCS1
:
905 case DESC_RATEVHT1SS_MCS2
:
908 case DESC_RATEVHT1SS_MCS3
:
911 case DESC_RATEVHT1SS_MCS4
:
914 case DESC_RATEVHT1SS_MCS5
:
917 case DESC_RATEVHT1SS_MCS6
:
920 case DESC_RATEVHT1SS_MCS7
:
923 case DESC_RATEVHT1SS_MCS8
:
926 case DESC_RATEVHT1SS_MCS9
:
929 case DESC_RATEVHT2SS_MCS0
:
932 case DESC_RATEVHT2SS_MCS1
:
935 case DESC_RATEVHT2SS_MCS2
:
938 case DESC_RATEVHT2SS_MCS3
:
941 case DESC_RATEVHT2SS_MCS4
:
944 case DESC_RATEVHT2SS_MCS5
:
947 case DESC_RATEVHT2SS_MCS6
:
950 case DESC_RATEVHT2SS_MCS7
:
953 case DESC_RATEVHT2SS_MCS8
:
956 case DESC_RATEVHT2SS_MCS9
:
966 if (NL80211_BAND_2GHZ
== hw
->conf
.chandef
.chan
->band
) {
1009 switch (desc_rate
) {
1040 switch (desc_rate
) {
1071 case DESC_RATEMCS10
:
1074 case DESC_RATEMCS11
:
1077 case DESC_RATEMCS12
:
1080 case DESC_RATEMCS13
:
1083 case DESC_RATEMCS14
:
1086 case DESC_RATEMCS15
:
1096 EXPORT_SYMBOL(rtlwifi_rate_mapping
);
1098 void rtl_get_tcb_desc(struct ieee80211_hw
*hw
,
1099 struct ieee80211_tx_info
*info
,
1100 struct ieee80211_sta
*sta
,
1101 struct sk_buff
*skb
, struct rtl_tcb_desc
*tcb_desc
)
1103 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1104 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
1105 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
1106 struct ieee80211_rate
*txrate
;
1107 __le16 fc
= rtl_get_fc(skb
);
1109 txrate
= ieee80211_get_tx_rate(hw
, info
);
1111 tcb_desc
->hw_rate
= txrate
->hw_value
;
1113 if (ieee80211_is_data(fc
)) {
1115 *we set data rate INX 0
1116 *in rtl_rc.c if skb is special data or
1117 *mgt which need low data rate.
1121 *So tcb_desc->hw_rate is just used for
1122 *special data and mgt frames
1124 if (info
->control
.rates
[0].idx
== 0 ||
1125 ieee80211_is_nullfunc(fc
)) {
1126 tcb_desc
->use_driver_rate
= true;
1127 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
1129 tcb_desc
->disable_ratefallback
= 1;
1132 *because hw will nerver use hw_rate
1133 *when tcb_desc->use_driver_rate = false
1134 *so we never set highest N rate here,
1135 *and N rate will all be controlled by FW
1136 *when tcb_desc->use_driver_rate = false
1138 if (sta
&& sta
->vht_cap
.vht_supported
) {
1140 _rtl_get_vht_highest_n_rate(hw
, sta
);
1142 if (sta
&& (sta
->ht_cap
.ht_supported
)) {
1144 _rtl_get_highest_n_rate(hw
, sta
);
1146 if (rtlmac
->mode
== WIRELESS_MODE_B
) {
1148 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE11M
];
1151 rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
];
1157 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)))
1158 tcb_desc
->multicast
= 1;
1159 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr
)))
1160 tcb_desc
->broadcast
= 1;
1162 _rtl_txrate_selectmode(hw
, sta
, tcb_desc
);
1163 _rtl_query_bandwidth_mode(hw
, sta
, tcb_desc
);
1164 _rtl_qurey_shortpreamble_mode(hw
, tcb_desc
, info
);
1165 _rtl_query_shortgi(hw
, sta
, tcb_desc
, info
);
1166 _rtl_query_protection_mode(hw
, tcb_desc
, info
);
1168 tcb_desc
->use_driver_rate
= true;
1169 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
1170 tcb_desc
->disable_ratefallback
= 1;
1171 tcb_desc
->mac_id
= 0;
1172 tcb_desc
->packet_bw
= false;
1175 EXPORT_SYMBOL(rtl_get_tcb_desc
);
1177 bool rtl_tx_mgmt_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1179 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1180 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1181 __le16 fc
= rtl_get_fc(skb
);
1183 if (rtlpriv
->dm
.supp_phymode_switch
&&
1184 mac
->link_state
< MAC80211_LINKED
&&
1185 (ieee80211_is_auth(fc
) || ieee80211_is_probe_req(fc
))) {
1186 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1187 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1189 if (ieee80211_is_auth(fc
)) {
1190 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
, "MAC80211_LINKING\n");
1193 mac
->link_state
= MAC80211_LINKING
;
1195 rtlpriv
->phy
.need_iqk
= true;
1201 EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc
);
1203 struct sk_buff
*rtl_make_del_ba(struct ieee80211_hw
*hw
, u8
*sa
,
1204 u8
*bssid
, u16 tid
);
1206 static void process_agg_start(struct ieee80211_hw
*hw
,
1207 struct ieee80211_hdr
*hdr
, u16 tid
)
1209 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1210 struct ieee80211_rx_status rx_status
= { 0 };
1211 struct sk_buff
*skb_delba
= NULL
;
1213 skb_delba
= rtl_make_del_ba(hw
, hdr
->addr2
, hdr
->addr3
, tid
);
1215 rx_status
.freq
= hw
->conf
.chandef
.chan
->center_freq
;
1216 rx_status
.band
= hw
->conf
.chandef
.chan
->band
;
1217 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1218 rx_status
.flag
|= RX_FLAG_MACTIME_START
;
1219 rx_status
.rate_idx
= 0;
1220 rx_status
.signal
= 50 + 10;
1221 memcpy(IEEE80211_SKB_RXCB(skb_delba
),
1222 &rx_status
, sizeof(rx_status
));
1223 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1227 ieee80211_rx_irqsafe(hw
, skb_delba
);
1231 bool rtl_action_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
1233 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1234 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
1235 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1236 __le16 fc
= rtl_get_fc(skb
);
1237 u8
*act
= (u8
*)(((u8
*)skb
->data
+ MAC80211_3ADDR_LEN
));
1240 if (!ieee80211_is_action(fc
))
1249 if (mac
->act_scanning
)
1252 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1253 "%s ACT_ADDBAREQ From :%pM\n",
1254 is_tx
? "Tx" : "Rx", hdr
->addr2
);
1255 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "req\n",
1256 skb
->data
, skb
->len
);
1258 struct ieee80211_sta
*sta
= NULL
;
1259 struct rtl_sta_info
*sta_entry
= NULL
;
1260 struct rtl_tid_data
*tid_data
;
1261 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1262 u16 capab
= 0, tid
= 0;
1265 sta
= rtl_find_sta(hw
, hdr
->addr3
);
1267 RT_TRACE(rtlpriv
, COMP_SEND
| COMP_RECV
,
1268 DBG_DMESG
, "sta is NULL\n");
1274 (struct rtl_sta_info
*)sta
->drv_priv
;
1280 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1282 IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1283 tid_data
= &sta_entry
->tids
[tid
];
1284 if (tid_data
->agg
.rx_agg_state
==
1286 process_agg_start(hw
, hdr
, tid
);
1291 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1292 "%s ACT_ADDBARSP From :%pM\n",
1293 is_tx
? "Tx" : "Rx", hdr
->addr2
);
1296 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1297 "ACT_ADDBADEL From :%pM\n", hdr
->addr2
);
1307 EXPORT_SYMBOL_GPL(rtl_action_proc
);
1309 static void setup_arp_tx(struct rtl_priv
*rtlpriv
, struct rtl_ps_ctl
*ppsc
)
1311 struct ieee80211_hw
*hw
= rtlpriv
->hw
;
1313 rtlpriv
->ra
.is_special_data
= true;
1314 if (rtlpriv
->cfg
->ops
->get_btc_status())
1315 rtlpriv
->btcoexist
.btc_ops
->btc_special_packet_notify(
1318 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1321 /*should call before software enc*/
1322 u8
rtl_is_special_data(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
,
1325 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1326 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1327 __le16 fc
= rtl_get_fc(skb
);
1329 u8 mac_hdr_len
= ieee80211_get_hdrlen_from_skb(skb
);
1330 u8 encrypt_header_len
= 0;
1332 const struct iphdr
*ip
;
1334 if (!ieee80211_is_data(fc
))
1337 switch (rtlpriv
->sec
.pairwise_enc_algorithm
) {
1338 case WEP40_ENCRYPTION
:
1339 case WEP104_ENCRYPTION
:
1340 encrypt_header_len
= 4;/*WEP_IV_LEN*/
1342 case TKIP_ENCRYPTION
:
1343 encrypt_header_len
= 8;/*TKIP_IV_LEN*/
1345 case AESCCMP_ENCRYPTION
:
1346 encrypt_header_len
= 8;/*CCMP_HDR_LEN;*/
1352 offset
= mac_hdr_len
+ SNAP_SIZE
;
1354 offset
+= encrypt_header_len
;
1355 ether_type
= be16_to_cpup((__be16
*)(skb
->data
+ offset
));
1357 if (ETH_P_IP
== ether_type
) {
1358 ip
= (struct iphdr
*)((u8
*)skb
->data
+ offset
+
1360 if (IPPROTO_UDP
== ip
->protocol
) {
1361 struct udphdr
*udp
= (struct udphdr
*)((u8
*)ip
+
1363 if (((((u8
*)udp
)[1] == 68) &&
1364 (((u8
*)udp
)[3] == 67)) ||
1365 ((((u8
*)udp
)[1] == 67) &&
1366 (((u8
*)udp
)[3] == 68))) {
1367 /* 68 : UDP BOOTP client
1368 * 67 : UDP BOOTP server
1370 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
),
1371 DBG_DMESG
, "dhcp %s !!\n",
1372 (is_tx
) ? "Tx" : "Rx");
1375 setup_arp_tx(rtlpriv
, ppsc
);
1379 } else if (ETH_P_ARP
== ether_type
) {
1381 setup_arp_tx(rtlpriv
, ppsc
);
1384 } else if (ETH_P_PAE
== ether_type
) {
1385 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1386 "802.1X %s EAPOL pkt!!\n", (is_tx
) ? "Tx" : "Rx");
1389 rtlpriv
->ra
.is_special_data
= true;
1391 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1395 } else if (ETH_P_IPV6
== ether_type
) {
1396 /* TODO: Handle any IPv6 cases that need special handling.
1397 * For now, always return false
1403 rtlpriv
->ra
.is_special_data
= false;
1406 EXPORT_SYMBOL_GPL(rtl_is_special_data
);
1408 /*********************************************************
1410 * functions called by core.c
1412 *********************************************************/
1413 int rtl_tx_agg_start(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1414 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
1416 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1417 struct rtl_tid_data
*tid_data
;
1418 struct rtl_sta_info
*sta_entry
= NULL
;
1423 if (unlikely(tid
>= MAX_TID_COUNT
))
1426 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1429 tid_data
= &sta_entry
->tids
[tid
];
1431 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1432 "on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1433 tid_data
->seq_number
);
1435 *ssn
= tid_data
->seq_number
;
1436 tid_data
->agg
.agg_state
= RTL_AGG_START
;
1438 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1442 int rtl_tx_agg_stop(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1443 struct ieee80211_sta
*sta
, u16 tid
)
1445 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1446 struct rtl_tid_data
*tid_data
;
1447 struct rtl_sta_info
*sta_entry
= NULL
;
1452 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1453 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1455 if (unlikely(tid
>= MAX_TID_COUNT
))
1458 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1459 tid_data
= &sta_entry
->tids
[tid
];
1460 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_STOP
;
1462 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1466 int rtl_rx_agg_start(struct ieee80211_hw
*hw
,
1467 struct ieee80211_sta
*sta
, u16 tid
)
1469 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1470 struct rtl_tid_data
*tid_data
;
1471 struct rtl_sta_info
*sta_entry
= NULL
;
1476 if (unlikely(tid
>= MAX_TID_COUNT
))
1479 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1482 tid_data
= &sta_entry
->tids
[tid
];
1484 RT_TRACE(rtlpriv
, COMP_RECV
, DBG_DMESG
,
1485 "on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1486 tid_data
->seq_number
);
1488 tid_data
->agg
.rx_agg_state
= RTL_RX_AGG_START
;
1492 int rtl_rx_agg_stop(struct ieee80211_hw
*hw
,
1493 struct ieee80211_sta
*sta
, u16 tid
)
1495 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1496 struct rtl_sta_info
*sta_entry
= NULL
;
1501 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1502 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1504 if (unlikely(tid
>= MAX_TID_COUNT
))
1507 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1508 sta_entry
->tids
[tid
].agg
.rx_agg_state
= RTL_RX_AGG_STOP
;
1512 int rtl_tx_agg_oper(struct ieee80211_hw
*hw
,
1513 struct ieee80211_sta
*sta
, u16 tid
)
1515 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1516 struct rtl_sta_info
*sta_entry
= NULL
;
1521 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1522 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1524 if (unlikely(tid
>= MAX_TID_COUNT
))
1527 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1528 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_OPERATIONAL
;
1533 /*********************************************************
1535 * wq & timer callback functions
1537 *********************************************************/
1538 /* this function is used for roaming */
1539 void rtl_beacon_statistic(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1541 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1542 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1544 if (rtlpriv
->mac80211
.opmode
!= NL80211_IFTYPE_STATION
)
1547 if (rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
)
1550 /* check if this really is a beacon */
1551 if (!ieee80211_is_beacon(hdr
->frame_control
) &&
1552 !ieee80211_is_probe_resp(hdr
->frame_control
))
1555 /* min. beacon length + FCS_LEN */
1556 if (skb
->len
<= 40 + FCS_LEN
)
1559 /* and only beacons from the associated BSSID, please */
1560 if (!ether_addr_equal(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
1563 rtlpriv
->link_info
.bcn_rx_inperiod
++;
1565 EXPORT_SYMBOL_GPL(rtl_beacon_statistic
);
1567 void rtl_watchdog_wq_callback(void *data
)
1569 struct rtl_works
*rtlworks
= container_of_dwork_rtl(data
,
1572 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1573 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1574 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1575 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1576 bool busytraffic
= false;
1577 bool tx_busy_traffic
= false;
1578 bool rx_busy_traffic
= false;
1579 bool higher_busytraffic
= false;
1580 bool higher_busyrxtraffic
= false;
1582 u32 rx_cnt_inp4eriod
= 0;
1583 u32 tx_cnt_inp4eriod
= 0;
1584 u32 aver_rx_cnt_inperiod
= 0;
1585 u32 aver_tx_cnt_inperiod
= 0;
1586 u32 aver_tidtx_inperiod
[MAX_TID_COUNT
] = {0};
1587 u32 tidtx_inp4eriod
[MAX_TID_COUNT
] = {0};
1589 if (is_hal_stop(rtlhal
))
1592 /* <1> Determine if action frame is allowed */
1593 if (mac
->link_state
> MAC80211_NOLINK
) {
1594 if (mac
->cnt_after_linked
< 20)
1595 mac
->cnt_after_linked
++;
1597 mac
->cnt_after_linked
= 0;
1600 /* <2> to check if traffic busy, if
1601 * busytraffic we don't change channel
1603 if (mac
->link_state
>= MAC80211_LINKED
) {
1605 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1606 for (idx
= 0; idx
<= 2; idx
++) {
1607 rtlpriv
->link_info
.num_rx_in4period
[idx
] =
1608 rtlpriv
->link_info
.num_rx_in4period
[idx
+ 1];
1609 rtlpriv
->link_info
.num_tx_in4period
[idx
] =
1610 rtlpriv
->link_info
.num_tx_in4period
[idx
+ 1];
1612 rtlpriv
->link_info
.num_rx_in4period
[3] =
1613 rtlpriv
->link_info
.num_rx_inperiod
;
1614 rtlpriv
->link_info
.num_tx_in4period
[3] =
1615 rtlpriv
->link_info
.num_tx_inperiod
;
1616 for (idx
= 0; idx
<= 3; idx
++) {
1618 rtlpriv
->link_info
.num_rx_in4period
[idx
];
1620 rtlpriv
->link_info
.num_tx_in4period
[idx
];
1622 aver_rx_cnt_inperiod
= rx_cnt_inp4eriod
/ 4;
1623 aver_tx_cnt_inperiod
= tx_cnt_inp4eriod
/ 4;
1625 /* (2) check traffic busy */
1626 if (aver_rx_cnt_inperiod
> 100 || aver_tx_cnt_inperiod
> 100) {
1628 if (aver_rx_cnt_inperiod
> aver_tx_cnt_inperiod
)
1629 rx_busy_traffic
= true;
1631 tx_busy_traffic
= false;
1634 /* Higher Tx/Rx data. */
1635 if (aver_rx_cnt_inperiod
> 4000 ||
1636 aver_tx_cnt_inperiod
> 4000) {
1637 higher_busytraffic
= true;
1639 /* Extremely high Rx data. */
1640 if (aver_rx_cnt_inperiod
> 5000)
1641 higher_busyrxtraffic
= true;
1644 /* check every tid's tx traffic */
1645 for (tid
= 0; tid
<= 7; tid
++) {
1646 for (idx
= 0; idx
<= 2; idx
++)
1647 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
] =
1648 rtlpriv
->link_info
.tidtx_in4period
[tid
]
1650 rtlpriv
->link_info
.tidtx_in4period
[tid
][3] =
1651 rtlpriv
->link_info
.tidtx_inperiod
[tid
];
1653 for (idx
= 0; idx
<= 3; idx
++)
1654 tidtx_inp4eriod
[tid
] +=
1655 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
];
1656 aver_tidtx_inperiod
[tid
] = tidtx_inp4eriod
[tid
] / 4;
1657 if (aver_tidtx_inperiod
[tid
] > 5000)
1658 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1661 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1665 if (((rtlpriv
->link_info
.num_rx_inperiod
+
1666 rtlpriv
->link_info
.num_tx_inperiod
) > 8) ||
1667 (rtlpriv
->link_info
.num_rx_inperiod
> 2))
1673 rtlpriv
->link_info
.num_rx_inperiod
= 0;
1674 rtlpriv
->link_info
.num_tx_inperiod
= 0;
1675 for (tid
= 0; tid
<= 7; tid
++)
1676 rtlpriv
->link_info
.tidtx_inperiod
[tid
] = 0;
1678 rtlpriv
->link_info
.busytraffic
= busytraffic
;
1679 rtlpriv
->link_info
.higher_busytraffic
= higher_busytraffic
;
1680 rtlpriv
->link_info
.rx_busy_traffic
= rx_busy_traffic
;
1681 rtlpriv
->link_info
.tx_busy_traffic
= tx_busy_traffic
;
1682 rtlpriv
->link_info
.higher_busyrxtraffic
= higher_busyrxtraffic
;
1685 if (!rtlpriv
->cfg
->mod_params
->disable_watchdog
)
1686 rtlpriv
->cfg
->ops
->dm_watchdog(hw
);
1689 if (mac
->link_state
== MAC80211_LINKED
&&
1690 mac
->opmode
== NL80211_IFTYPE_STATION
) {
1691 if ((rtlpriv
->link_info
.bcn_rx_inperiod
+
1692 rtlpriv
->link_info
.num_rx_inperiod
) == 0) {
1693 rtlpriv
->link_info
.roam_times
++;
1694 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_DMESG
,
1695 "AP off for %d s\n",
1696 (rtlpriv
->link_info
.roam_times
* 2));
1698 /* if we can't recv beacon for 10s,
1699 * we should reconnect this AP
1701 if (rtlpriv
->link_info
.roam_times
>= 5) {
1702 pr_err("AP off, try to reconnect now\n");
1703 rtlpriv
->link_info
.roam_times
= 0;
1704 ieee80211_connection_loss(
1705 rtlpriv
->mac80211
.vif
);
1708 rtlpriv
->link_info
.roam_times
= 0;
1712 if (rtlpriv
->cfg
->ops
->get_btc_status())
1713 rtlpriv
->btcoexist
.btc_ops
->btc_periodical(rtlpriv
);
1715 rtlpriv
->link_info
.bcn_rx_inperiod
= 0;
1718 void rtl_watch_dog_timer_callback(unsigned long data
)
1720 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
1721 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1723 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
1724 &rtlpriv
->works
.watchdog_wq
, 0);
1726 mod_timer(&rtlpriv
->works
.watchdog_timer
,
1727 jiffies
+ MSECS(RTL_WATCH_DOG_TIME
));
1729 void rtl_fwevt_wq_callback(void *data
)
1731 struct rtl_works
*rtlworks
=
1732 container_of_dwork_rtl(data
, struct rtl_works
, fwevt_wq
);
1733 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1734 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1736 rtlpriv
->cfg
->ops
->c2h_command_handle(hw
);
1739 void rtl_c2hcmd_enqueue(struct ieee80211_hw
*hw
, u8 tag
, u8 len
, u8
*val
)
1741 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1742 unsigned long flags
;
1743 struct rtl_c2hcmd
*c2hcmd
;
1745 c2hcmd
= kmalloc(sizeof(*c2hcmd
),
1746 in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
);
1751 c2hcmd
->val
= kmalloc(len
,
1752 in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
);
1760 memcpy(c2hcmd
->val
, val
, len
);
1763 spin_lock_irqsave(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
1765 list_add_tail(&c2hcmd
->list
, &rtlpriv
->c2hcmd_list
);
1767 spin_unlock_irqrestore(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
1770 queue_delayed_work(rtlpriv
->works
.rtl_wq
, &rtlpriv
->works
.c2hcmd_wq
, 0);
1778 RT_TRACE(rtlpriv
, COMP_CMD
, DBG_WARNING
,
1779 "C2H cmd enqueue fail.\n");
1781 EXPORT_SYMBOL(rtl_c2hcmd_enqueue
);
1783 void rtl_c2hcmd_launcher(struct ieee80211_hw
*hw
, int exec
)
1785 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1786 unsigned long flags
;
1787 struct rtl_c2hcmd
*c2hcmd
;
1790 for (i
= 0; i
< 200; i
++) {
1791 /* dequeue a task */
1792 spin_lock_irqsave(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
1794 c2hcmd
= list_first_entry_or_null(&rtlpriv
->c2hcmd_list
,
1795 struct rtl_c2hcmd
, list
);
1798 list_del(&c2hcmd
->list
);
1800 spin_unlock_irqrestore(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
1806 if (rtlpriv
->cfg
->ops
->c2h_content_parsing
&& exec
)
1807 rtlpriv
->cfg
->ops
->c2h_content_parsing(hw
,
1808 c2hcmd
->tag
, c2hcmd
->len
, c2hcmd
->val
);
1817 void rtl_c2hcmd_wq_callback(void *data
)
1819 struct rtl_works
*rtlworks
= container_of_dwork_rtl(data
,
1822 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1824 rtl_c2hcmd_launcher(hw
, 1);
1827 void rtl_easy_concurrent_retrytimer_callback(unsigned long data
)
1829 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
1830 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1831 struct rtl_priv
*buddy_priv
= rtlpriv
->buddy_priv
;
1833 if (buddy_priv
== NULL
)
1836 rtlpriv
->cfg
->ops
->dualmac_easy_concurrent(hw
);
1838 /*********************************************************
1840 * frame process functions
1842 *********************************************************/
1843 u8
*rtl_find_ie(u8
*data
, unsigned int len
, u8 ie
)
1845 struct ieee80211_mgmt
*mgmt
= (void *)data
;
1848 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
1851 if (pos
+ 2 + pos
[1] > end
)
1862 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1863 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1864 static struct sk_buff
*rtl_make_smps_action(struct ieee80211_hw
*hw
,
1865 enum ieee80211_smps_mode smps
,
1868 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1869 struct sk_buff
*skb
;
1870 struct ieee80211_mgmt
*action_frame
;
1872 /* 27 = header + category + action + smps mode */
1873 skb
= dev_alloc_skb(27 + hw
->extra_tx_headroom
);
1877 skb_reserve(skb
, hw
->extra_tx_headroom
);
1878 action_frame
= (void *)skb_put(skb
, 27);
1879 memset(action_frame
, 0, 27);
1880 memcpy(action_frame
->da
, da
, ETH_ALEN
);
1881 memcpy(action_frame
->sa
, rtlefuse
->dev_addr
, ETH_ALEN
);
1882 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
1883 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1884 IEEE80211_STYPE_ACTION
);
1885 action_frame
->u
.action
.category
= WLAN_CATEGORY_HT
;
1886 action_frame
->u
.action
.u
.ht_smps
.action
= WLAN_HT_ACTION_SMPS
;
1888 case IEEE80211_SMPS_AUTOMATIC
:/* 0 */
1889 case IEEE80211_SMPS_NUM_MODES
:/* 4 */
1891 /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
1892 * According to Kernel Code, here is right.
1894 case IEEE80211_SMPS_OFF
:/* 1 */ /*MIMO_PS_NOLIMIT*/
1895 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1896 WLAN_HT_SMPS_CONTROL_DISABLED
;/* 0 */
1898 case IEEE80211_SMPS_STATIC
:/* 2 */ /*MIMO_PS_STATIC*/
1899 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1900 WLAN_HT_SMPS_CONTROL_STATIC
;/* 1 */
1902 case IEEE80211_SMPS_DYNAMIC
:/* 3 */ /*MIMO_PS_DYNAMIC*/
1903 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1904 WLAN_HT_SMPS_CONTROL_DYNAMIC
;/* 3 */
1911 int rtl_send_smps_action(struct ieee80211_hw
*hw
,
1912 struct ieee80211_sta
*sta
,
1913 enum ieee80211_smps_mode smps
)
1915 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1916 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1917 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1918 struct sk_buff
*skb
= NULL
;
1919 struct rtl_tcb_desc tcb_desc
;
1920 u8 bssid
[ETH_ALEN
] = {0};
1922 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1924 if (rtlpriv
->mac80211
.act_scanning
)
1930 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
1933 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1936 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_AP
)
1937 memcpy(bssid
, rtlpriv
->efuse
.dev_addr
, ETH_ALEN
);
1939 memcpy(bssid
, rtlpriv
->mac80211
.bssid
, ETH_ALEN
);
1941 skb
= rtl_make_smps_action(hw
, smps
, sta
->addr
, bssid
);
1942 /* this is a type = mgmt * stype = action frame */
1944 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1945 struct rtl_sta_info
*sta_entry
=
1946 (struct rtl_sta_info
*) sta
->drv_priv
;
1947 sta_entry
->mimo_ps
= smps
;
1948 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
1950 info
->control
.rates
[0].idx
= 0;
1951 info
->band
= hw
->conf
.chandef
.chan
->band
;
1952 rtlpriv
->intf_ops
->adapter_tx(hw
, sta
, skb
, &tcb_desc
);
1959 EXPORT_SYMBOL(rtl_send_smps_action
);
1961 void rtl_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
1963 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1964 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1965 enum io_type iotype
;
1967 if (!is_hal_stop(rtlhal
)) {
1968 switch (operation
) {
1969 case SCAN_OPT_BACKUP
:
1970 iotype
= IO_CMD_PAUSE_DM_BY_SCAN
;
1971 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1975 case SCAN_OPT_RESTORE
:
1976 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
1977 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1982 pr_err("Unknown Scan Backup operation.\n");
1987 EXPORT_SYMBOL(rtl_phy_scan_operation_backup
);
1989 /* because mac80211 have issues when can receive del ba
1990 * so here we just make a fake del_ba if we receive a ba_req
1991 * but rx_agg was opened to let mac80211 release some ba
1992 * related resources, so please this del_ba for tx
1994 struct sk_buff
*rtl_make_del_ba(struct ieee80211_hw
*hw
,
1995 u8
*sa
, u8
*bssid
, u16 tid
)
1997 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1998 struct sk_buff
*skb
;
1999 struct ieee80211_mgmt
*action_frame
;
2002 /* 27 = header + category + action + smps mode */
2003 skb
= dev_alloc_skb(34 + hw
->extra_tx_headroom
);
2007 skb_reserve(skb
, hw
->extra_tx_headroom
);
2008 action_frame
= (void *)skb_put(skb
, 34);
2009 memset(action_frame
, 0, 34);
2010 memcpy(action_frame
->sa
, sa
, ETH_ALEN
);
2011 memcpy(action_frame
->da
, rtlefuse
->dev_addr
, ETH_ALEN
);
2012 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
2013 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2014 IEEE80211_STYPE_ACTION
);
2015 action_frame
->u
.action
.category
= WLAN_CATEGORY_BACK
;
2016 action_frame
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
2017 params
= (u16
)(1 << 11); /* bit 11 initiator */
2018 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
2020 action_frame
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
2021 action_frame
->u
.action
.u
.delba
.reason_code
=
2022 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT
);
2027 /*********************************************************
2031 *********************************************************/
2032 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw
*hw
,
2033 struct octet_string vendor_ie
)
2035 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2036 bool matched
= false;
2037 static u8 athcap_1
[] = { 0x00, 0x03, 0x7F };
2038 static u8 athcap_2
[] = { 0x00, 0x13, 0x74 };
2039 static u8 broadcap_1
[] = { 0x00, 0x10, 0x18 };
2040 static u8 broadcap_2
[] = { 0x00, 0x0a, 0xf7 };
2041 static u8 broadcap_3
[] = { 0x00, 0x05, 0xb5 };
2042 static u8 racap
[] = { 0x00, 0x0c, 0x43 };
2043 static u8 ciscocap
[] = { 0x00, 0x40, 0x96 };
2044 static u8 marvcap
[] = { 0x00, 0x50, 0x43 };
2046 if (memcmp(vendor_ie
.octet
, athcap_1
, 3) == 0 ||
2047 memcmp(vendor_ie
.octet
, athcap_2
, 3) == 0) {
2048 rtlpriv
->mac80211
.vendor
= PEER_ATH
;
2050 } else if (memcmp(vendor_ie
.octet
, broadcap_1
, 3) == 0 ||
2051 memcmp(vendor_ie
.octet
, broadcap_2
, 3) == 0 ||
2052 memcmp(vendor_ie
.octet
, broadcap_3
, 3) == 0) {
2053 rtlpriv
->mac80211
.vendor
= PEER_BROAD
;
2055 } else if (memcmp(vendor_ie
.octet
, racap
, 3) == 0) {
2056 rtlpriv
->mac80211
.vendor
= PEER_RAL
;
2058 } else if (memcmp(vendor_ie
.octet
, ciscocap
, 3) == 0) {
2059 rtlpriv
->mac80211
.vendor
= PEER_CISCO
;
2061 } else if (memcmp(vendor_ie
.octet
, marvcap
, 3) == 0) {
2062 rtlpriv
->mac80211
.vendor
= PEER_MARV
;
2069 static bool rtl_find_221_ie(struct ieee80211_hw
*hw
, u8
*data
,
2072 struct ieee80211_mgmt
*mgmt
= (void *)data
;
2073 struct octet_string vendor_ie
;
2076 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
2079 if (pos
[0] == 221) {
2080 vendor_ie
.length
= pos
[1];
2081 vendor_ie
.octet
= &pos
[2];
2082 if (rtl_chk_vendor_ouisub(hw
, vendor_ie
))
2086 if (pos
+ 2 + pos
[1] > end
)
2094 void rtl_recognize_peer(struct ieee80211_hw
*hw
, u8
*data
, unsigned int len
)
2096 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2097 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2098 struct ieee80211_hdr
*hdr
= (void *)data
;
2099 u32 vendor
= PEER_UNKNOWN
;
2101 static u8 ap3_1
[3] = { 0x00, 0x14, 0xbf };
2102 static u8 ap3_2
[3] = { 0x00, 0x1a, 0x70 };
2103 static u8 ap3_3
[3] = { 0x00, 0x1d, 0x7e };
2104 static u8 ap4_1
[3] = { 0x00, 0x90, 0xcc };
2105 static u8 ap4_2
[3] = { 0x00, 0x0e, 0x2e };
2106 static u8 ap4_3
[3] = { 0x00, 0x18, 0x02 };
2107 static u8 ap4_4
[3] = { 0x00, 0x17, 0x3f };
2108 static u8 ap4_5
[3] = { 0x00, 0x1c, 0xdf };
2109 static u8 ap5_1
[3] = { 0x00, 0x1c, 0xf0 };
2110 static u8 ap5_2
[3] = { 0x00, 0x21, 0x91 };
2111 static u8 ap5_3
[3] = { 0x00, 0x24, 0x01 };
2112 static u8 ap5_4
[3] = { 0x00, 0x15, 0xe9 };
2113 static u8 ap5_5
[3] = { 0x00, 0x17, 0x9A };
2114 static u8 ap5_6
[3] = { 0x00, 0x18, 0xE7 };
2115 static u8 ap6_1
[3] = { 0x00, 0x17, 0x94 };
2116 static u8 ap7_1
[3] = { 0x00, 0x14, 0xa4 };
2118 if (mac
->opmode
!= NL80211_IFTYPE_STATION
)
2121 if (mac
->link_state
== MAC80211_NOLINK
) {
2122 mac
->vendor
= PEER_UNKNOWN
;
2126 if (mac
->cnt_after_linked
> 2)
2129 /* check if this really is a beacon */
2130 if (!ieee80211_is_beacon(hdr
->frame_control
))
2133 /* min. beacon length + FCS_LEN */
2134 if (len
<= 40 + FCS_LEN
)
2137 /* and only beacons from the associated BSSID, please */
2138 if (!ether_addr_equal_64bits(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
2141 if (rtl_find_221_ie(hw
, data
, len
))
2142 vendor
= mac
->vendor
;
2144 if ((memcmp(mac
->bssid
, ap5_1
, 3) == 0) ||
2145 (memcmp(mac
->bssid
, ap5_2
, 3) == 0) ||
2146 (memcmp(mac
->bssid
, ap5_3
, 3) == 0) ||
2147 (memcmp(mac
->bssid
, ap5_4
, 3) == 0) ||
2148 (memcmp(mac
->bssid
, ap5_5
, 3) == 0) ||
2149 (memcmp(mac
->bssid
, ap5_6
, 3) == 0) ||
2150 vendor
== PEER_ATH
) {
2152 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>ath find\n");
2153 } else if ((memcmp(mac
->bssid
, ap4_4
, 3) == 0) ||
2154 (memcmp(mac
->bssid
, ap4_5
, 3) == 0) ||
2155 (memcmp(mac
->bssid
, ap4_1
, 3) == 0) ||
2156 (memcmp(mac
->bssid
, ap4_2
, 3) == 0) ||
2157 (memcmp(mac
->bssid
, ap4_3
, 3) == 0) ||
2158 vendor
== PEER_RAL
) {
2159 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>ral find\n");
2161 } else if (memcmp(mac
->bssid
, ap6_1
, 3) == 0 ||
2162 vendor
== PEER_CISCO
) {
2163 vendor
= PEER_CISCO
;
2164 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>cisco find\n");
2165 } else if ((memcmp(mac
->bssid
, ap3_1
, 3) == 0) ||
2166 (memcmp(mac
->bssid
, ap3_2
, 3) == 0) ||
2167 (memcmp(mac
->bssid
, ap3_3
, 3) == 0) ||
2168 vendor
== PEER_BROAD
) {
2169 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>broad find\n");
2170 vendor
= PEER_BROAD
;
2171 } else if (memcmp(mac
->bssid
, ap7_1
, 3) == 0 ||
2172 vendor
== PEER_MARV
) {
2174 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>marv find\n");
2177 mac
->vendor
= vendor
;
2179 EXPORT_SYMBOL_GPL(rtl_recognize_peer
);
2181 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2182 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2183 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2184 MODULE_LICENSE("GPL");
2185 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2187 struct rtl_global_var rtl_global_var
= {};
2188 EXPORT_SYMBOL_GPL(rtl_global_var
);
2190 static int __init
rtl_core_module_init(void)
2192 if (rtl_rate_control_register())
2193 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
2195 /* init some global vars */
2196 INIT_LIST_HEAD(&rtl_global_var
.glb_priv_list
);
2197 spin_lock_init(&rtl_global_var
.glb_list_lock
);
2202 static void __exit
rtl_core_module_exit(void)
2205 rtl_rate_control_unregister();
2208 module_init(rtl_core_module_init
);
2209 module_exit(rtl_core_module_exit
);