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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/module.h>
43 *NOTICE!!!: This file will be very big, we hsould
44 *keep it clear under follwing roles:
46 *This file include follwing part, so, if you add new
47 *functions into this file, please check which part it
48 *should includes. or check if you should add new part
51 *1) mac80211 init functions
52 *2) tx information functions
53 *3) functions called by core.c
54 *4) wq & timer callback functions
55 *5) frame process functions
61 /*********************************************************
63 * mac80211 init functions
65 *********************************************************/
66 static struct ieee80211_channel rtl_channeltable_2g
[] = {
67 {.center_freq
= 2412, .hw_value
= 1,},
68 {.center_freq
= 2417, .hw_value
= 2,},
69 {.center_freq
= 2422, .hw_value
= 3,},
70 {.center_freq
= 2427, .hw_value
= 4,},
71 {.center_freq
= 2432, .hw_value
= 5,},
72 {.center_freq
= 2437, .hw_value
= 6,},
73 {.center_freq
= 2442, .hw_value
= 7,},
74 {.center_freq
= 2447, .hw_value
= 8,},
75 {.center_freq
= 2452, .hw_value
= 9,},
76 {.center_freq
= 2457, .hw_value
= 10,},
77 {.center_freq
= 2462, .hw_value
= 11,},
78 {.center_freq
= 2467, .hw_value
= 12,},
79 {.center_freq
= 2472, .hw_value
= 13,},
80 {.center_freq
= 2484, .hw_value
= 14,},
83 static struct ieee80211_channel rtl_channeltable_5g
[] = {
84 {.center_freq
= 5180, .hw_value
= 36,},
85 {.center_freq
= 5200, .hw_value
= 40,},
86 {.center_freq
= 5220, .hw_value
= 44,},
87 {.center_freq
= 5240, .hw_value
= 48,},
88 {.center_freq
= 5260, .hw_value
= 52,},
89 {.center_freq
= 5280, .hw_value
= 56,},
90 {.center_freq
= 5300, .hw_value
= 60,},
91 {.center_freq
= 5320, .hw_value
= 64,},
92 {.center_freq
= 5500, .hw_value
= 100,},
93 {.center_freq
= 5520, .hw_value
= 104,},
94 {.center_freq
= 5540, .hw_value
= 108,},
95 {.center_freq
= 5560, .hw_value
= 112,},
96 {.center_freq
= 5580, .hw_value
= 116,},
97 {.center_freq
= 5600, .hw_value
= 120,},
98 {.center_freq
= 5620, .hw_value
= 124,},
99 {.center_freq
= 5640, .hw_value
= 128,},
100 {.center_freq
= 5660, .hw_value
= 132,},
101 {.center_freq
= 5680, .hw_value
= 136,},
102 {.center_freq
= 5700, .hw_value
= 140,},
103 {.center_freq
= 5745, .hw_value
= 149,},
104 {.center_freq
= 5765, .hw_value
= 153,},
105 {.center_freq
= 5785, .hw_value
= 157,},
106 {.center_freq
= 5805, .hw_value
= 161,},
107 {.center_freq
= 5825, .hw_value
= 165,},
110 static struct ieee80211_rate rtl_ratetable_2g
[] = {
111 {.bitrate
= 10, .hw_value
= 0x00,},
112 {.bitrate
= 20, .hw_value
= 0x01,},
113 {.bitrate
= 55, .hw_value
= 0x02,},
114 {.bitrate
= 110, .hw_value
= 0x03,},
115 {.bitrate
= 60, .hw_value
= 0x04,},
116 {.bitrate
= 90, .hw_value
= 0x05,},
117 {.bitrate
= 120, .hw_value
= 0x06,},
118 {.bitrate
= 180, .hw_value
= 0x07,},
119 {.bitrate
= 240, .hw_value
= 0x08,},
120 {.bitrate
= 360, .hw_value
= 0x09,},
121 {.bitrate
= 480, .hw_value
= 0x0a,},
122 {.bitrate
= 540, .hw_value
= 0x0b,},
125 static struct ieee80211_rate rtl_ratetable_5g
[] = {
126 {.bitrate
= 60, .hw_value
= 0x04,},
127 {.bitrate
= 90, .hw_value
= 0x05,},
128 {.bitrate
= 120, .hw_value
= 0x06,},
129 {.bitrate
= 180, .hw_value
= 0x07,},
130 {.bitrate
= 240, .hw_value
= 0x08,},
131 {.bitrate
= 360, .hw_value
= 0x09,},
132 {.bitrate
= 480, .hw_value
= 0x0a,},
133 {.bitrate
= 540, .hw_value
= 0x0b,},
136 static const struct ieee80211_supported_band rtl_band_2ghz
= {
137 .band
= IEEE80211_BAND_2GHZ
,
139 .channels
= rtl_channeltable_2g
,
140 .n_channels
= ARRAY_SIZE(rtl_channeltable_2g
),
142 .bitrates
= rtl_ratetable_2g
,
143 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_2g
),
148 static struct ieee80211_supported_band rtl_band_5ghz
= {
149 .band
= IEEE80211_BAND_5GHZ
,
151 .channels
= rtl_channeltable_5g
,
152 .n_channels
= ARRAY_SIZE(rtl_channeltable_5g
),
154 .bitrates
= rtl_ratetable_5g
,
155 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_5g
),
160 static const u8 tid_to_ac
[] = {
161 2, /* IEEE80211_AC_BE */
162 3, /* IEEE80211_AC_BK */
163 3, /* IEEE80211_AC_BK */
164 2, /* IEEE80211_AC_BE */
165 1, /* IEEE80211_AC_VI */
166 1, /* IEEE80211_AC_VI */
167 0, /* IEEE80211_AC_VO */
168 0, /* IEEE80211_AC_VO */
171 u8
rtl_tid_to_ac(struct ieee80211_hw
*hw
, u8 tid
)
173 return tid_to_ac
[tid
];
176 static void _rtl_init_hw_ht_capab(struct ieee80211_hw
*hw
,
177 struct ieee80211_sta_ht_cap
*ht_cap
)
179 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
180 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
182 ht_cap
->ht_supported
= true;
183 ht_cap
->cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
184 IEEE80211_HT_CAP_SGI_40
|
185 IEEE80211_HT_CAP_SGI_20
|
186 IEEE80211_HT_CAP_DSSSCCK40
| IEEE80211_HT_CAP_MAX_AMSDU
;
188 if (rtlpriv
->rtlhal
.disable_amsdu_8k
)
189 ht_cap
->cap
&= ~IEEE80211_HT_CAP_MAX_AMSDU
;
192 *Maximum length of AMPDU that the STA can receive.
193 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
195 ht_cap
->ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
197 /*Minimum MPDU start spacing , */
198 ht_cap
->ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
200 ht_cap
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
203 *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
206 *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7
207 *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15
208 *if rx_ant >=3 rx_mask[2]=0xff;
209 *if BW_40 rx_mask[4]=0x01;
210 *highest supported RX rate
212 if (get_rf_type(rtlphy
) == RF_1T2R
|| get_rf_type(rtlphy
) == RF_2T2R
) {
214 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("1T2R or 2T2R\n"));
216 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
217 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
218 ht_cap
->mcs
.rx_mask
[4] = 0x01;
220 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
221 } else if (get_rf_type(rtlphy
) == RF_1T1R
) {
223 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("1T1R\n"));
225 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
226 ht_cap
->mcs
.rx_mask
[1] = 0x00;
227 ht_cap
->mcs
.rx_mask
[4] = 0x01;
229 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7
);
233 static void _rtl_init_mac80211(struct ieee80211_hw
*hw
)
235 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
236 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
237 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
238 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
239 struct ieee80211_supported_band
*sband
;
242 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&& rtlhal
->bandset
==
245 /* <1> use mac->bands as mem for hw->wiphy->bands */
246 sband
= &(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]);
248 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
249 * to default value(1T1R) */
250 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]), &rtl_band_2ghz
,
251 sizeof(struct ieee80211_supported_band
));
253 /* <3> init ht cap base on ant_num */
254 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
256 /* <4> set mac->sband to wiphy->sband */
257 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = sband
;
260 /* <1> use mac->bands as mem for hw->wiphy->bands */
261 sband
= &(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]);
263 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
264 * to default value(1T1R) */
265 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]), &rtl_band_5ghz
,
266 sizeof(struct ieee80211_supported_band
));
268 /* <3> init ht cap base on ant_num */
269 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
271 /* <4> set mac->sband to wiphy->sband */
272 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = sband
;
274 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
275 /* <1> use mac->bands as mem for hw->wiphy->bands */
276 sband
= &(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]);
278 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
279 * to default value(1T1R) */
280 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]),
282 sizeof(struct ieee80211_supported_band
));
284 /* <3> init ht cap base on ant_num */
285 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
287 /* <4> set mac->sband to wiphy->sband */
288 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = sband
;
289 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
290 /* <1> use mac->bands as mem for hw->wiphy->bands */
291 sband
= &(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]);
293 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
294 * to default value(1T1R) */
295 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]),
297 sizeof(struct ieee80211_supported_band
));
299 /* <3> init ht cap base on ant_num */
300 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
302 /* <4> set mac->sband to wiphy->sband */
303 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = sband
;
305 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
307 rtlhal
->current_bandtype
));
310 /* <5> set hw caps */
311 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
312 IEEE80211_HW_RX_INCLUDES_FCS
|
313 IEEE80211_HW_BEACON_FILTER
|
314 IEEE80211_HW_AMPDU_AGGREGATION
|
315 IEEE80211_HW_CONNECTION_MONITOR
|
316 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
317 IEEE80211_HW_REPORTS_TX_ACK_STATUS
| 0;
319 /* swlps or hwlps has been set in diff chip in init_sw_vars */
320 if (rtlpriv
->psc
.swctrl_lps
)
321 hw
->flags
|= IEEE80211_HW_SUPPORTS_PS
|
322 IEEE80211_HW_PS_NULLFUNC_STACK
|
323 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
326 hw
->wiphy
->interface_modes
=
327 BIT(NL80211_IFTYPE_AP
) |
328 BIT(NL80211_IFTYPE_STATION
) |
329 BIT(NL80211_IFTYPE_ADHOC
);
331 hw
->wiphy
->rts_threshold
= 2347;
334 hw
->extra_tx_headroom
= RTL_TX_HEADER_SIZE
;
336 /* TODO: Correct this value for our hw */
337 /* TODO: define these hard code value */
338 hw
->channel_change_time
= 100;
339 hw
->max_listen_interval
= 10;
340 hw
->max_rate_tries
= 4;
341 /* hw->max_rates = 1; */
342 hw
->sta_data_size
= sizeof(struct rtl_sta_info
);
344 /* <6> mac address */
345 if (is_valid_ether_addr(rtlefuse
->dev_addr
)) {
346 SET_IEEE80211_PERM_ADDR(hw
, rtlefuse
->dev_addr
);
348 u8 rtlmac1
[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
349 get_random_bytes((rtlmac1
+ (ETH_ALEN
- 1)), 1);
350 SET_IEEE80211_PERM_ADDR(hw
, rtlmac1
);
355 static void _rtl_init_deferred_work(struct ieee80211_hw
*hw
)
357 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
360 init_timer(&rtlpriv
->works
.watchdog_timer
);
361 setup_timer(&rtlpriv
->works
.watchdog_timer
,
362 rtl_watch_dog_timer_callback
, (unsigned long)hw
);
365 rtlpriv
->works
.hw
= hw
;
366 rtlpriv
->works
.rtl_wq
= alloc_workqueue(rtlpriv
->cfg
->name
, 0, 0);
367 INIT_DELAYED_WORK(&rtlpriv
->works
.watchdog_wq
,
368 (void *)rtl_watchdog_wq_callback
);
369 INIT_DELAYED_WORK(&rtlpriv
->works
.ips_nic_off_wq
,
370 (void *)rtl_ips_nic_off_wq_callback
);
371 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_work
,
372 (void *)rtl_swlps_wq_callback
);
373 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_rfon_wq
,
374 (void *)rtl_swlps_rfon_wq_callback
);
378 void rtl_deinit_deferred_work(struct ieee80211_hw
*hw
)
380 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
382 del_timer_sync(&rtlpriv
->works
.watchdog_timer
);
384 cancel_delayed_work(&rtlpriv
->works
.watchdog_wq
);
385 cancel_delayed_work(&rtlpriv
->works
.ips_nic_off_wq
);
386 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
387 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
390 void rtl_init_rfkill(struct ieee80211_hw
*hw
)
392 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
398 /*set init state to on */
399 rtlpriv
->rfkill
.rfkill_state
= 1;
400 wiphy_rfkill_set_hw_state(hw
->wiphy
, 0);
402 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
405 pr_info("wireless switch is %s\n",
406 rtlpriv
->rfkill
.rfkill_state
? "on" : "off");
408 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
410 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
411 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
414 wiphy_rfkill_start_polling(hw
->wiphy
);
417 void rtl_deinit_rfkill(struct ieee80211_hw
*hw
)
419 wiphy_rfkill_stop_polling(hw
->wiphy
);
422 int rtl_init_core(struct ieee80211_hw
*hw
)
424 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
425 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
427 /* <1> init mac80211 */
428 _rtl_init_mac80211(hw
);
431 /* <2> rate control register */
432 hw
->rate_control_algorithm
= "rtl_rc";
435 * <3> init CRDA must come after init
436 * mac80211 hw in _rtl_init_mac80211.
438 if (rtl_regd_init(hw
, rtl_reg_notifier
)) {
439 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("REGD init failed\n"));
442 /* CRDA regd hint must after init CRDA */
443 if (regulatory_hint(hw
->wiphy
, rtlpriv
->regd
.alpha2
)) {
444 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
445 ("regulatory_hint fail\n"));
450 mutex_init(&rtlpriv
->locks
.conf_mutex
);
451 spin_lock_init(&rtlpriv
->locks
.ips_lock
);
452 spin_lock_init(&rtlpriv
->locks
.irq_th_lock
);
453 spin_lock_init(&rtlpriv
->locks
.h2c_lock
);
454 spin_lock_init(&rtlpriv
->locks
.rf_ps_lock
);
455 spin_lock_init(&rtlpriv
->locks
.rf_lock
);
456 spin_lock_init(&rtlpriv
->locks
.lps_lock
);
457 spin_lock_init(&rtlpriv
->locks
.waitq_lock
);
458 spin_lock_init(&rtlpriv
->locks
.cck_and_rw_pagea_lock
);
460 rtlmac
->link_state
= MAC80211_NOLINK
;
462 /* <5> init deferred work */
463 _rtl_init_deferred_work(hw
);
468 void rtl_deinit_core(struct ieee80211_hw
*hw
)
472 void rtl_init_rx_config(struct ieee80211_hw
*hw
)
474 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
475 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
477 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*) (&mac
->rx_conf
));
480 /*********************************************************
482 * tx information functions
484 *********************************************************/
485 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw
*hw
,
486 struct rtl_tcb_desc
*tcb_desc
,
487 struct ieee80211_tx_info
*info
)
489 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
490 u8 rate_flag
= info
->control
.rates
[0].flags
;
492 tcb_desc
->use_shortpreamble
= false;
494 /* 1M can only use Long Preamble. 11B spec */
495 if (tcb_desc
->hw_rate
== rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE1M
])
497 else if (rate_flag
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
498 tcb_desc
->use_shortpreamble
= true;
503 static void _rtl_query_shortgi(struct ieee80211_hw
*hw
,
504 struct ieee80211_sta
*sta
,
505 struct rtl_tcb_desc
*tcb_desc
,
506 struct ieee80211_tx_info
*info
)
508 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
509 u8 rate_flag
= info
->control
.rates
[0].flags
;
510 u8 sgi_40
= 0, sgi_20
= 0, bw_40
= 0;
511 tcb_desc
->use_shortgi
= false;
516 sgi_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
;
517 sgi_20
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
;
519 if (!(sta
->ht_cap
.ht_supported
))
522 if (!sgi_40
&& !sgi_20
)
525 if (mac
->opmode
== NL80211_IFTYPE_STATION
)
527 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
528 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
529 bw_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
532 tcb_desc
->use_shortgi
= true;
533 else if ((bw_40
== false) && sgi_20
)
534 tcb_desc
->use_shortgi
= true;
536 if (!(rate_flag
& IEEE80211_TX_RC_SHORT_GI
))
537 tcb_desc
->use_shortgi
= false;
540 static void _rtl_query_protection_mode(struct ieee80211_hw
*hw
,
541 struct rtl_tcb_desc
*tcb_desc
,
542 struct ieee80211_tx_info
*info
)
544 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
545 u8 rate_flag
= info
->control
.rates
[0].flags
;
547 /* Common Settings */
548 tcb_desc
->rts_stbc
= false;
549 tcb_desc
->cts_enable
= false;
550 tcb_desc
->rts_sc
= 0;
551 tcb_desc
->rts_bw
= false;
552 tcb_desc
->rts_use_shortpreamble
= false;
553 tcb_desc
->rts_use_shortgi
= false;
555 if (rate_flag
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
556 /* Use CTS-to-SELF in protection mode. */
557 tcb_desc
->rts_enable
= true;
558 tcb_desc
->cts_enable
= true;
559 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
560 } else if (rate_flag
& IEEE80211_TX_RC_USE_RTS_CTS
) {
561 /* Use RTS-CTS in protection mode. */
562 tcb_desc
->rts_enable
= true;
563 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
567 static void _rtl_txrate_selectmode(struct ieee80211_hw
*hw
,
568 struct ieee80211_sta
*sta
,
569 struct rtl_tcb_desc
*tcb_desc
)
571 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
572 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
573 struct rtl_sta_info
*sta_entry
= NULL
;
577 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
578 ratr_index
= sta_entry
->ratr_index
;
580 if (!tcb_desc
->disable_ratefallback
|| !tcb_desc
->use_driver_rate
) {
581 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
582 tcb_desc
->ratr_index
= 0;
583 } else if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
584 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
) {
586 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE2M
];
587 tcb_desc
->use_driver_rate
= 1;
591 tcb_desc
->ratr_index
= ratr_index
;
592 } else if (mac
->opmode
== NL80211_IFTYPE_AP
) {
593 tcb_desc
->ratr_index
= ratr_index
;
597 if (rtlpriv
->dm
.useramask
) {
598 /* TODO we will differentiate adhoc and station futrue */
599 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
600 tcb_desc
->mac_id
= 0;
602 if (mac
->mode
== WIRELESS_MODE_N_24G
)
603 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NGB
;
604 else if (mac
->mode
== WIRELESS_MODE_N_5G
)
605 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NG
;
606 else if (mac
->mode
& WIRELESS_MODE_G
)
607 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_GB
;
608 else if (mac
->mode
& WIRELESS_MODE_B
)
609 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_B
;
610 else if (mac
->mode
& WIRELESS_MODE_A
)
611 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_G
;
612 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
613 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
616 tcb_desc
->mac_id
= sta
->aid
+ 1;
618 tcb_desc
->mac_id
= 1;
620 tcb_desc
->mac_id
= 0;
627 static void _rtl_query_bandwidth_mode(struct ieee80211_hw
*hw
,
628 struct ieee80211_sta
*sta
,
629 struct rtl_tcb_desc
*tcb_desc
)
631 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
632 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
634 tcb_desc
->packet_bw
= false;
637 if (mac
->opmode
== NL80211_IFTYPE_AP
||
638 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
639 if (!(sta
->ht_cap
.ht_supported
) ||
640 !(sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
642 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
643 if (!mac
->bw_40
|| !(sta
->ht_cap
.ht_supported
))
646 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
)
649 /*use legency rate, shall use 20MHz */
650 if (tcb_desc
->hw_rate
<= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
])
653 tcb_desc
->packet_bw
= true;
656 static u8
_rtl_get_highest_n_rate(struct ieee80211_hw
*hw
)
658 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
659 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
662 if (get_rf_type(rtlphy
) == RF_2T2R
)
663 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
];
665 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS7
];
670 /* mac80211's rate_idx is like this:
672 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
675 * (rx_status->flag & RX_FLAG_HT) = 0,
676 * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11,
679 * (rx_status->flag & RX_FLAG_HT) = 1,
680 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
682 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
684 * (rx_status->flag & RX_FLAG_HT) = 0,
685 * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7,
688 * (rx_status->flag & RX_FLAG_HT) = 1,
689 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
691 int rtlwifi_rate_mapping(struct ieee80211_hw
*hw
,
692 bool isht
, u8 desc_rate
, bool first_ampdu
)
697 if (IEEE80211_BAND_2GHZ
== hw
->conf
.channel
->band
) {
705 case DESC92_RATE5_5M
:
774 case DESC92_RATEMCS0
:
777 case DESC92_RATEMCS1
:
780 case DESC92_RATEMCS2
:
783 case DESC92_RATEMCS3
:
786 case DESC92_RATEMCS4
:
789 case DESC92_RATEMCS5
:
792 case DESC92_RATEMCS6
:
795 case DESC92_RATEMCS7
:
798 case DESC92_RATEMCS8
:
801 case DESC92_RATEMCS9
:
804 case DESC92_RATEMCS10
:
807 case DESC92_RATEMCS11
:
810 case DESC92_RATEMCS12
:
813 case DESC92_RATEMCS13
:
816 case DESC92_RATEMCS14
:
819 case DESC92_RATEMCS15
:
829 EXPORT_SYMBOL(rtlwifi_rate_mapping
);
831 void rtl_get_tcb_desc(struct ieee80211_hw
*hw
,
832 struct ieee80211_tx_info
*info
,
833 struct ieee80211_sta
*sta
,
834 struct sk_buff
*skb
, struct rtl_tcb_desc
*tcb_desc
)
836 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
837 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
838 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
839 struct ieee80211_rate
*txrate
;
840 __le16 fc
= hdr
->frame_control
;
842 txrate
= ieee80211_get_tx_rate(hw
, info
);
843 tcb_desc
->hw_rate
= txrate
->hw_value
;
845 if (ieee80211_is_data(fc
)) {
847 *we set data rate INX 0
848 *in rtl_rc.c if skb is special data or
849 *mgt which need low data rate.
853 *So tcb_desc->hw_rate is just used for
854 *special data and mgt frames
856 if (info
->control
.rates
[0].idx
== 0 ||
857 ieee80211_is_nullfunc(fc
)) {
858 tcb_desc
->use_driver_rate
= true;
859 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
861 tcb_desc
->disable_ratefallback
= 1;
864 *because hw will nerver use hw_rate
865 *when tcb_desc->use_driver_rate = false
866 *so we never set highest N rate here,
867 *and N rate will all be controlled by FW
868 *when tcb_desc->use_driver_rate = false
870 if (sta
&& (sta
->ht_cap
.ht_supported
)) {
871 tcb_desc
->hw_rate
= _rtl_get_highest_n_rate(hw
);
873 if (rtlmac
->mode
== WIRELESS_MODE_B
) {
875 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE11M
];
878 rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
];
883 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)))
884 tcb_desc
->multicast
= 1;
885 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr
)))
886 tcb_desc
->broadcast
= 1;
888 _rtl_txrate_selectmode(hw
, sta
, tcb_desc
);
889 _rtl_query_bandwidth_mode(hw
, sta
, tcb_desc
);
890 _rtl_qurey_shortpreamble_mode(hw
, tcb_desc
, info
);
891 _rtl_query_shortgi(hw
, sta
, tcb_desc
, info
);
892 _rtl_query_protection_mode(hw
, tcb_desc
, info
);
894 tcb_desc
->use_driver_rate
= true;
895 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
896 tcb_desc
->disable_ratefallback
= 1;
897 tcb_desc
->mac_id
= 0;
898 tcb_desc
->packet_bw
= false;
901 EXPORT_SYMBOL(rtl_get_tcb_desc
);
903 bool rtl_action_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
905 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
906 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
907 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
908 __le16 fc
= hdr
->frame_control
;
909 u8
*act
= (u8
*) (((u8
*) skb
->data
+ MAC80211_3ADDR_LEN
));
912 if (!ieee80211_is_action(fc
))
921 if (mac
->act_scanning
)
924 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
925 ("%s ACT_ADDBAREQ From :%pM\n",
926 is_tx
? "Tx" : "Rx", hdr
->addr2
));
929 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
930 ("%s ACT_ADDBARSP From :%pM\n",
931 is_tx
? "Tx" : "Rx", hdr
->addr2
));
934 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
935 ("ACT_ADDBADEL From :%pM\n", hdr
->addr2
));
946 /*should call before software enc*/
947 u8
rtl_is_special_data(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
949 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
950 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
951 __le16 fc
= rtl_get_fc(skb
);
953 u8 mac_hdr_len
= ieee80211_get_hdrlen_from_skb(skb
);
954 const struct iphdr
*ip
;
956 if (!ieee80211_is_data(fc
))
960 ip
= (struct iphdr
*)((u8
*) skb
->data
+ mac_hdr_len
+
961 SNAP_SIZE
+ PROTOC_TYPE_SIZE
);
962 ether_type
= *(u16
*) ((u8
*) skb
->data
+ mac_hdr_len
+ SNAP_SIZE
);
963 /* ether_type = ntohs(ether_type); */
965 if (ETH_P_IP
== ether_type
) {
966 if (IPPROTO_UDP
== ip
->protocol
) {
967 struct udphdr
*udp
= (struct udphdr
*)((u8
*) ip
+
969 if (((((u8
*) udp
)[1] == 68) &&
970 (((u8
*) udp
)[3] == 67)) ||
971 ((((u8
*) udp
)[1] == 67) &&
972 (((u8
*) udp
)[3] == 68))) {
974 * 68 : UDP BOOTP client
975 * 67 : UDP BOOTP server
977 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
),
978 DBG_DMESG
, ("dhcp %s !!\n",
979 (is_tx
) ? "Tx" : "Rx"));
983 ppsc
->last_delaylps_stamp_jiffies
=
990 } else if (ETH_P_ARP
== ether_type
) {
993 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
997 } else if (ETH_P_PAE
== ether_type
) {
998 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
999 ("802.1X %s EAPOL pkt!!\n", (is_tx
) ? "Tx" : "Rx"));
1003 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1007 } else if (ETH_P_IPV6
== ether_type
) {
1015 /*********************************************************
1017 * functions called by core.c
1019 *********************************************************/
1020 int rtl_tx_agg_start(struct ieee80211_hw
*hw
,
1021 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
1023 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1024 struct rtl_tid_data
*tid_data
;
1025 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1026 struct rtl_sta_info
*sta_entry
= NULL
;
1031 if (unlikely(tid
>= MAX_TID_COUNT
))
1034 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1037 tid_data
= &sta_entry
->tids
[tid
];
1039 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1040 ("on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1041 tid_data
->seq_number
));
1043 *ssn
= tid_data
->seq_number
;
1044 tid_data
->agg
.agg_state
= RTL_AGG_START
;
1046 ieee80211_start_tx_ba_cb_irqsafe(mac
->vif
, sta
->addr
, tid
);
1051 int rtl_tx_agg_stop(struct ieee80211_hw
*hw
,
1052 struct ieee80211_sta
*sta
, u16 tid
)
1054 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1055 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1056 struct rtl_sta_info
*sta_entry
= NULL
;
1062 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("ra = NULL\n"));
1066 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1067 ("on ra = %pM tid = %d\n", sta
->addr
, tid
));
1069 if (unlikely(tid
>= MAX_TID_COUNT
))
1072 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1073 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_STOP
;
1075 ieee80211_stop_tx_ba_cb_irqsafe(mac
->vif
, sta
->addr
, tid
);
1080 int rtl_tx_agg_oper(struct ieee80211_hw
*hw
,
1081 struct ieee80211_sta
*sta
, u16 tid
)
1083 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1084 struct rtl_sta_info
*sta_entry
= NULL
;
1090 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("ra = NULL\n"));
1094 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1095 ("on ra = %pM tid = %d\n", sta
->addr
, tid
));
1097 if (unlikely(tid
>= MAX_TID_COUNT
))
1100 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1101 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_OPERATIONAL
;
1106 /*********************************************************
1108 * wq & timer callback functions
1110 *********************************************************/
1111 void rtl_watchdog_wq_callback(void *data
)
1113 struct rtl_works
*rtlworks
= container_of_dwork_rtl(data
,
1116 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1117 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1118 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1119 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1120 bool busytraffic
= false;
1121 bool higher_busytraffic
= false;
1122 bool higher_busyrxtraffic
= false;
1124 u32 rx_cnt_inp4eriod
= 0;
1125 u32 tx_cnt_inp4eriod
= 0;
1126 u32 aver_rx_cnt_inperiod
= 0;
1127 u32 aver_tx_cnt_inperiod
= 0;
1128 u32 aver_tidtx_inperiod
[MAX_TID_COUNT
] = {0};
1129 u32 tidtx_inp4eriod
[MAX_TID_COUNT
] = {0};
1130 bool enter_ps
= false;
1132 if (is_hal_stop(rtlhal
))
1135 /* <1> Determine if action frame is allowed */
1136 if (mac
->link_state
> MAC80211_NOLINK
) {
1137 if (mac
->cnt_after_linked
< 20)
1138 mac
->cnt_after_linked
++;
1140 mac
->cnt_after_linked
= 0;
1144 *<2> to check if traffic busy, if
1145 * busytraffic we don't change channel
1147 if (mac
->link_state
>= MAC80211_LINKED
) {
1149 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1150 for (idx
= 0; idx
<= 2; idx
++) {
1151 rtlpriv
->link_info
.num_rx_in4period
[idx
] =
1152 rtlpriv
->link_info
.num_rx_in4period
[idx
+ 1];
1153 rtlpriv
->link_info
.num_tx_in4period
[idx
] =
1154 rtlpriv
->link_info
.num_tx_in4period
[idx
+ 1];
1156 rtlpriv
->link_info
.num_rx_in4period
[3] =
1157 rtlpriv
->link_info
.num_rx_inperiod
;
1158 rtlpriv
->link_info
.num_tx_in4period
[3] =
1159 rtlpriv
->link_info
.num_tx_inperiod
;
1160 for (idx
= 0; idx
<= 3; idx
++) {
1162 rtlpriv
->link_info
.num_rx_in4period
[idx
];
1164 rtlpriv
->link_info
.num_tx_in4period
[idx
];
1166 aver_rx_cnt_inperiod
= rx_cnt_inp4eriod
/ 4;
1167 aver_tx_cnt_inperiod
= tx_cnt_inp4eriod
/ 4;
1169 /* (2) check traffic busy */
1170 if (aver_rx_cnt_inperiod
> 100 || aver_tx_cnt_inperiod
> 100)
1173 /* Higher Tx/Rx data. */
1174 if (aver_rx_cnt_inperiod
> 4000 ||
1175 aver_tx_cnt_inperiod
> 4000) {
1176 higher_busytraffic
= true;
1178 /* Extremely high Rx data. */
1179 if (aver_rx_cnt_inperiod
> 5000)
1180 higher_busyrxtraffic
= true;
1183 /* check every tid's tx traffic */
1184 for (tid
= 0; tid
<= 7; tid
++) {
1185 for (idx
= 0; idx
<= 2; idx
++)
1186 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
] =
1187 rtlpriv
->link_info
.tidtx_in4period
[tid
]
1189 rtlpriv
->link_info
.tidtx_in4period
[tid
][3] =
1190 rtlpriv
->link_info
.tidtx_inperiod
[tid
];
1192 for (idx
= 0; idx
<= 3; idx
++)
1193 tidtx_inp4eriod
[tid
] +=
1194 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
];
1195 aver_tidtx_inperiod
[tid
] = tidtx_inp4eriod
[tid
] / 4;
1196 if (aver_tidtx_inperiod
[tid
] > 5000)
1197 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1200 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1204 if (((rtlpriv
->link_info
.num_rx_inperiod
+
1205 rtlpriv
->link_info
.num_tx_inperiod
) > 8) ||
1206 (rtlpriv
->link_info
.num_rx_inperiod
> 2))
1211 /* LeisurePS only work in infra mode. */
1218 rtlpriv
->link_info
.num_rx_inperiod
= 0;
1219 rtlpriv
->link_info
.num_tx_inperiod
= 0;
1220 for (tid
= 0; tid
<= 7; tid
++)
1221 rtlpriv
->link_info
.tidtx_inperiod
[tid
] = 0;
1223 rtlpriv
->link_info
.busytraffic
= busytraffic
;
1224 rtlpriv
->link_info
.higher_busytraffic
= higher_busytraffic
;
1225 rtlpriv
->link_info
.higher_busyrxtraffic
= higher_busyrxtraffic
;
1228 rtlpriv
->cfg
->ops
->dm_watchdog(hw
);
1231 void rtl_watch_dog_timer_callback(unsigned long data
)
1233 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
1234 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1236 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
1237 &rtlpriv
->works
.watchdog_wq
, 0);
1239 mod_timer(&rtlpriv
->works
.watchdog_timer
,
1240 jiffies
+ MSECS(RTL_WATCH_DOG_TIME
));
1243 /*********************************************************
1245 * frame process functions
1247 *********************************************************/
1248 u8
*rtl_find_ie(u8
*data
, unsigned int len
, u8 ie
)
1250 struct ieee80211_mgmt
*mgmt
= (void *)data
;
1253 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
1256 if (pos
+ 2 + pos
[1] > end
)
1267 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1268 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1269 static struct sk_buff
*rtl_make_smps_action(struct ieee80211_hw
*hw
,
1270 enum ieee80211_smps_mode smps
, u8
*da
, u8
*bssid
)
1272 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1273 struct sk_buff
*skb
;
1274 struct ieee80211_mgmt
*action_frame
;
1276 /* 27 = header + category + action + smps mode */
1277 skb
= dev_alloc_skb(27 + hw
->extra_tx_headroom
);
1281 skb_reserve(skb
, hw
->extra_tx_headroom
);
1282 action_frame
= (void *)skb_put(skb
, 27);
1283 memset(action_frame
, 0, 27);
1284 memcpy(action_frame
->da
, da
, ETH_ALEN
);
1285 memcpy(action_frame
->sa
, rtlefuse
->dev_addr
, ETH_ALEN
);
1286 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
1287 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1288 IEEE80211_STYPE_ACTION
);
1289 action_frame
->u
.action
.category
= WLAN_CATEGORY_HT
;
1290 action_frame
->u
.action
.u
.ht_smps
.action
= WLAN_HT_ACTION_SMPS
;
1292 case IEEE80211_SMPS_AUTOMATIC
:/* 0 */
1293 case IEEE80211_SMPS_NUM_MODES
:/* 4 */
1295 case IEEE80211_SMPS_OFF
:/* 1 */ /*MIMO_PS_NOLIMIT*/
1296 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1297 WLAN_HT_SMPS_CONTROL_DISABLED
;/* 0 */
1299 case IEEE80211_SMPS_STATIC
:/* 2 */ /*MIMO_PS_STATIC*/
1300 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1301 WLAN_HT_SMPS_CONTROL_STATIC
;/* 1 */
1303 case IEEE80211_SMPS_DYNAMIC
:/* 3 */ /*MIMO_PS_DYNAMIC*/
1304 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1305 WLAN_HT_SMPS_CONTROL_DYNAMIC
;/* 3 */
1312 int rtl_send_smps_action(struct ieee80211_hw
*hw
,
1313 struct ieee80211_sta
*sta
, u8
*da
, u8
*bssid
,
1314 enum ieee80211_smps_mode smps
)
1316 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1317 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1318 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1319 struct sk_buff
*skb
= rtl_make_smps_action(hw
, smps
, da
, bssid
);
1320 struct rtl_tcb_desc tcb_desc
;
1321 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1323 if (rtlpriv
->mac80211
.act_scanning
)
1329 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
1332 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1335 /* this is a type = mgmt * stype = action frame */
1337 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1338 struct rtl_sta_info
*sta_entry
=
1339 (struct rtl_sta_info
*) sta
->drv_priv
;
1340 sta_entry
->mimo_ps
= smps
;
1341 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
1343 info
->control
.rates
[0].idx
= 0;
1344 info
->control
.sta
= sta
;
1345 info
->band
= hw
->conf
.channel
->band
;
1346 rtlpriv
->intf_ops
->adapter_tx(hw
, skb
, &tcb_desc
);
1352 /*********************************************************
1356 *********************************************************/
1357 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw
*hw
,
1358 struct octet_string vendor_ie
)
1360 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1361 bool matched
= false;
1362 static u8 athcap_1
[] = { 0x00, 0x03, 0x7F };
1363 static u8 athcap_2
[] = { 0x00, 0x13, 0x74 };
1364 static u8 broadcap_1
[] = { 0x00, 0x10, 0x18 };
1365 static u8 broadcap_2
[] = { 0x00, 0x0a, 0xf7 };
1366 static u8 broadcap_3
[] = { 0x00, 0x05, 0xb5 };
1367 static u8 racap
[] = { 0x00, 0x0c, 0x43 };
1368 static u8 ciscocap
[] = { 0x00, 0x40, 0x96 };
1369 static u8 marvcap
[] = { 0x00, 0x50, 0x43 };
1371 if (memcmp(vendor_ie
.octet
, athcap_1
, 3) == 0 ||
1372 memcmp(vendor_ie
.octet
, athcap_2
, 3) == 0) {
1373 rtlpriv
->mac80211
.vendor
= PEER_ATH
;
1375 } else if (memcmp(vendor_ie
.octet
, broadcap_1
, 3) == 0 ||
1376 memcmp(vendor_ie
.octet
, broadcap_2
, 3) == 0 ||
1377 memcmp(vendor_ie
.octet
, broadcap_3
, 3) == 0) {
1378 rtlpriv
->mac80211
.vendor
= PEER_BROAD
;
1380 } else if (memcmp(vendor_ie
.octet
, racap
, 3) == 0) {
1381 rtlpriv
->mac80211
.vendor
= PEER_RAL
;
1383 } else if (memcmp(vendor_ie
.octet
, ciscocap
, 3) == 0) {
1384 rtlpriv
->mac80211
.vendor
= PEER_CISCO
;
1386 } else if (memcmp(vendor_ie
.octet
, marvcap
, 3) == 0) {
1387 rtlpriv
->mac80211
.vendor
= PEER_MARV
;
1394 static bool rtl_find_221_ie(struct ieee80211_hw
*hw
, u8
*data
,
1397 struct ieee80211_mgmt
*mgmt
= (void *)data
;
1398 struct octet_string vendor_ie
;
1401 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
1404 if (pos
[0] == 221) {
1405 vendor_ie
.length
= pos
[1];
1406 vendor_ie
.octet
= &pos
[2];
1407 if (rtl_chk_vendor_ouisub(hw
, vendor_ie
))
1411 if (pos
+ 2 + pos
[1] > end
)
1419 void rtl_recognize_peer(struct ieee80211_hw
*hw
, u8
*data
, unsigned int len
)
1421 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1422 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1423 struct ieee80211_hdr
*hdr
= (void *)data
;
1424 u32 vendor
= PEER_UNKNOWN
;
1426 static u8 ap3_1
[3] = { 0x00, 0x14, 0xbf };
1427 static u8 ap3_2
[3] = { 0x00, 0x1a, 0x70 };
1428 static u8 ap3_3
[3] = { 0x00, 0x1d, 0x7e };
1429 static u8 ap4_1
[3] = { 0x00, 0x90, 0xcc };
1430 static u8 ap4_2
[3] = { 0x00, 0x0e, 0x2e };
1431 static u8 ap4_3
[3] = { 0x00, 0x18, 0x02 };
1432 static u8 ap4_4
[3] = { 0x00, 0x17, 0x3f };
1433 static u8 ap4_5
[3] = { 0x00, 0x1c, 0xdf };
1434 static u8 ap5_1
[3] = { 0x00, 0x1c, 0xf0 };
1435 static u8 ap5_2
[3] = { 0x00, 0x21, 0x91 };
1436 static u8 ap5_3
[3] = { 0x00, 0x24, 0x01 };
1437 static u8 ap5_4
[3] = { 0x00, 0x15, 0xe9 };
1438 static u8 ap5_5
[3] = { 0x00, 0x17, 0x9A };
1439 static u8 ap5_6
[3] = { 0x00, 0x18, 0xE7 };
1440 static u8 ap6_1
[3] = { 0x00, 0x17, 0x94 };
1441 static u8 ap7_1
[3] = { 0x00, 0x14, 0xa4 };
1443 if (mac
->opmode
!= NL80211_IFTYPE_STATION
)
1446 if (mac
->link_state
== MAC80211_NOLINK
) {
1447 mac
->vendor
= PEER_UNKNOWN
;
1451 if (mac
->cnt_after_linked
> 2)
1454 /* check if this really is a beacon */
1455 if (!ieee80211_is_beacon(hdr
->frame_control
))
1458 /* min. beacon length + FCS_LEN */
1459 if (len
<= 40 + FCS_LEN
)
1462 /* and only beacons from the associated BSSID, please */
1463 if (compare_ether_addr(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
1466 if (rtl_find_221_ie(hw
, data
, len
))
1467 vendor
= mac
->vendor
;
1469 if ((memcmp(mac
->bssid
, ap5_1
, 3) == 0) ||
1470 (memcmp(mac
->bssid
, ap5_2
, 3) == 0) ||
1471 (memcmp(mac
->bssid
, ap5_3
, 3) == 0) ||
1472 (memcmp(mac
->bssid
, ap5_4
, 3) == 0) ||
1473 (memcmp(mac
->bssid
, ap5_5
, 3) == 0) ||
1474 (memcmp(mac
->bssid
, ap5_6
, 3) == 0) ||
1475 vendor
== PEER_ATH
) {
1477 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>ath find\n"));
1478 } else if ((memcmp(mac
->bssid
, ap4_4
, 3) == 0) ||
1479 (memcmp(mac
->bssid
, ap4_5
, 3) == 0) ||
1480 (memcmp(mac
->bssid
, ap4_1
, 3) == 0) ||
1481 (memcmp(mac
->bssid
, ap4_2
, 3) == 0) ||
1482 (memcmp(mac
->bssid
, ap4_3
, 3) == 0) ||
1483 vendor
== PEER_RAL
) {
1484 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>ral findn\n"));
1486 } else if (memcmp(mac
->bssid
, ap6_1
, 3) == 0 ||
1487 vendor
== PEER_CISCO
) {
1488 vendor
= PEER_CISCO
;
1489 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>cisco find\n"));
1490 } else if ((memcmp(mac
->bssid
, ap3_1
, 3) == 0) ||
1491 (memcmp(mac
->bssid
, ap3_2
, 3) == 0) ||
1492 (memcmp(mac
->bssid
, ap3_3
, 3) == 0) ||
1493 vendor
== PEER_BROAD
) {
1494 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>broad find\n"));
1495 vendor
= PEER_BROAD
;
1496 } else if (memcmp(mac
->bssid
, ap7_1
, 3) == 0 ||
1497 vendor
== PEER_MARV
) {
1499 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>marv find\n"));
1502 mac
->vendor
= vendor
;
1505 /*********************************************************
1509 *********************************************************/
1510 static ssize_t
rtl_show_debug_level(struct device
*d
,
1511 struct device_attribute
*attr
, char *buf
)
1513 struct ieee80211_hw
*hw
= dev_get_drvdata(d
);
1514 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1516 return sprintf(buf
, "0x%08X\n", rtlpriv
->dbg
.global_debuglevel
);
1519 static ssize_t
rtl_store_debug_level(struct device
*d
,
1520 struct device_attribute
*attr
,
1521 const char *buf
, size_t count
)
1523 struct ieee80211_hw
*hw
= dev_get_drvdata(d
);
1524 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1528 ret
= strict_strtoul(buf
, 0, &val
);
1530 printk(KERN_DEBUG
"%s is not in hex or decimal form.\n", buf
);
1532 rtlpriv
->dbg
.global_debuglevel
= val
;
1533 printk(KERN_DEBUG
"debuglevel:%x\n",
1534 rtlpriv
->dbg
.global_debuglevel
);
1537 return strnlen(buf
, count
);
1540 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1541 rtl_show_debug_level
, rtl_store_debug_level
);
1543 static struct attribute
*rtl_sysfs_entries
[] = {
1545 &dev_attr_debug_level
.attr
,
1551 * "name" is folder name witch will be
1552 * put in device directory like :
1553 * sys/devices/pci0000:00/0000:00:1c.4/
1554 * 0000:06:00.0/rtl_sysfs
1556 struct attribute_group rtl_attribute_group
= {
1558 .attrs
= rtl_sysfs_entries
,
1561 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
1562 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
1563 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
1564 MODULE_LICENSE("GPL");
1565 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
1567 static int __init
rtl_core_module_init(void)
1569 if (rtl_rate_control_register())
1570 pr_err("Unable to register rtl_rc, use default RC !!\n");
1575 static void __exit
rtl_core_module_exit(void)
1578 rtl_rate_control_unregister();
1581 module_init(rtl_core_module_init
);
1582 module_exit(rtl_core_module_exit
);