1 /******************************************************************************
3 * Copyright(c) 2009-2010 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 *****************************************************************************/
27 #include <linux/module.h>
38 *NOTICE!!!: This file will be very big, we hsould
39 *keep it clear under follwing roles:
41 *This file include follwing part, so, if you add new
42 *functions into this file, please check which part it
43 *should includes. or check if you should add new part
46 *1) mac80211 init functions
47 *2) tx information functions
48 *3) functions called by core.c
49 *4) wq & timer callback functions
50 *5) frame process functions
57 /*********************************************************
59 * mac80211 init functions
61 *********************************************************/
62 static struct ieee80211_channel rtl_channeltable_2g
[] = {
63 {.center_freq
= 2412, .hw_value
= 1,},
64 {.center_freq
= 2417, .hw_value
= 2,},
65 {.center_freq
= 2422, .hw_value
= 3,},
66 {.center_freq
= 2427, .hw_value
= 4,},
67 {.center_freq
= 2432, .hw_value
= 5,},
68 {.center_freq
= 2437, .hw_value
= 6,},
69 {.center_freq
= 2442, .hw_value
= 7,},
70 {.center_freq
= 2447, .hw_value
= 8,},
71 {.center_freq
= 2452, .hw_value
= 9,},
72 {.center_freq
= 2457, .hw_value
= 10,},
73 {.center_freq
= 2462, .hw_value
= 11,},
74 {.center_freq
= 2467, .hw_value
= 12,},
75 {.center_freq
= 2472, .hw_value
= 13,},
76 {.center_freq
= 2484, .hw_value
= 14,},
79 static struct ieee80211_channel rtl_channeltable_5g
[] = {
80 {.center_freq
= 5180, .hw_value
= 36,},
81 {.center_freq
= 5200, .hw_value
= 40,},
82 {.center_freq
= 5220, .hw_value
= 44,},
83 {.center_freq
= 5240, .hw_value
= 48,},
84 {.center_freq
= 5260, .hw_value
= 52,},
85 {.center_freq
= 5280, .hw_value
= 56,},
86 {.center_freq
= 5300, .hw_value
= 60,},
87 {.center_freq
= 5320, .hw_value
= 64,},
88 {.center_freq
= 5500, .hw_value
= 100,},
89 {.center_freq
= 5520, .hw_value
= 104,},
90 {.center_freq
= 5540, .hw_value
= 108,},
91 {.center_freq
= 5560, .hw_value
= 112,},
92 {.center_freq
= 5580, .hw_value
= 116,},
93 {.center_freq
= 5600, .hw_value
= 120,},
94 {.center_freq
= 5620, .hw_value
= 124,},
95 {.center_freq
= 5640, .hw_value
= 128,},
96 {.center_freq
= 5660, .hw_value
= 132,},
97 {.center_freq
= 5680, .hw_value
= 136,},
98 {.center_freq
= 5700, .hw_value
= 140,},
99 {.center_freq
= 5745, .hw_value
= 149,},
100 {.center_freq
= 5765, .hw_value
= 153,},
101 {.center_freq
= 5785, .hw_value
= 157,},
102 {.center_freq
= 5805, .hw_value
= 161,},
103 {.center_freq
= 5825, .hw_value
= 165,},
106 static struct ieee80211_rate rtl_ratetable_2g
[] = {
107 {.bitrate
= 10, .hw_value
= 0x00,},
108 {.bitrate
= 20, .hw_value
= 0x01,},
109 {.bitrate
= 55, .hw_value
= 0x02,},
110 {.bitrate
= 110, .hw_value
= 0x03,},
111 {.bitrate
= 60, .hw_value
= 0x04,},
112 {.bitrate
= 90, .hw_value
= 0x05,},
113 {.bitrate
= 120, .hw_value
= 0x06,},
114 {.bitrate
= 180, .hw_value
= 0x07,},
115 {.bitrate
= 240, .hw_value
= 0x08,},
116 {.bitrate
= 360, .hw_value
= 0x09,},
117 {.bitrate
= 480, .hw_value
= 0x0a,},
118 {.bitrate
= 540, .hw_value
= 0x0b,},
121 static struct ieee80211_rate rtl_ratetable_5g
[] = {
122 {.bitrate
= 60, .hw_value
= 0x04,},
123 {.bitrate
= 90, .hw_value
= 0x05,},
124 {.bitrate
= 120, .hw_value
= 0x06,},
125 {.bitrate
= 180, .hw_value
= 0x07,},
126 {.bitrate
= 240, .hw_value
= 0x08,},
127 {.bitrate
= 360, .hw_value
= 0x09,},
128 {.bitrate
= 480, .hw_value
= 0x0a,},
129 {.bitrate
= 540, .hw_value
= 0x0b,},
132 static const struct ieee80211_supported_band rtl_band_2ghz
= {
133 .band
= IEEE80211_BAND_2GHZ
,
135 .channels
= rtl_channeltable_2g
,
136 .n_channels
= ARRAY_SIZE(rtl_channeltable_2g
),
138 .bitrates
= rtl_ratetable_2g
,
139 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_2g
),
144 static struct ieee80211_supported_band rtl_band_5ghz
= {
145 .band
= IEEE80211_BAND_5GHZ
,
147 .channels
= rtl_channeltable_5g
,
148 .n_channels
= ARRAY_SIZE(rtl_channeltable_5g
),
150 .bitrates
= rtl_ratetable_5g
,
151 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_5g
),
156 static const u8 tid_to_ac
[] = {
157 2, /* IEEE80211_AC_BE */
158 3, /* IEEE80211_AC_BK */
159 3, /* IEEE80211_AC_BK */
160 2, /* IEEE80211_AC_BE */
161 1, /* IEEE80211_AC_VI */
162 1, /* IEEE80211_AC_VI */
163 0, /* IEEE80211_AC_VO */
164 0, /* IEEE80211_AC_VO */
167 u8
rtl92e_tid_to_ac(struct ieee80211_hw
*hw
, u8 tid
)
169 return tid_to_ac
[tid
];
172 static void _rtl_init_hw_ht_capab(struct ieee80211_hw
*hw
,
173 struct ieee80211_sta_ht_cap
*ht_cap
)
175 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
176 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
178 ht_cap
->ht_supported
= true;
179 ht_cap
->cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
180 IEEE80211_HT_CAP_SGI_40
|
181 IEEE80211_HT_CAP_SGI_20
|
182 IEEE80211_HT_CAP_DSSSCCK40
| IEEE80211_HT_CAP_MAX_AMSDU
;
184 if (rtlpriv
->rtlhal
.disable_amsdu_8k
)
185 ht_cap
->cap
&= ~IEEE80211_HT_CAP_MAX_AMSDU
;
188 *Maximum length of AMPDU that the STA can receive.
189 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
191 ht_cap
->ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
193 /*Minimum MPDU start spacing , */
194 ht_cap
->ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
196 ht_cap
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
199 *hw->wiphy->bands[IEEE80211_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 RT_TRACE(COMP_INIT
, DBG_EMERG
, ("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(COMP_INIT
, DBG_DMESG
, ("1T2R or 2T2R\n"));
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
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
226 } else if (get_rf_type(rtlphy
) == RF_1T1R
) {
227 RT_TRACE(COMP_INIT
, DBG_DMESG
, ("1T1R\n"));
229 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
230 ht_cap
->mcs
.rx_mask
[1] = 0x00;
231 ht_cap
->mcs
.rx_mask
[4] = 0x01;
233 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7
);
238 static void _rtl_init_hw_vht_capab(struct ieee80211_hw
*hw
,
239 struct ieee80211_sta_vht_cap
*vht_cap
)
241 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
242 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
244 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
246 vht_cap
->vht_supported
= true;
248 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895
|
249 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991
|
250 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
|
251 IEEE80211_VHT_CAP_SHORT_GI_80
|
252 IEEE80211_VHT_CAP_TXSTBC
|
253 IEEE80211_VHT_CAP_RXSTBC_1
|
254 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
255 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
256 IEEE80211_VHT_CAP_HTC_VHT
|
257 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
|
258 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN
|
259 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN
|
262 mcs_map
= IEEE80211_VHT_MCS_SUPPORT_0_9
<< 0 |
263 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 2 |
264 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 4 |
265 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 6 |
266 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 8 |
267 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 10 |
268 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 12 |
269 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 14;
271 vht_cap
->vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
272 vht_cap
->vht_mcs
.rx_highest
=
273 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9
);
274 vht_cap
->vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
275 vht_cap
->vht_mcs
.tx_highest
=
276 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9
);
277 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
280 vht_cap
->vht_supported
= true;
282 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895
|
283 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991
|
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
;
323 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&&
324 rtlhal
->bandset
== BAND_ON_BOTH
) {
326 /* <1> use mac->bands as mem for hw->wiphy->bands */
327 sband
= &(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]);
329 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
330 * to default value(1T1R) */
331 memcpy(&(rtlmac
->bands
[IEEE80211_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
[IEEE80211_BAND_2GHZ
] = sband
;
341 /* <1> use mac->bands as mem for hw->wiphy->bands */
342 sband
= &(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]);
344 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
345 * to default value(1T1R) */
346 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]), &rtl_band_5ghz
,
347 sizeof(struct ieee80211_supported_band
));
349 /* <3> init ht cap base on ant_num */
350 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
352 _rtl_init_hw_vht_capab(hw
, &sband
->vht_cap
);
354 /* <4> set mac->sband to wiphy->sband */
355 hw
->wiphy
->bands
[IEEE80211_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
[IEEE80211_BAND_2GHZ
]);
361 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
362 * to default value(1T1R) */
363 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]),
365 sizeof(struct ieee80211_supported_band
));
367 /* <3> init ht cap base on ant_num */
368 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
370 /* <4> set mac->sband to wiphy->sband */
371 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = sband
;
372 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
373 /* <1> use mac->bands as mem for hw->wiphy->bands */
374 sband
= &(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]);
376 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
377 * to default value(1T1R) */
378 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]),
380 sizeof(struct ieee80211_supported_band
));
382 /* <3> init ht cap base on ant_num */
383 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
385 _rtl_init_hw_vht_capab(hw
, &sband
->vht_cap
);
387 /* <4> set mac->sband to wiphy->sband */
388 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = sband
;
390 RT_TRACE(COMP_INIT
, DBG_EMERG
,
391 ("Err BAND %d\n", rtlhal
->current_bandtype
));
394 /* <5> set hw caps */
395 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
396 IEEE80211_HW_RX_INCLUDES_FCS
|
397 IEEE80211_HW_AMPDU_AGGREGATION
|
398 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
399 IEEE80211_HW_CONNECTION_MONITOR
|
400 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
401 IEEE80211_HW_MFP_CAPABLE
| 0;
403 /* swlps or hwlps has been set in diff chip in init_sw_vars */
404 if (rtlpriv
->psc
.b_swctrl_lps
)
405 hw
->flags
|= IEEE80211_HW_SUPPORTS_PS
|
406 IEEE80211_HW_PS_NULLFUNC_STACK
|
407 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
409 /*<delete in kernel start>*/
410 hw
->wiphy
->interface_modes
=
411 BIT(NL80211_IFTYPE_AP
) |
412 BIT(NL80211_IFTYPE_STATION
) |
413 BIT(NL80211_IFTYPE_ADHOC
) |
414 BIT(NL80211_IFTYPE_MESH_POINT
) |
415 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
416 BIT(NL80211_IFTYPE_P2P_GO
);
417 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
419 hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
421 hw
->wiphy
->rts_threshold
= 2347;
424 hw
->extra_tx_headroom
= RTL_TX_HEADER_SIZE
;
426 /* TODO: Correct this value for our hw */
427 /* TODO: define these hard code value */
428 /* hw->channel_change_time = 100; kernel does not use it*/
429 hw
->max_listen_interval
= 10;
430 hw
->max_rate_tries
= 4;
431 /* hw->max_rates = 1; */
432 hw
->sta_data_size
= sizeof(struct rtl_sta_info
);
434 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
436 if (rtlpriv
->psc
.wo_wlan_mode
) {
437 if (rtlpriv
->psc
.wo_wlan_mode
& WAKE_ON_MAGIC_PACKET
)
438 rtlpriv
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
;
439 if (rtlpriv
->psc
.wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) {
440 rtlpriv
->wowlan
.n_patterns
=
441 MAX_SUPPORT_WOL_PATTERN_NUM
;
442 rtlpriv
->wowlan
.pattern_min_len
= MIN_WOL_PATTERN_SIZE
;
443 rtlpriv
->wowlan
.pattern_max_len
= MAX_WOL_PATTERN_SIZE
;
445 hw
->wiphy
->wowlan
= &(rtlpriv
->wowlan
);
449 /* <6> mac address */
450 if (is_valid_ether_addr(rtlefuse
->dev_addr
)) {
451 SET_IEEE80211_PERM_ADDR(hw
, rtlefuse
->dev_addr
);
453 u8 rtlmac
[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
454 get_random_bytes((rtlmac
+ (ETH_ALEN
- 1)), 1);
455 SET_IEEE80211_PERM_ADDR(hw
, rtlmac
);
459 static void _rtl_init_deferred_work(struct ieee80211_hw
*hw
)
461 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
464 init_timer(&rtlpriv
->works
.watchdog_timer
);
465 setup_timer(&rtlpriv
->works
.watchdog_timer
,
466 rtl92e_watch_dog_timer_callback
, (unsigned long)hw
);
467 init_timer(&rtlpriv
->works
.dualmac_easyconcurrent_retrytimer
);
468 setup_timer(&rtlpriv
->works
.dualmac_easyconcurrent_retrytimer
,
469 rtl92e_easy_concurrent_retrytimer_callback
, (unsigned long)hw
);
471 rtlpriv
->works
.hw
= hw
;
472 rtlpriv
->works
.rtl_wq
= alloc_workqueue(rtlpriv
->cfg
->name
, 0, 0);
473 INIT_DELAYED_WORK(&rtlpriv
->works
.watchdog_wq
,
474 (void *)rtl92e_watchdog_wq_callback
);
475 INIT_DELAYED_WORK(&rtlpriv
->works
.ips_nic_off_wq
,
476 (void *)rtl92e_ips_nic_off_wq_callback
);
477 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_work
,
478 (void *)rtl92e_swlps_wq_callback
);
479 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_rfon_wq
,
480 (void *)rtl92e_swlps_rfon_wq_callback
);
481 INIT_DELAYED_WORK(&rtlpriv
->works
.fwevt_wq
,
482 (void *)rtl92e_fwevt_wq_callback
);
485 void rtl92e_deinit_deferred_work(struct ieee80211_hw
*hw
)
487 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
489 del_timer_sync(&rtlpriv
->works
.watchdog_timer
);
491 cancel_delayed_work(&rtlpriv
->works
.watchdog_wq
);
492 cancel_delayed_work(&rtlpriv
->works
.ips_nic_off_wq
);
493 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
494 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
495 cancel_delayed_work(&rtlpriv
->works
.fwevt_wq
);
498 void rtl92e_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
= 1;
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
);
525 void rtl92e_deinit_rfkill(struct ieee80211_hw
*hw
)
527 wiphy_rfkill_stop_polling(hw
->wiphy
);
531 static void rtl_init_vif(struct ieee80211_hw
*hw
)
533 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
535 INIT_LIST_HEAD(&rtlpriv
->vif_priv
.vif_list
);
537 rtlpriv
->vif_priv
.vifs
= 0;
541 int rtl92e_init_core(struct ieee80211_hw
*hw
)
543 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
544 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
546 /* <1> init mac80211 */
547 _rtl_init_mac80211(hw
);
549 rtlmac
->link_state
= MAC80211_NOLINK
;
551 /* <2> rate control register */
552 hw
->rate_control_algorithm
= "rtl_rc";
555 * <3> init CRDA must come after init
556 * mac80211 hw in _rtl_init_mac80211.
558 if (rtl92e_regd_init(hw
, rtl92e_reg_notifier
)) {
559 RT_TRACE(COMP_ERR
, DBG_EMERG
, ("REGD init failed\n"));
564 mutex_init(&rtlpriv
->locks
.conf_mutex
);
565 spin_lock_init(&rtlpriv
->locks
.ips_lock
);
566 spin_lock_init(&rtlpriv
->locks
.irq_th_lock
);
567 spin_lock_init(&rtlpriv
->locks
.h2c_lock
);
568 spin_lock_init(&rtlpriv
->locks
.rf_ps_lock
);
569 spin_lock_init(&rtlpriv
->locks
.rf_lock
);
570 spin_lock_init(&rtlpriv
->locks
.lps_lock
);
571 spin_lock_init(&rtlpriv
->locks
.waitq_lock
);
572 spin_lock_init(&rtlpriv
->locks
.entry_list_lock
);
573 spin_lock_init(&rtlpriv
->locks
.cck_and_rw_pagea_lock
);
574 spin_lock_init(&rtlpriv
->locks
.check_sendpkt_lock
);
575 spin_lock_init(&rtlpriv
->locks
.fw_ps_lock
);
576 spin_lock_init(&rtlpriv
->locks
.iqk_lock
);
578 INIT_LIST_HEAD(&rtlpriv
->entry_list
);
580 /* <6> init deferred work */
581 _rtl_init_deferred_work(hw
);
591 void rtl92e_deinit_core(struct ieee80211_hw
*hw
)
595 void rtl92e_init_rx_config(struct ieee80211_hw
*hw
)
597 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
598 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
600 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(&mac
->rx_conf
));
603 /*********************************************************
605 * tx information functions
607 *********************************************************/
608 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw
*hw
,
609 struct rtl_tcb_desc
*tcb_desc
,
610 struct ieee80211_tx_info
*info
)
612 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
613 u8 rate_flag
= info
->control
.rates
[0].flags
;
615 tcb_desc
->use_shortpreamble
= false;
617 /* 1M can only use Long Preamble. 11B spec */
618 if (tcb_desc
->hw_rate
== rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE1M
])
620 else if (rate_flag
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
621 tcb_desc
->use_shortpreamble
= true;
626 static void _rtl_query_shortgi(struct ieee80211_hw
*hw
,
627 struct ieee80211_sta
*sta
,
628 struct rtl_tcb_desc
*tcb_desc
,
629 struct ieee80211_tx_info
*info
)
631 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
632 u8 rate_flag
= info
->control
.rates
[0].flags
;
633 u8 sgi_40
= 0, sgi_20
= 0, bw_40
= 0;
634 u8 sgi_80
= 0, bw_80
= 0;
635 tcb_desc
->use_shortgi
= false;
640 sgi_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
;
641 sgi_20
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
;
642 sgi_80
= sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SHORT_GI_80
;
644 if (!(sta
->ht_cap
.ht_supported
) && !(sta
->vht_cap
.vht_supported
))
647 if (!sgi_40
&& !sgi_20
)
650 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
653 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
654 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
655 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
656 bw_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
657 bw_80
= sta
->vht_cap
.vht_supported
;
662 tcb_desc
->use_shortgi
= true;
664 tcb_desc
->use_shortgi
= false;
667 tcb_desc
->use_shortgi
= true;
668 else if (!bw_40
&& sgi_20
)
669 tcb_desc
->use_shortgi
= true;
672 if (!(rate_flag
& IEEE80211_TX_RC_SHORT_GI
))
673 tcb_desc
->use_shortgi
= false;
676 static void _rtl_query_protection_mode(struct ieee80211_hw
*hw
,
677 struct rtl_tcb_desc
*tcb_desc
,
678 struct ieee80211_tx_info
*info
)
680 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
681 u8 rate_flag
= info
->control
.rates
[0].flags
;
683 /* Common Settings */
684 tcb_desc
->b_rts_stbc
= false;
685 tcb_desc
->b_cts_enable
= false;
686 tcb_desc
->rts_sc
= 0;
687 tcb_desc
->b_rts_bw
= false;
688 tcb_desc
->b_rts_use_shortpreamble
= false;
689 tcb_desc
->b_rts_use_shortgi
= false;
691 if (rate_flag
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
692 /* Use CTS-to-SELF in protection mode. */
693 tcb_desc
->b_rts_enable
= true;
694 tcb_desc
->b_cts_enable
= true;
695 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
696 } else if (rate_flag
& IEEE80211_TX_RC_USE_RTS_CTS
) {
697 /* Use RTS-CTS in protection mode. */
698 tcb_desc
->b_rts_enable
= true;
699 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
703 static void _rtl_txrate_selectmode(struct ieee80211_hw
*hw
,
704 struct ieee80211_sta
*sta
,
705 struct rtl_tcb_desc
*tcb_desc
)
707 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
708 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
709 struct rtl_sta_info
*sta_entry
= NULL
;
713 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
714 ratr_index
= sta_entry
->ratr_index
;
716 if (!tcb_desc
->disable_ratefallback
|| !tcb_desc
->use_driver_rate
) {
717 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
718 tcb_desc
->ratr_index
= 0;
719 } else if (mac
->opmode
== NL80211_IFTYPE_ADHOC
||
720 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
721 if (tcb_desc
->b_multicast
|| tcb_desc
->b_broadcast
) {
723 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE2M
];
724 tcb_desc
->use_driver_rate
= 1;
725 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
727 tcb_desc
->ratr_index
= ratr_index
;
729 } else if (mac
->opmode
== NL80211_IFTYPE_AP
) {
730 tcb_desc
->ratr_index
= ratr_index
;
734 if (rtlpriv
->dm
.b_useramask
) {
735 tcb_desc
->ratr_index
= ratr_index
;
736 /* TODO we will differentiate adhoc and station futrue */
737 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
738 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
739 tcb_desc
->mac_id
= 0;
741 if (mac
->mode
== WIRELESS_MODE_AC_5G
)
742 tcb_desc
->ratr_index
=
743 RATR_INX_WIRELESS_AC_5N
;
744 else if (mac
->mode
== WIRELESS_MODE_AC_24G
)
745 tcb_desc
->ratr_index
=
746 RATR_INX_WIRELESS_AC_24N
;
747 else if (mac
->mode
== WIRELESS_MODE_N_24G
)
748 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NGB
;
749 else if (mac
->mode
== WIRELESS_MODE_N_5G
)
750 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NG
;
751 else if (mac
->mode
& WIRELESS_MODE_G
)
752 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_GB
;
753 else if (mac
->mode
& WIRELESS_MODE_B
)
754 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_B
;
755 else if (mac
->mode
& WIRELESS_MODE_A
)
756 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_G
;
758 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
759 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
762 tcb_desc
->mac_id
= sta
->aid
+ 1;
764 tcb_desc
->mac_id
= 1;
766 tcb_desc
->mac_id
= 0;
772 static void _rtl_query_bandwidth_mode(struct ieee80211_hw
*hw
,
773 struct ieee80211_sta
*sta
,
774 struct rtl_tcb_desc
*tcb_desc
)
776 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
777 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
779 tcb_desc
->packet_bw
= 0;
782 if (mac
->opmode
== NL80211_IFTYPE_AP
||
783 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
784 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
785 if (!(sta
->ht_cap
.ht_supported
) ||
786 !(sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
788 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
789 if (!mac
->bw_40
|| !(sta
->ht_cap
.ht_supported
))
792 if (tcb_desc
->b_multicast
|| tcb_desc
->b_broadcast
)
795 /*use legency rate, shall use 20MHz */
796 if (tcb_desc
->hw_rate
<= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
])
799 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_20_40
;
801 if (rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8812AE
||
802 rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8821AE
) {
803 if (mac
->opmode
== NL80211_IFTYPE_AP
||
804 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
805 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
806 if (!(sta
->vht_cap
.vht_supported
)) {
808 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
810 !(sta
->vht_cap
.vht_supported
))
814 if (tcb_desc
->hw_rate
<=
815 rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
])
817 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_80
;
821 static u8
_rtl_get_vht_highest_n_rate(struct ieee80211_hw
*hw
,
822 struct ieee80211_sta
*sta
)
824 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
825 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
827 u16 map
= le16_to_cpu(sta
->vht_cap
.vht_mcs
.tx_mcs_map
);
829 if ((get_rf_type(rtlphy
) == RF_2T2R
) &&
830 (map
& 0x000c) != 0x000c0) {
831 if ((map
& 0x000c) >> 2 == IEEE80211_VHT_MCS_SUPPORT_0_7
)
833 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS7
];
834 else if ((map
& 0x000c) >> 2 == IEEE80211_VHT_MCS_SUPPORT_0_8
)
835 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
837 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
839 if ((map
& 0x0003) == IEEE80211_VHT_MCS_SUPPORT_0_7
)
840 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS7
];
841 else if ((map
& 0x0003) == IEEE80211_VHT_MCS_SUPPORT_0_8
)
842 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
844 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
850 static u8
_rtl_get_highest_n_rate(struct ieee80211_hw
*hw
,
851 struct ieee80211_sta
*sta
)
853 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
854 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
857 if ((get_rf_type(rtlphy
) == RF_2T2R
) &&
858 (sta
->ht_cap
.mcs
.rx_mask
[1] != 0))
859 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
];
861 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS7
];
866 void stg_rtl_get_tcb_desc(struct ieee80211_hw
*hw
,
867 struct ieee80211_tx_info
*info
,
868 struct ieee80211_sta
*sta
,
869 struct sk_buff
*skb
, struct rtl_tcb_desc
*tcb_desc
)
871 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
872 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
873 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
874 struct ieee80211_rate
*txrate
;
875 __le16 fc
= rtl_get_fc(skb
);
877 txrate
= ieee80211_get_tx_rate(hw
, info
);
879 tcb_desc
->hw_rate
= txrate
->hw_value
;
881 if (ieee80211_is_data(fc
)) {
883 *we set data rate INX 0
884 *in rtl_rc.c if skb is special data or
885 *mgt which need low data rate.
889 *So tcb_desc->hw_rate is just used for
890 *special data and mgt frames
892 if (info
->control
.rates
[0].idx
== 0 ||
893 ieee80211_is_nullfunc(fc
)) {
894 tcb_desc
->use_driver_rate
= true;
895 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
897 tcb_desc
->disable_ratefallback
= 1;
900 *because hw will nerver use hw_rate
901 *when tcb_desc->use_driver_rate = false
902 *so we never set highest N rate here,
903 *and N rate will all be controled by FW
904 *when tcb_desc->use_driver_rate = false
906 if (sta
&& sta
->vht_cap
.vht_supported
) {
908 _rtl_get_vht_highest_n_rate(hw
, sta
);
909 } else if (sta
&& (sta
->ht_cap
.ht_supported
)) {
911 _rtl_get_highest_n_rate(hw
, sta
);
913 if (rtlmac
->mode
== WIRELESS_MODE_B
) {
915 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE11M
];
918 rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
];
923 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)))
924 tcb_desc
->b_multicast
= 1;
925 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr
)))
926 tcb_desc
->b_broadcast
= 1;
928 _rtl_txrate_selectmode(hw
, sta
, tcb_desc
);
929 _rtl_query_bandwidth_mode(hw
, sta
, tcb_desc
);
930 _rtl_qurey_shortpreamble_mode(hw
, tcb_desc
, info
);
931 _rtl_query_shortgi(hw
, sta
, tcb_desc
, info
);
932 _rtl_query_protection_mode(hw
, tcb_desc
, info
);
934 tcb_desc
->use_driver_rate
= true;
935 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
936 tcb_desc
->disable_ratefallback
= 1;
937 tcb_desc
->mac_id
= 0;
938 tcb_desc
->packet_bw
= 0;
941 EXPORT_SYMBOL(stg_rtl_get_tcb_desc
);
943 bool rtl92e_tx_mgmt_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
945 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
946 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
947 __le16 fc
= rtl_get_fc(skb
);
949 if (rtlpriv
->dm
.supp_phymode_switch
&&
950 mac
->link_state
< MAC80211_LINKED
&&
951 (ieee80211_is_auth(fc
) || ieee80211_is_probe_req(fc
))) {
952 if (rtlpriv
->cfg
->ops
->check_switch_to_dmdp
)
953 rtlpriv
->cfg
->ops
->check_switch_to_dmdp(hw
);
955 if (ieee80211_is_auth(fc
)) {
956 RT_TRACE(COMP_SEND
, DBG_DMESG
, ("MAC80211_LINKING\n"));
957 rtl92e_ips_nic_on(hw
);
959 mac
->link_state
= MAC80211_LINKING
;
961 rtlpriv
->phy
.b_need_iqk
= true;
966 struct sk_buff
*rtl92e_make_del_ba(struct ieee80211_hw
*hw
, u8
*sa
,
969 bool rtl92e_action_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
971 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
972 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
973 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
974 __le16 fc
= rtl_get_fc(skb
);
975 u8
*act
= (u8
*)(((u8
*)skb
->data
+ MAC80211_3ADDR_LEN
));
978 if (!ieee80211_is_action(fc
))
987 if (mac
->act_scanning
)
990 RT_TRACE((COMP_SEND
| COMP_RECV
), DBG_DMESG
,
991 ("%s ACT_ADDBAREQ From:%pM\n",
992 is_tx
? "Tx" : "Rx", hdr
->addr2
));
993 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "req\n",
994 skb
->data
, skb
->len
);
996 struct ieee80211_sta
*sta
= NULL
;
997 struct rtl_sta_info
*sta_entry
= NULL
;
998 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
999 u16 capab
= 0, tid
= 0;
1000 struct rtl_tid_data
*tid_data
;
1001 struct sk_buff
*skb_delba
= NULL
;
1002 struct ieee80211_rx_status rx_status
= { 0 };
1005 sta
= rtl_find_sta(hw
, hdr
->addr3
);
1007 RT_TRACE((COMP_SEND
| COMP_RECV
),
1008 DBG_TRACE
, ("sta is NULL\n"));
1014 (struct rtl_sta_info
*)sta
->drv_priv
;
1019 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1021 IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1022 tid_data
= &sta_entry
->tids
[tid
];
1023 if (tid_data
->agg
.rx_agg_state
==
1025 skb_delba
= rtl92e_make_del_ba(hw
,
1031 hw
->conf
.chandef
.chan
->center_freq
;
1033 hw
->conf
.chandef
.chan
->band
;
1034 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1035 rx_status
.flag
|= RX_FLAG_MACTIME_MPDU
;
1036 rx_status
.rate_idx
= 0;
1037 rx_status
.signal
= 50 + 10;
1038 memcpy(IEEE80211_SKB_RXCB(skb_delba
),
1039 &rx_status
, sizeof(rx_status
));
1040 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1042 skb_delba
->data
, skb_delba
->len
);
1043 ieee80211_rx_irqsafe(hw
, skb_delba
);
1050 RT_TRACE((COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1051 ("%s ACT_ADDBARSP From :%pM\n",
1052 is_tx
? "Tx" : "Rx", hdr
->addr2
));
1055 RT_TRACE((COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1056 ("ACT_ADDBADEL From :%pM\n", hdr
->addr2
));
1067 /*should call before software enc*/
1068 u8
rtl92e_is_special_data(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1071 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1072 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1073 __le16 fc
= rtl_get_fc(skb
);
1075 u8 mac_hdr_len
= ieee80211_get_hdrlen_from_skb(skb
);
1076 const struct iphdr
*ip
;
1078 if (!ieee80211_is_data(fc
))
1081 ip
= (struct iphdr
*)((u8
*)skb
->data
+ mac_hdr_len
+
1082 SNAP_SIZE
+ PROTOC_TYPE_SIZE
);
1083 ether_type
= be16_to_cpup((__be16
*)
1084 (skb
->data
+ mac_hdr_len
+ SNAP_SIZE
));
1086 if (ETH_P_IP
== ether_type
) {
1087 if (IPPROTO_UDP
== ip
->protocol
) {
1088 struct udphdr
*udp
= (struct udphdr
*)((u8
*)ip
+
1090 if (((((u8
*)udp
)[1] == 68) &&
1091 (((u8
*)udp
)[3] == 67)) ||
1092 ((((u8
*)udp
)[1] == 67) &&
1093 (((u8
*)udp
)[3] == 68))) {
1095 * 68 : UDP BOOTP client
1096 * 67 : UDP BOOTP server
1098 RT_TRACE((COMP_SEND
| COMP_RECV
),
1099 DBG_DMESG
, ("dhcp %s !!\n",
1100 (is_tx
) ? "Tx" : "Rx"));
1103 rtlpriv
->ra
.is_special_data
= true;
1104 if (rtlpriv
->cfg
->ops
->get_btc_status())
1105 rtlpriv
->btcoexist
.btc_ops
->btc_special_packet_notify(
1107 rtl92e_lps_leave(hw
);
1108 ppsc
->last_delaylps_stamp_jiffies
=
1115 } else if (ETH_P_ARP
== ether_type
) {
1117 rtlpriv
->ra
.is_special_data
= true;
1118 if (rtlpriv
->cfg
->ops
->get_btc_status())
1119 rtlpriv
->btcoexist
.btc_ops
->btc_special_packet_notify(
1121 rtl92e_lps_leave(hw
);
1122 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1126 } else if (ETH_P_PAE
== ether_type
) {
1127 RT_TRACE((COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1128 ("802.1X %s EAPOL pkt!!\n", (is_tx
) ? "Tx" : "Rx"));
1131 rtlpriv
->ra
.is_special_data
= true;
1132 rtl92e_lps_leave(hw
);
1133 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1137 } else if (0x86DD == ether_type
) {
1142 rtlpriv
->ra
.is_special_data
= false;
1146 /*********************************************************
1148 * functions called by core.c
1150 *********************************************************/
1151 int rtl92e_tx_agg_start(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1152 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
1154 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1155 struct rtl_tid_data
*tid_data
;
1156 struct rtl_sta_info
*sta_entry
= NULL
;
1161 if (unlikely(tid
>= MAX_TID_COUNT
))
1164 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1167 tid_data
= &sta_entry
->tids
[tid
];
1169 RT_TRACE(COMP_SEND
, DBG_DMESG
,
1170 ("on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1171 tid_data
->seq_number
));
1173 *ssn
= tid_data
->seq_number
;
1174 tid_data
->agg
.agg_state
= RTL_AGG_START
;
1176 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1180 int rtl92e_tx_agg_stop(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1181 struct ieee80211_sta
*sta
, u16 tid
)
1183 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1184 struct rtl_tid_data
*tid_data
;
1185 struct rtl_sta_info
*sta_entry
= NULL
;
1190 /* Comparing an array to null is not useful */
1192 RT_TRACE(COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
1196 RT_TRACE(COMP_SEND
, DBG_DMESG
,
1197 ("on ra = %pM tid = %d\n", sta
->addr
, tid
));
1199 if (unlikely(tid
>= MAX_TID_COUNT
))
1202 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1203 tid_data
= &sta_entry
->tids
[tid
];
1204 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_STOP
;
1206 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1210 int rtl92e_rx_agg_start(struct ieee80211_hw
*hw
,
1211 struct ieee80211_sta
*sta
, u16 tid
)
1213 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1214 struct rtl_tid_data
*tid_data
;
1215 struct rtl_sta_info
*sta_entry
= NULL
;
1220 if (unlikely(tid
>= MAX_TID_COUNT
))
1223 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1226 tid_data
= &sta_entry
->tids
[tid
];
1228 RT_TRACE(COMP_RECV
, DBG_DMESG
,
1229 ("on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1230 tid_data
->seq_number
));
1232 tid_data
->agg
.rx_agg_state
= RTL_RX_AGG_START
;
1236 int rtl92e_rx_agg_stop(struct ieee80211_hw
*hw
,
1237 struct ieee80211_sta
*sta
, u16 tid
)
1239 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1240 struct rtl_tid_data
*tid_data
;
1241 struct rtl_sta_info
*sta_entry
= NULL
;
1246 /* Comparing an array to null is not useful */
1248 RT_TRACE(COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
1252 RT_TRACE(COMP_SEND
, DBG_DMESG
,
1253 ("on ra = %pM tid = %d\n", sta
->addr
, tid
));
1255 if (unlikely(tid
>= MAX_TID_COUNT
))
1258 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1259 tid_data
= &sta_entry
->tids
[tid
];
1260 sta_entry
->tids
[tid
].agg
.rx_agg_state
= RTL_RX_AGG_STOP
;
1265 int rtl92e_tx_agg_oper(struct ieee80211_hw
*hw
,
1266 struct ieee80211_sta
*sta
, u16 tid
)
1268 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1269 struct rtl_tid_data
*tid_data
;
1270 struct rtl_sta_info
*sta_entry
= NULL
;
1275 /* Comparing an array to null is not useful */
1277 RT_TRACE(COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
1281 RT_TRACE(COMP_SEND
, DBG_DMESG
,
1282 ("on ra = %pM tid = %d\n", sta
->addr
, tid
));
1284 if (unlikely(tid
>= MAX_TID_COUNT
))
1287 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1288 tid_data
= &sta_entry
->tids
[tid
];
1289 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_OPERATIONAL
;
1294 /*********************************************************
1296 * wq & timer callback functions
1298 *********************************************************/
1299 /* this function is used for roaming */
1300 void rtl92e_beacon_statistic(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1302 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1303 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1305 if (rtlpriv
->mac80211
.opmode
!= NL80211_IFTYPE_STATION
)
1308 if (rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
)
1311 /* check if this really is a beacon */
1312 if (!ieee80211_is_beacon(hdr
->frame_control
) &&
1313 !ieee80211_is_probe_resp(hdr
->frame_control
))
1316 /* min. beacon length + FCS_LEN */
1317 if (skb
->len
<= 40 + FCS_LEN
)
1320 /* and only beacons from the associated BSSID, please */
1321 if (!ether_addr_equal(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
1324 rtlpriv
->link_info
.bcn_rx_inperiod
++;
1327 void rtl92e_watchdog_wq_callback(void *data
)
1329 struct rtl_works
*rtlworks
= container_of_dwork_rtl(data
,
1332 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1333 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1334 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1335 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1336 bool b_busytraffic
= false;
1337 bool b_tx_busy_traffic
= false;
1338 bool b_rx_busy_traffic
= false;
1339 bool b_higher_busytraffic
= false;
1340 bool b_higher_busyrxtraffic
= false;
1342 u32 rx_cnt_inp4eriod
= 0;
1343 u32 tx_cnt_inp4eriod
= 0;
1344 u32 aver_rx_cnt_inperiod
= 0;
1345 u32 aver_tx_cnt_inperiod
= 0;
1346 u32 aver_tidtx_inperiod
[MAX_TID_COUNT
] = {0};
1347 u32 tidtx_inp4eriod
[MAX_TID_COUNT
] = {0};
1348 bool benter_ps
= false;
1350 if (is_hal_stop(rtlhal
))
1353 /* <1> Determine if action frame is allowed */
1354 if (mac
->link_state
> MAC80211_NOLINK
) {
1355 if (mac
->cnt_after_linked
< 20)
1356 mac
->cnt_after_linked
++;
1358 mac
->cnt_after_linked
= 0;
1361 /* <2> to check if traffic busy, if
1362 * busytraffic we don't change channel */
1363 if (mac
->link_state
>= MAC80211_LINKED
) {
1364 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1365 for (idx
= 0; idx
<= 2; idx
++) {
1366 rtlpriv
->link_info
.num_rx_in4period
[idx
] =
1367 rtlpriv
->link_info
.num_rx_in4period
[idx
+ 1];
1368 rtlpriv
->link_info
.num_tx_in4period
[idx
] =
1369 rtlpriv
->link_info
.num_tx_in4period
[idx
+ 1];
1371 rtlpriv
->link_info
.num_rx_in4period
[3] =
1372 rtlpriv
->link_info
.num_rx_inperiod
;
1373 rtlpriv
->link_info
.num_tx_in4period
[3] =
1374 rtlpriv
->link_info
.num_tx_inperiod
;
1375 for (idx
= 0; idx
<= 3; idx
++) {
1377 rtlpriv
->link_info
.num_rx_in4period
[idx
];
1379 rtlpriv
->link_info
.num_tx_in4period
[idx
];
1381 aver_rx_cnt_inperiod
= rx_cnt_inp4eriod
/ 4;
1382 aver_tx_cnt_inperiod
= tx_cnt_inp4eriod
/ 4;
1384 /* (2) check traffic busy */
1385 if (aver_rx_cnt_inperiod
> 100 || aver_tx_cnt_inperiod
> 100) {
1386 b_busytraffic
= true;
1387 if (aver_rx_cnt_inperiod
> aver_tx_cnt_inperiod
)
1388 b_rx_busy_traffic
= true;
1390 b_tx_busy_traffic
= false;
1393 /* Higher Tx/Rx data. */
1394 if (aver_rx_cnt_inperiod
> 4000 ||
1395 aver_tx_cnt_inperiod
> 4000) {
1396 b_higher_busytraffic
= true;
1398 /* Extremely high Rx data. */
1399 if (aver_rx_cnt_inperiod
> 5000)
1400 b_higher_busyrxtraffic
= true;
1403 /* check every tid's tx traffic */
1404 for (tid
= 0; tid
<= 7; tid
++) {
1405 for (idx
= 0; idx
<= 2; idx
++)
1406 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
] =
1407 rtlpriv
->link_info
.tidtx_in4period
[tid
]
1409 rtlpriv
->link_info
.tidtx_in4period
[tid
][3] =
1410 rtlpriv
->link_info
.tidtx_inperiod
[tid
];
1412 for (idx
= 0; idx
<= 3; idx
++)
1413 tidtx_inp4eriod
[tid
] +=
1414 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
];
1415 aver_tidtx_inperiod
[tid
] = tidtx_inp4eriod
[tid
] / 4;
1416 if (aver_tidtx_inperiod
[tid
] > 5000)
1417 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1420 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1424 if (((rtlpriv
->link_info
.num_rx_inperiod
+
1425 rtlpriv
->link_info
.num_tx_inperiod
) > 8) ||
1426 (rtlpriv
->link_info
.num_rx_inperiod
> 2))
1431 /* LeisurePS only work in infra mode. */
1433 rtl92e_lps_enter(hw
);
1435 rtl92e_lps_leave(hw
);
1438 rtlpriv
->link_info
.num_rx_inperiod
= 0;
1439 rtlpriv
->link_info
.num_tx_inperiod
= 0;
1440 for (tid
= 0; tid
<= 7; tid
++)
1441 rtlpriv
->link_info
.tidtx_inperiod
[tid
] = 0;
1443 rtlpriv
->link_info
.b_busytraffic
= b_busytraffic
;
1444 rtlpriv
->link_info
.b_rx_busy_traffic
= b_rx_busy_traffic
;
1445 rtlpriv
->link_info
.b_tx_busy_traffic
= b_tx_busy_traffic
;
1446 rtlpriv
->link_info
.b_higher_busytraffic
= b_higher_busytraffic
;
1447 rtlpriv
->link_info
.b_higher_busyrxtraffic
= b_higher_busyrxtraffic
;
1450 rtlpriv
->cfg
->ops
->dm_watchdog(hw
);
1453 if (mac
->link_state
== MAC80211_LINKED
&&
1454 mac
->opmode
== NL80211_IFTYPE_STATION
) {
1455 if ((rtlpriv
->link_info
.bcn_rx_inperiod
+
1456 rtlpriv
->link_info
.num_rx_inperiod
) == 0) {
1457 rtlpriv
->link_info
.roam_times
++;
1458 RT_TRACE(COMP_ERR
, DBG_DMESG
,
1459 ("AP off for %d s\n",
1460 (rtlpriv
->link_info
.roam_times
* 2)));
1462 /* if we can't recv beacon for 10s,
1463 * we should reconnect this AP */
1464 if (rtlpriv
->link_info
.roam_times
>= 5) {
1465 RT_TRACE(COMP_ERR
, DBG_EMERG
,
1466 ("AP off, try to reconnect now\n"));
1467 rtlpriv
->link_info
.roam_times
= 0;
1468 ieee80211_connection_loss(
1469 rtlpriv
->mac80211
.vif
);
1472 rtlpriv
->link_info
.roam_times
= 0;
1476 if (rtlpriv
->cfg
->ops
->get_btc_status())
1477 rtlpriv
->btcoexist
.btc_ops
->btc_periodical(rtlpriv
);
1479 rtlpriv
->link_info
.bcn_rx_inperiod
= 0;
1482 void rtl92e_watch_dog_timer_callback(unsigned long data
)
1484 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
1485 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1487 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
1488 &rtlpriv
->works
.watchdog_wq
, 0);
1490 mod_timer(&rtlpriv
->works
.watchdog_timer
,
1491 jiffies
+ MSECS(RTL_WATCH_DOG_TIME
));
1493 void rtl92e_fwevt_wq_callback(void *data
)
1495 struct rtl_works
*rtlworks
=
1496 container_of_dwork_rtl(data
, struct rtl_works
, fwevt_wq
);
1497 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1498 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1500 rtlpriv
->cfg
->ops
->c2h_command_handle(hw
);
1502 void rtl92e_easy_concurrent_retrytimer_callback(unsigned long data
)
1504 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
1505 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1506 struct rtl_priv
*buddy_priv
= rtlpriv
->buddy_priv
;
1508 if (buddy_priv
== NULL
)
1511 rtlpriv
->cfg
->ops
->dualmac_easy_concurrent(hw
);
1513 /*********************************************************
1515 * frame process functions
1517 *********************************************************/
1518 u8
*rtl92e_find_ie(u8
*data
, unsigned int len
, u8 ie
)
1520 struct ieee80211_mgmt
*mgmt
= (void *)data
;
1523 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
1526 if (pos
+ 2 + pos
[1] > end
)
1537 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1538 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1539 static struct sk_buff
*rtl_make_smps_action(struct ieee80211_hw
*hw
,
1540 enum ieee80211_smps_mode smps
,
1543 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1544 struct sk_buff
*skb
;
1545 struct ieee80211_mgmt_compat
*action_frame
;
1547 /* 27 = header + category + action + smps mode */
1548 skb
= dev_alloc_skb(27 + hw
->extra_tx_headroom
);
1552 skb_reserve(skb
, hw
->extra_tx_headroom
);
1553 action_frame
= (void *)skb_put(skb
, 27);
1554 memset(action_frame
, 0, 27);
1555 ether_addr_copy(action_frame
->da
, da
);
1556 ether_addr_copy(action_frame
->sa
, rtlefuse
->dev_addr
);
1557 ether_addr_copy(action_frame
->bssid
, bssid
);
1558 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1559 IEEE80211_STYPE_ACTION
);
1560 action_frame
->u
.action
.category
= WLAN_CATEGORY_HT
;
1561 action_frame
->u
.action
.u
.ht_smps
.action
= WLAN_HT_ACTION_SMPS
;
1563 case IEEE80211_SMPS_AUTOMATIC
:/* 0 */
1564 case IEEE80211_SMPS_NUM_MODES
:/* 4 */
1566 /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
1567 * According to Kernel Code, here is right.
1569 case IEEE80211_SMPS_OFF
:/* 1 */ /*MIMO_PS_NOLIMIT*/
1570 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1571 WLAN_HT_SMPS_CONTROL_DISABLED
;/* 0 */
1573 case IEEE80211_SMPS_STATIC
:/* 2 */ /*MIMO_PS_STATIC*/
1574 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1575 WLAN_HT_SMPS_CONTROL_STATIC
;/* 1 */
1577 case IEEE80211_SMPS_DYNAMIC
:/* 3 */ /*MIMO_PS_DYNAMIC*/
1578 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1579 WLAN_HT_SMPS_CONTROL_DYNAMIC
;/* 3 */
1586 int stg_rtl_send_smps_action(struct ieee80211_hw
*hw
,
1587 struct ieee80211_sta
*sta
,
1588 enum ieee80211_smps_mode smps
)
1590 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1591 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1592 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1593 struct sk_buff
*skb
= NULL
;
1594 struct rtl_tcb_desc tcb_desc
;
1595 u8 bssid
[ETH_ALEN
] = {0};
1597 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1599 if (rtlpriv
->mac80211
.act_scanning
)
1605 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
1608 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1611 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_AP
)
1612 ether_addr_copy(bssid
, rtlpriv
->efuse
.dev_addr
);
1614 ether_addr_copy(bssid
, rtlpriv
->mac80211
.bssid
);
1616 skb
= rtl_make_smps_action(hw
, smps
, sta
->addr
, bssid
);
1617 /* this is a type = mgmt * stype = action frame */
1619 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1620 struct rtl_sta_info
*sta_entry
=
1621 (struct rtl_sta_info
*)sta
->drv_priv
;
1622 sta_entry
->mimo_ps
= smps
;
1623 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
1625 info
->control
.rates
[0].idx
= 0;
1626 info
->band
= hw
->conf
.chandef
.chan
->band
;
1627 rtlpriv
->intf_ops
->adapter_tx(hw
, sta
, skb
, &tcb_desc
);
1634 EXPORT_SYMBOL(stg_rtl_send_smps_action
);
1636 /* because mac80211 have issues when can receive del ba
1637 * so here we just make a fake del_ba if we receive a ba_req
1638 * but rx_agg was opened to let mac80211 release some ba
1639 * related resources, so please this del_ba for tx */
1640 struct sk_buff
*rtl92e_make_del_ba(struct ieee80211_hw
*hw
,
1641 u8
*sa
, u8
*bssid
, u16 tid
)
1643 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1644 struct sk_buff
*skb
;
1645 struct ieee80211_mgmt
*action_frame
;
1648 /* 27 = header + category + action + smps mode */
1649 skb
= dev_alloc_skb(34 + hw
->extra_tx_headroom
);
1653 skb_reserve(skb
, hw
->extra_tx_headroom
);
1654 action_frame
= (void *)skb_put(skb
, 34);
1655 memset(action_frame
, 0, 34);
1656 ether_addr_copy(action_frame
->sa
, sa
);
1657 ether_addr_copy(action_frame
->da
, rtlefuse
->dev_addr
);
1658 ether_addr_copy(action_frame
->bssid
, bssid
);
1659 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1660 IEEE80211_STYPE_ACTION
);
1661 action_frame
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1662 action_frame
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1663 params
= (u16
)(1 << 11); /* bit 11 initiator */
1664 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1666 action_frame
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1667 action_frame
->u
.action
.u
.delba
.reason_code
=
1668 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT
);
1673 /*********************************************************
1677 *********************************************************/
1678 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw
*hw
,
1679 struct octet_string vendor_ie
)
1681 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1682 bool matched
= false;
1683 static u8 athcap_1
[] = { 0x00, 0x03, 0x7F };
1684 static u8 athcap_2
[] = { 0x00, 0x13, 0x74 };
1685 static u8 broadcap_1
[] = { 0x00, 0x10, 0x18 };
1686 static u8 broadcap_2
[] = { 0x00, 0x0a, 0xf7 };
1687 static u8 broadcap_3
[] = { 0x00, 0x05, 0xb5 };
1688 static u8 racap
[] = { 0x00, 0x0c, 0x43 };
1689 static u8 ciscocap
[] = { 0x00, 0x40, 0x96 };
1690 static u8 marvcap
[] = { 0x00, 0x50, 0x43 };
1692 if (memcmp(vendor_ie
.octet
, athcap_1
, 3) == 0 ||
1693 memcmp(vendor_ie
.octet
, athcap_2
, 3) == 0) {
1694 rtlpriv
->mac80211
.vendor
= PEER_ATH
;
1696 } else if (memcmp(vendor_ie
.octet
, broadcap_1
, 3) == 0 ||
1697 memcmp(vendor_ie
.octet
, broadcap_2
, 3) == 0 ||
1698 memcmp(vendor_ie
.octet
, broadcap_3
, 3) == 0) {
1699 rtlpriv
->mac80211
.vendor
= PEER_BROAD
;
1701 } else if (memcmp(vendor_ie
.octet
, racap
, 3) == 0) {
1702 rtlpriv
->mac80211
.vendor
= PEER_RAL
;
1704 } else if (memcmp(vendor_ie
.octet
, ciscocap
, 3) == 0) {
1705 rtlpriv
->mac80211
.vendor
= PEER_CISCO
;
1707 } else if (memcmp(vendor_ie
.octet
, marvcap
, 3) == 0) {
1708 rtlpriv
->mac80211
.vendor
= PEER_MARV
;
1715 static bool rtl_find_221_ie(struct ieee80211_hw
*hw
, u8
*data
, unsigned int len
)
1717 struct ieee80211_mgmt
*mgmt
= (void *)data
;
1718 struct octet_string vendor_ie
;
1721 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
1724 if (pos
[0] == 221) {
1725 vendor_ie
.length
= pos
[1];
1726 vendor_ie
.octet
= &pos
[2];
1727 if (rtl_chk_vendor_ouisub(hw
, vendor_ie
))
1731 if (pos
+ 2 + pos
[1] > end
)
1739 void rtl92e_recognize_peer(struct ieee80211_hw
*hw
, u8
*data
, unsigned int len
)
1741 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1742 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1743 struct ieee80211_hdr
*hdr
= (void *)data
;
1744 u32 vendor
= PEER_UNKNOWN
;
1746 static u8 ap3_1
[3] = { 0x00, 0x14, 0xbf };
1747 static u8 ap3_2
[3] = { 0x00, 0x1a, 0x70 };
1748 static u8 ap3_3
[3] = { 0x00, 0x1d, 0x7e };
1749 static u8 ap4_1
[3] = { 0x00, 0x90, 0xcc };
1750 static u8 ap4_2
[3] = { 0x00, 0x0e, 0x2e };
1751 static u8 ap4_3
[3] = { 0x00, 0x18, 0x02 };
1752 static u8 ap4_4
[3] = { 0x00, 0x17, 0x3f };
1753 static u8 ap4_5
[3] = { 0x00, 0x1c, 0xdf };
1754 static u8 ap5_1
[3] = { 0x00, 0x1c, 0xf0 };
1755 static u8 ap5_2
[3] = { 0x00, 0x21, 0x91 };
1756 static u8 ap5_3
[3] = { 0x00, 0x24, 0x01 };
1757 static u8 ap5_4
[3] = { 0x00, 0x15, 0xe9 };
1758 static u8 ap5_5
[3] = { 0x00, 0x17, 0x9A };
1759 static u8 ap5_6
[3] = { 0x00, 0x18, 0xE7 };
1760 static u8 ap6_1
[3] = { 0x00, 0x17, 0x94 };
1761 static u8 ap7_1
[3] = { 0x00, 0x14, 0xa4 };
1763 if (mac
->opmode
!= NL80211_IFTYPE_STATION
)
1766 if (mac
->link_state
== MAC80211_NOLINK
) {
1767 mac
->vendor
= PEER_UNKNOWN
;
1771 if (mac
->cnt_after_linked
> 2)
1774 /* check if this really is a beacon */
1775 if (!ieee80211_is_beacon(hdr
->frame_control
))
1778 /* min. beacon length + FCS_LEN */
1779 if (len
<= 40 + FCS_LEN
)
1782 /* and only beacons from the associated BSSID, please */
1783 if (!ether_addr_equal(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
1786 if (rtl_find_221_ie(hw
, data
, len
))
1787 vendor
= mac
->vendor
;
1789 if ((memcmp(mac
->bssid
, ap5_1
, 3) == 0) ||
1790 (memcmp(mac
->bssid
, ap5_2
, 3) == 0) ||
1791 (memcmp(mac
->bssid
, ap5_3
, 3) == 0) ||
1792 (memcmp(mac
->bssid
, ap5_4
, 3) == 0) ||
1793 (memcmp(mac
->bssid
, ap5_5
, 3) == 0) ||
1794 (memcmp(mac
->bssid
, ap5_6
, 3) == 0) ||
1795 vendor
== PEER_ATH
) {
1797 RT_TRACE(COMP_MAC80211
, DBG_LOUD
, ("=>ath find\n"));
1798 } else if ((memcmp(mac
->bssid
, ap4_4
, 3) == 0) ||
1799 (memcmp(mac
->bssid
, ap4_5
, 3) == 0) ||
1800 (memcmp(mac
->bssid
, ap4_1
, 3) == 0) ||
1801 (memcmp(mac
->bssid
, ap4_2
, 3) == 0) ||
1802 (memcmp(mac
->bssid
, ap4_3
, 3) == 0) ||
1803 vendor
== PEER_RAL
) {
1804 RT_TRACE(COMP_MAC80211
, DBG_LOUD
, ("=>ral findn\n"));
1806 } else if (memcmp(mac
->bssid
, ap6_1
, 3) == 0 ||
1807 vendor
== PEER_CISCO
) {
1808 vendor
= PEER_CISCO
;
1809 RT_TRACE(COMP_MAC80211
, DBG_LOUD
, ("=>cisco find\n"));
1810 } else if ((memcmp(mac
->bssid
, ap3_1
, 3) == 0) ||
1811 (memcmp(mac
->bssid
, ap3_2
, 3) == 0) ||
1812 (memcmp(mac
->bssid
, ap3_3
, 3) == 0) ||
1813 vendor
== PEER_BROAD
) {
1814 RT_TRACE(COMP_MAC80211
, DBG_LOUD
, ("=>broad find\n"));
1815 vendor
= PEER_BROAD
;
1816 } else if (memcmp(mac
->bssid
, ap7_1
, 3) == 0 ||
1817 vendor
== PEER_MARV
) {
1819 RT_TRACE(COMP_MAC80211
, DBG_LOUD
, ("=>marv find\n"));
1822 mac
->vendor
= vendor
;
1825 /*********************************************************
1829 *********************************************************/
1830 struct rtl_global_var global_var
= {};
1832 int rtl_core_module_init(void)
1834 static int here_once
;
1839 if (rtl92e_rate_control_register())
1840 pr_debug("rtl: Unable to register rtl_rc, use default RC !!\n");
1842 /* init some global vars */
1843 INIT_LIST_HEAD(&global_var
.glb_priv_list
);
1844 spin_lock_init(&global_var
.glb_list_lock
);
1848 void rtl_core_module_exit(void)
1851 rtl92e_rate_control_unregister();