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 *****************************************************************************/
40 *NOTICE!!!: This file will be very big, we hsould
41 *keep it clear under follwing roles:
43 *This file include follwing part, so, if you add new
44 *functions into this file, please check which part it
45 *should includes. or check if you should add new part
48 *1) mac80211 init functions
49 *2) tx information functions
50 *3) functions called by core.c
51 *4) wq & timer callback functions
52 *5) frame process functions
58 /*********************************************************
60 * mac80211 init functions
62 *********************************************************/
63 static struct ieee80211_channel rtl_channeltable_2g[] = {
64 {.center_freq = 2412, .hw_value = 1,},
65 {.center_freq = 2417, .hw_value = 2,},
66 {.center_freq = 2422, .hw_value = 3,},
67 {.center_freq = 2427, .hw_value = 4,},
68 {.center_freq = 2432, .hw_value = 5,},
69 {.center_freq = 2437, .hw_value = 6,},
70 {.center_freq = 2442, .hw_value = 7,},
71 {.center_freq = 2447, .hw_value = 8,},
72 {.center_freq = 2452, .hw_value = 9,},
73 {.center_freq = 2457, .hw_value = 10,},
74 {.center_freq = 2462, .hw_value = 11,},
75 {.center_freq = 2467, .hw_value = 12,},
76 {.center_freq = 2472, .hw_value = 13,},
77 {.center_freq = 2484, .hw_value = 14,},
80 static struct ieee80211_channel rtl_channeltable_5g[] = {
81 {.center_freq = 5180, .hw_value = 36,},
82 {.center_freq = 5200, .hw_value = 40,},
83 {.center_freq = 5220, .hw_value = 44,},
84 {.center_freq = 5240, .hw_value = 48,},
85 {.center_freq = 5260, .hw_value = 52,},
86 {.center_freq = 5280, .hw_value = 56,},
87 {.center_freq = 5300, .hw_value = 60,},
88 {.center_freq = 5320, .hw_value = 64,},
89 {.center_freq = 5500, .hw_value = 100,},
90 {.center_freq = 5520, .hw_value = 104,},
91 {.center_freq = 5540, .hw_value = 108,},
92 {.center_freq = 5560, .hw_value = 112,},
93 {.center_freq = 5580, .hw_value = 116,},
94 {.center_freq = 5600, .hw_value = 120,},
95 {.center_freq = 5620, .hw_value = 124,},
96 {.center_freq = 5640, .hw_value = 128,},
97 {.center_freq = 5660, .hw_value = 132,},
98 {.center_freq = 5680, .hw_value = 136,},
99 {.center_freq = 5700, .hw_value = 140,},
100 {.center_freq = 5745, .hw_value = 149,},
101 {.center_freq = 5765, .hw_value = 153,},
102 {.center_freq = 5785, .hw_value = 157,},
103 {.center_freq = 5805, .hw_value = 161,},
104 {.center_freq = 5825, .hw_value = 165,},
107 static struct ieee80211_rate rtl_ratetable_2g[] = {
108 {.bitrate = 10, .hw_value = 0x00,},
109 {.bitrate = 20, .hw_value = 0x01,},
110 {.bitrate = 55, .hw_value = 0x02,},
111 {.bitrate = 110, .hw_value = 0x03,},
112 {.bitrate = 60, .hw_value = 0x04,},
113 {.bitrate = 90, .hw_value = 0x05,},
114 {.bitrate = 120, .hw_value = 0x06,},
115 {.bitrate = 180, .hw_value = 0x07,},
116 {.bitrate = 240, .hw_value = 0x08,},
117 {.bitrate = 360, .hw_value = 0x09,},
118 {.bitrate = 480, .hw_value = 0x0a,},
119 {.bitrate = 540, .hw_value = 0x0b,},
122 static struct ieee80211_rate rtl_ratetable_5g[] = {
123 {.bitrate = 60, .hw_value = 0x04,},
124 {.bitrate = 90, .hw_value = 0x05,},
125 {.bitrate = 120, .hw_value = 0x06,},
126 {.bitrate = 180, .hw_value = 0x07,},
127 {.bitrate = 240, .hw_value = 0x08,},
128 {.bitrate = 360, .hw_value = 0x09,},
129 {.bitrate = 480, .hw_value = 0x0a,},
130 {.bitrate = 540, .hw_value = 0x0b,},
133 static const struct ieee80211_supported_band rtl_band_2ghz = {
134 .band = IEEE80211_BAND_2GHZ,
136 .channels = rtl_channeltable_2g,
137 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
139 .bitrates = rtl_ratetable_2g,
140 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
145 static struct ieee80211_supported_band rtl_band_5ghz = {
146 .band = IEEE80211_BAND_5GHZ,
148 .channels = rtl_channeltable_5g,
149 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
151 .bitrates = rtl_ratetable_5g,
152 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
157 static const u8 tid_to_ac[] = {
158 2, /* IEEE80211_AC_BE */
159 3, /* IEEE80211_AC_BK */
160 3, /* IEEE80211_AC_BK */
161 2, /* IEEE80211_AC_BE */
162 1, /* IEEE80211_AC_VI */
163 1, /* IEEE80211_AC_VI */
164 0, /* IEEE80211_AC_VO */
165 0, /* IEEE80211_AC_VO */
168 u8 rtl_tid_to_ac(struct ieee80211_hw *hw, u8 tid)
170 return tid_to_ac[tid];
173 static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
174 struct ieee80211_sta_ht_cap *ht_cap)
176 struct rtl_priv *rtlpriv = rtl_priv(hw);
177 struct rtl_phy *rtlphy = &(rtlpriv->phy);
179 ht_cap->ht_supported = true;
180 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
181 IEEE80211_HT_CAP_SGI_40 |
182 IEEE80211_HT_CAP_SGI_20 |
183 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
185 if (rtlpriv->rtlhal.disable_amsdu_8k)
186 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
189 *Maximum length of AMPDU that the STA can receive.
190 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
192 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
194 /*Minimum MPDU start spacing , */
195 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
197 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
200 *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
203 *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7
204 *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15
205 *if rx_ant >=3 rx_mask[2]=0xff;
206 *if BW_40 rx_mask[4]=0x01;
207 *highest supported RX rate
209 if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_2T2R) {
211 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("1T2R or 2T2R\n"));
213 ht_cap->mcs.rx_mask[0] = 0xFF;
214 ht_cap->mcs.rx_mask[1] = 0xFF;
215 ht_cap->mcs.rx_mask[4] = 0x01;
217 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
218 } else if (get_rf_type(rtlphy) == RF_1T1R) {
220 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("1T1R\n"));
222 ht_cap->mcs.rx_mask[0] = 0xFF;
223 ht_cap->mcs.rx_mask[1] = 0x00;
224 ht_cap->mcs.rx_mask[4] = 0x01;
226 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
230 static void _rtl_init_mac80211(struct ieee80211_hw *hw)
232 struct rtl_priv *rtlpriv = rtl_priv(hw);
233 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
234 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
235 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
236 struct ieee80211_supported_band *sband;
239 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset ==
242 /* <1> use mac->bands as mem for hw->wiphy->bands */
243 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
245 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
246 * to default value(1T1R) */
247 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
248 sizeof(struct ieee80211_supported_band));
250 /* <3> init ht cap base on ant_num */
251 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
253 /* <4> set mac->sband to wiphy->sband */
254 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
257 /* <1> use mac->bands as mem for hw->wiphy->bands */
258 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
260 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
261 * to default value(1T1R) */
262 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
263 sizeof(struct ieee80211_supported_band));
265 /* <3> init ht cap base on ant_num */
266 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
268 /* <4> set mac->sband to wiphy->sband */
269 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
271 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
272 /* <1> use mac->bands as mem for hw->wiphy->bands */
273 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
275 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
276 * to default value(1T1R) */
277 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
279 sizeof(struct ieee80211_supported_band));
281 /* <3> init ht cap base on ant_num */
282 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
284 /* <4> set mac->sband to wiphy->sband */
285 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
286 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
287 /* <1> use mac->bands as mem for hw->wiphy->bands */
288 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
290 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
291 * to default value(1T1R) */
292 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
294 sizeof(struct ieee80211_supported_band));
296 /* <3> init ht cap base on ant_num */
297 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
299 /* <4> set mac->sband to wiphy->sband */
300 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
302 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
304 rtlhal->current_bandtype));
307 /* <5> set hw caps */
308 hw->flags = IEEE80211_HW_SIGNAL_DBM |
309 IEEE80211_HW_RX_INCLUDES_FCS |
310 IEEE80211_HW_BEACON_FILTER |
311 IEEE80211_HW_AMPDU_AGGREGATION |
312 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
314 /* swlps or hwlps has been set in diff chip in init_sw_vars */
315 if (rtlpriv->psc.swctrl_lps)
316 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
317 IEEE80211_HW_PS_NULLFUNC_STACK |
318 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
321 hw->wiphy->interface_modes =
322 BIT(NL80211_IFTYPE_AP) |
323 BIT(NL80211_IFTYPE_STATION) |
324 BIT(NL80211_IFTYPE_ADHOC);
326 hw->wiphy->rts_threshold = 2347;
329 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
331 /* TODO: Correct this value for our hw */
332 /* TODO: define these hard code value */
333 hw->channel_change_time = 100;
334 hw->max_listen_interval = 10;
335 hw->max_rate_tries = 4;
336 /* hw->max_rates = 1; */
337 hw->sta_data_size = sizeof(struct rtl_sta_info);
339 /* <6> mac address */
340 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
341 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
343 u8 rtlmac[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
344 get_random_bytes((rtlmac + (ETH_ALEN - 1)), 1);
345 SET_IEEE80211_PERM_ADDR(hw, rtlmac);
350 static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
352 struct rtl_priv *rtlpriv = rtl_priv(hw);
355 init_timer(&rtlpriv->works.watchdog_timer);
356 setup_timer(&rtlpriv->works.watchdog_timer,
357 rtl_watch_dog_timer_callback, (unsigned long)hw);
360 rtlpriv->works.hw = hw;
361 rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0);
362 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
363 (void *)rtl_watchdog_wq_callback);
364 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
365 (void *)rtl_ips_nic_off_wq_callback);
366 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
367 (void *)rtl_swlps_wq_callback);
368 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
369 (void *)rtl_swlps_rfon_wq_callback);
373 void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
375 struct rtl_priv *rtlpriv = rtl_priv(hw);
377 del_timer_sync(&rtlpriv->works.watchdog_timer);
379 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
380 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
381 cancel_delayed_work(&rtlpriv->works.ps_work);
382 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
385 void rtl_init_rfkill(struct ieee80211_hw *hw)
387 struct rtl_priv *rtlpriv = rtl_priv(hw);
393 /*set init state to on */
394 rtlpriv->rfkill.rfkill_state = 1;
395 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
397 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
400 printk(KERN_INFO "rtlwifi: wireless switch is %s\n",
401 rtlpriv->rfkill.rfkill_state ? "on" : "off");
403 rtlpriv->rfkill.rfkill_state = radio_state;
405 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
406 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
409 wiphy_rfkill_start_polling(hw->wiphy);
412 void rtl_deinit_rfkill(struct ieee80211_hw *hw)
414 wiphy_rfkill_stop_polling(hw->wiphy);
417 int rtl_init_core(struct ieee80211_hw *hw)
419 struct rtl_priv *rtlpriv = rtl_priv(hw);
420 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
422 /* <1> init mac80211 */
423 _rtl_init_mac80211(hw);
426 /* <2> rate control register */
427 hw->rate_control_algorithm = "rtl_rc";
430 * <3> init CRDA must come after init
431 * mac80211 hw in _rtl_init_mac80211.
433 if (rtl_regd_init(hw, rtl_reg_notifier)) {
434 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("REGD init failed\n"));
437 /* CRDA regd hint must after init CRDA */
438 if (regulatory_hint(hw->wiphy, rtlpriv->regd.alpha2)) {
439 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
440 ("regulatory_hint fail\n"));
445 mutex_init(&rtlpriv->locks.conf_mutex);
446 spin_lock_init(&rtlpriv->locks.ips_lock);
447 spin_lock_init(&rtlpriv->locks.irq_th_lock);
448 spin_lock_init(&rtlpriv->locks.h2c_lock);
449 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
450 spin_lock_init(&rtlpriv->locks.rf_lock);
451 spin_lock_init(&rtlpriv->locks.lps_lock);
452 spin_lock_init(&rtlpriv->locks.waitq_lock);
453 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
455 rtlmac->link_state = MAC80211_NOLINK;
457 /* <5> init deferred work */
458 _rtl_init_deferred_work(hw);
463 void rtl_deinit_core(struct ieee80211_hw *hw)
467 void rtl_init_rx_config(struct ieee80211_hw *hw)
469 struct rtl_priv *rtlpriv = rtl_priv(hw);
470 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
472 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
475 /*********************************************************
477 * tx information functions
479 *********************************************************/
480 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
481 struct rtl_tcb_desc *tcb_desc,
482 struct ieee80211_tx_info *info)
484 struct rtl_priv *rtlpriv = rtl_priv(hw);
485 u8 rate_flag = info->control.rates[0].flags;
487 tcb_desc->use_shortpreamble = false;
489 /* 1M can only use Long Preamble. 11B spec */
490 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
492 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
493 tcb_desc->use_shortpreamble = true;
498 static void _rtl_query_shortgi(struct ieee80211_hw *hw,
499 struct ieee80211_sta *sta,
500 struct rtl_tcb_desc *tcb_desc,
501 struct ieee80211_tx_info *info)
503 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
504 u8 rate_flag = info->control.rates[0].flags;
505 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
506 tcb_desc->use_shortgi = false;
511 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
512 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
514 if (!(sta->ht_cap.ht_supported))
517 if (!sgi_40 && !sgi_20)
520 if (mac->opmode == NL80211_IFTYPE_STATION)
522 else if (mac->opmode == NL80211_IFTYPE_AP ||
523 mac->opmode == NL80211_IFTYPE_ADHOC)
524 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
526 if ((bw_40 == true) && sgi_40)
527 tcb_desc->use_shortgi = true;
528 else if ((bw_40 == false) && sgi_20)
529 tcb_desc->use_shortgi = true;
531 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
532 tcb_desc->use_shortgi = false;
535 static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
536 struct rtl_tcb_desc *tcb_desc,
537 struct ieee80211_tx_info *info)
539 struct rtl_priv *rtlpriv = rtl_priv(hw);
540 u8 rate_flag = info->control.rates[0].flags;
542 /* Common Settings */
543 tcb_desc->rts_stbc = false;
544 tcb_desc->cts_enable = false;
545 tcb_desc->rts_sc = 0;
546 tcb_desc->rts_bw = false;
547 tcb_desc->rts_use_shortpreamble = false;
548 tcb_desc->rts_use_shortgi = false;
550 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
551 /* Use CTS-to-SELF in protection mode. */
552 tcb_desc->rts_enable = true;
553 tcb_desc->cts_enable = true;
554 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
555 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
556 /* Use RTS-CTS in protection mode. */
557 tcb_desc->rts_enable = true;
558 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
562 static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
563 struct ieee80211_sta *sta,
564 struct rtl_tcb_desc *tcb_desc)
566 struct rtl_priv *rtlpriv = rtl_priv(hw);
567 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
568 struct rtl_sta_info *sta_entry = NULL;
572 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
573 ratr_index = sta_entry->ratr_index;
575 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
576 if (mac->opmode == NL80211_IFTYPE_STATION) {
577 tcb_desc->ratr_index = 0;
578 } else if (mac->opmode == NL80211_IFTYPE_ADHOC) {
579 if (tcb_desc->multicast || tcb_desc->broadcast) {
581 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
582 tcb_desc->use_driver_rate = 1;
586 tcb_desc->ratr_index = ratr_index;
587 } else if (mac->opmode == NL80211_IFTYPE_AP) {
588 tcb_desc->ratr_index = ratr_index;
592 if (rtlpriv->dm.useramask) {
593 /* TODO we will differentiate adhoc and station futrue */
594 if (mac->opmode == NL80211_IFTYPE_STATION) {
595 tcb_desc->mac_id = 0;
597 if (mac->mode == WIRELESS_MODE_N_24G)
598 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
599 else if (mac->mode == WIRELESS_MODE_N_5G)
600 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
601 else if (mac->mode & WIRELESS_MODE_G)
602 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
603 else if (mac->mode & WIRELESS_MODE_B)
604 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
605 else if (mac->mode & WIRELESS_MODE_A)
606 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
607 } else if (mac->opmode == NL80211_IFTYPE_AP ||
608 mac->opmode == NL80211_IFTYPE_ADHOC) {
611 tcb_desc->mac_id = sta->aid + 1;
613 tcb_desc->mac_id = 1;
615 tcb_desc->mac_id = 0;
622 static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
623 struct ieee80211_sta *sta,
624 struct rtl_tcb_desc *tcb_desc)
626 struct rtl_priv *rtlpriv = rtl_priv(hw);
627 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
629 tcb_desc->packet_bw = false;
632 if (mac->opmode == NL80211_IFTYPE_AP ||
633 mac->opmode == NL80211_IFTYPE_ADHOC) {
634 if (!(sta->ht_cap.ht_supported) ||
635 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
637 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
638 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
641 if (tcb_desc->multicast || tcb_desc->broadcast)
644 /*use legency rate, shall use 20MHz */
645 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
648 tcb_desc->packet_bw = true;
651 static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw)
653 struct rtl_priv *rtlpriv = rtl_priv(hw);
654 struct rtl_phy *rtlphy = &(rtlpriv->phy);
657 if (get_rf_type(rtlphy) == RF_2T2R)
658 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
660 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
665 void rtl_get_tcb_desc(struct ieee80211_hw *hw,
666 struct ieee80211_tx_info *info,
667 struct ieee80211_sta *sta,
668 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
670 struct rtl_priv *rtlpriv = rtl_priv(hw);
671 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
672 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
673 struct ieee80211_rate *txrate;
674 __le16 fc = hdr->frame_control;
676 txrate = ieee80211_get_tx_rate(hw, info);
677 tcb_desc->hw_rate = txrate->hw_value;
679 if (ieee80211_is_data(fc)) {
681 *we set data rate INX 0
682 *in rtl_rc.c if skb is special data or
683 *mgt which need low data rate.
687 *So tcb_desc->hw_rate is just used for
688 *special data and mgt frames
690 if (info->control.rates[0].idx == 0 &&
691 ieee80211_is_nullfunc(fc)) {
692 tcb_desc->use_driver_rate = true;
693 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
695 tcb_desc->disable_ratefallback = 1;
698 *because hw will nerver use hw_rate
699 *when tcb_desc->use_driver_rate = false
700 *so we never set highest N rate here,
701 *and N rate will all be controlled by FW
702 *when tcb_desc->use_driver_rate = false
704 if (sta && (sta->ht_cap.ht_supported)) {
705 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw);
707 if (rtlmac->mode == WIRELESS_MODE_B) {
709 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
712 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
717 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
718 tcb_desc->multicast = 1;
719 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
720 tcb_desc->broadcast = 1;
722 _rtl_txrate_selectmode(hw, sta, tcb_desc);
723 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
724 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
725 _rtl_query_shortgi(hw, sta, tcb_desc, info);
726 _rtl_query_protection_mode(hw, tcb_desc, info);
728 tcb_desc->use_driver_rate = true;
729 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
730 tcb_desc->disable_ratefallback = 1;
731 tcb_desc->mac_id = 0;
732 tcb_desc->packet_bw = false;
735 EXPORT_SYMBOL(rtl_get_tcb_desc);
737 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
739 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
740 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
741 struct rtl_priv *rtlpriv = rtl_priv(hw);
742 __le16 fc = hdr->frame_control;
743 u8 *act = (u8 *) (((u8 *) skb->data + MAC80211_3ADDR_LEN));
746 if (!ieee80211_is_action(fc))
755 if (mac->act_scanning)
758 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
759 ("%s ACT_ADDBAREQ From :" MAC_FMT "\n",
760 is_tx ? "Tx" : "Rx", MAC_ARG(hdr->addr2)));
763 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
764 ("%s ACT_ADDBARSP From :" MAC_FMT "\n",
765 is_tx ? "Tx" : "Rx", MAC_ARG(hdr->addr2)));
768 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
769 ("ACT_ADDBADEL From :" MAC_FMT "\n",
770 MAC_ARG(hdr->addr2)));
781 /*should call before software enc*/
782 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
784 struct rtl_priv *rtlpriv = rtl_priv(hw);
785 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
786 __le16 fc = rtl_get_fc(skb);
788 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
789 const struct iphdr *ip;
791 if (!ieee80211_is_data(fc))
795 ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len +
796 SNAP_SIZE + PROTOC_TYPE_SIZE);
797 ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE);
798 /* ether_type = ntohs(ether_type); */
800 if (ETH_P_IP == ether_type) {
801 if (IPPROTO_UDP == ip->protocol) {
802 struct udphdr *udp = (struct udphdr *)((u8 *) ip +
804 if (((((u8 *) udp)[1] == 68) &&
805 (((u8 *) udp)[3] == 67)) ||
806 ((((u8 *) udp)[1] == 67) &&
807 (((u8 *) udp)[3] == 68))) {
809 * 68 : UDP BOOTP client
810 * 67 : UDP BOOTP server
812 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
813 DBG_DMESG, ("dhcp %s !!\n",
814 (is_tx) ? "Tx" : "Rx"));
818 ppsc->last_delaylps_stamp_jiffies =
825 } else if (ETH_P_ARP == ether_type) {
828 ppsc->last_delaylps_stamp_jiffies = jiffies;
832 } else if (ETH_P_PAE == ether_type) {
833 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
834 ("802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx"));
838 ppsc->last_delaylps_stamp_jiffies = jiffies;
842 } else if (ETH_P_IPV6 == ether_type) {
850 /*********************************************************
852 * functions called by core.c
854 *********************************************************/
855 int rtl_tx_agg_start(struct ieee80211_hw *hw,
856 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
858 struct rtl_priv *rtlpriv = rtl_priv(hw);
859 struct rtl_tid_data *tid_data;
860 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
861 struct rtl_sta_info *sta_entry = NULL;
866 if (unlikely(tid >= MAX_TID_COUNT))
869 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
872 tid_data = &sta_entry->tids[tid];
874 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
875 ("on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
876 tid_data->seq_number));
878 *ssn = tid_data->seq_number;
879 tid_data->agg.agg_state = RTL_AGG_START;
881 ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
886 int rtl_tx_agg_stop(struct ieee80211_hw *hw,
887 struct ieee80211_sta *sta, u16 tid)
889 struct rtl_priv *rtlpriv = rtl_priv(hw);
890 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
891 struct rtl_sta_info *sta_entry = NULL;
897 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
901 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
902 ("on ra = %pM tid = %d\n", sta->addr, tid));
904 if (unlikely(tid >= MAX_TID_COUNT))
907 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
908 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
910 ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
915 int rtl_tx_agg_oper(struct ieee80211_hw *hw,
916 struct ieee80211_sta *sta, u16 tid)
918 struct rtl_priv *rtlpriv = rtl_priv(hw);
919 struct rtl_sta_info *sta_entry = NULL;
925 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
929 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
930 ("on ra = %pM tid = %d\n", sta->addr, tid));
932 if (unlikely(tid >= MAX_TID_COUNT))
935 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
936 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
941 /*********************************************************
943 * wq & timer callback functions
945 *********************************************************/
946 void rtl_watchdog_wq_callback(void *data)
948 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
951 struct ieee80211_hw *hw = rtlworks->hw;
952 struct rtl_priv *rtlpriv = rtl_priv(hw);
953 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
954 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
955 bool busytraffic = false;
956 bool higher_busytraffic = false;
957 bool higher_busyrxtraffic = false;
959 u32 rx_cnt_inp4eriod = 0;
960 u32 tx_cnt_inp4eriod = 0;
961 u32 aver_rx_cnt_inperiod = 0;
962 u32 aver_tx_cnt_inperiod = 0;
963 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
964 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
965 bool enter_ps = false;
967 if (is_hal_stop(rtlhal))
970 /* <1> Determine if action frame is allowed */
971 if (mac->link_state > MAC80211_NOLINK) {
972 if (mac->cnt_after_linked < 20)
973 mac->cnt_after_linked++;
975 mac->cnt_after_linked = 0;
979 *<3> to check if traffic busy, if
980 * busytraffic we don't change channel
982 if (mac->link_state >= MAC80211_LINKED) {
984 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
985 for (idx = 0; idx <= 2; idx++) {
986 rtlpriv->link_info.num_rx_in4period[idx] =
987 rtlpriv->link_info.num_rx_in4period[idx + 1];
988 rtlpriv->link_info.num_tx_in4period[idx] =
989 rtlpriv->link_info.num_tx_in4period[idx + 1];
991 rtlpriv->link_info.num_rx_in4period[3] =
992 rtlpriv->link_info.num_rx_inperiod;
993 rtlpriv->link_info.num_tx_in4period[3] =
994 rtlpriv->link_info.num_tx_inperiod;
995 for (idx = 0; idx <= 3; idx++) {
997 rtlpriv->link_info.num_rx_in4period[idx];
999 rtlpriv->link_info.num_tx_in4period[idx];
1001 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1002 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1004 /* (2) check traffic busy */
1005 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100)
1008 /* Higher Tx/Rx data. */
1009 if (aver_rx_cnt_inperiod > 4000 ||
1010 aver_tx_cnt_inperiod > 4000) {
1011 higher_busytraffic = true;
1013 /* Extremely high Rx data. */
1014 if (aver_rx_cnt_inperiod > 5000)
1015 higher_busyrxtraffic = true;
1018 /* check every tid's tx traffic */
1019 for (tid = 0; tid <= 7; tid++) {
1020 for (idx = 0; idx <= 2; idx++)
1021 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1022 rtlpriv->link_info.tidtx_in4period[tid]
1024 rtlpriv->link_info.tidtx_in4period[tid][3] =
1025 rtlpriv->link_info.tidtx_inperiod[tid];
1027 for (idx = 0; idx <= 3; idx++)
1028 tidtx_inp4eriod[tid] +=
1029 rtlpriv->link_info.tidtx_in4period[tid][idx];
1030 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1031 if (aver_tidtx_inperiod[tid] > 5000)
1032 rtlpriv->link_info.higher_busytxtraffic[tid] =
1035 rtlpriv->link_info.higher_busytxtraffic[tid] =
1039 if (((rtlpriv->link_info.num_rx_inperiod +
1040 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1041 (rtlpriv->link_info.num_rx_inperiod > 2))
1046 /* LeisurePS only work in infra mode. */
1053 rtlpriv->link_info.num_rx_inperiod = 0;
1054 rtlpriv->link_info.num_tx_inperiod = 0;
1055 for (tid = 0; tid <= 7; tid++)
1056 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
1058 rtlpriv->link_info.busytraffic = busytraffic;
1059 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
1060 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
1063 rtlpriv->cfg->ops->dm_watchdog(hw);
1066 void rtl_watch_dog_timer_callback(unsigned long data)
1068 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1069 struct rtl_priv *rtlpriv = rtl_priv(hw);
1071 queue_delayed_work(rtlpriv->works.rtl_wq,
1072 &rtlpriv->works.watchdog_wq, 0);
1074 mod_timer(&rtlpriv->works.watchdog_timer,
1075 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1078 /*********************************************************
1080 * frame process functions
1082 *********************************************************/
1083 u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1085 struct ieee80211_mgmt *mgmt = (void *)data;
1088 pos = (u8 *)mgmt->u.beacon.variable;
1091 if (pos + 2 + pos[1] > end)
1102 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1103 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1104 static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
1105 enum ieee80211_smps_mode smps, u8 *da, u8 *bssid)
1107 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1108 struct sk_buff *skb;
1109 struct ieee80211_mgmt *action_frame;
1111 /* 27 = header + category + action + smps mode */
1112 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1116 skb_reserve(skb, hw->extra_tx_headroom);
1117 action_frame = (void *)skb_put(skb, 27);
1118 memset(action_frame, 0, 27);
1119 memcpy(action_frame->da, da, ETH_ALEN);
1120 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1121 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1122 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1123 IEEE80211_STYPE_ACTION);
1124 action_frame->u.action.category = WLAN_CATEGORY_HT;
1125 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1127 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1128 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1130 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1131 action_frame->u.action.u.ht_smps.smps_control =
1132 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1134 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1135 action_frame->u.action.u.ht_smps.smps_control =
1136 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1138 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1139 action_frame->u.action.u.ht_smps.smps_control =
1140 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1147 int rtl_send_smps_action(struct ieee80211_hw *hw,
1148 struct ieee80211_sta *sta, u8 *da, u8 *bssid,
1149 enum ieee80211_smps_mode smps)
1151 struct rtl_priv *rtlpriv = rtl_priv(hw);
1152 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1153 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1154 struct sk_buff *skb = rtl_make_smps_action(hw, smps, da, bssid);
1155 struct rtl_tcb_desc tcb_desc;
1156 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1158 if (rtlpriv->mac80211.act_scanning)
1164 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1167 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1170 /* this is a type = mgmt * stype = action frame */
1172 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1173 struct rtl_sta_info *sta_entry =
1174 (struct rtl_sta_info *) sta->drv_priv;
1175 sta_entry->mimo_ps = smps;
1176 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
1178 info->control.rates[0].idx = 0;
1179 info->control.sta = sta;
1180 info->band = hw->conf.channel->band;
1181 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
1187 /*********************************************************
1191 *********************************************************/
1192 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
1193 struct octet_string vendor_ie)
1195 struct rtl_priv *rtlpriv = rtl_priv(hw);
1196 bool matched = false;
1197 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1198 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1199 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1200 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1201 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1202 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1203 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1204 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1206 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1207 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1208 rtlpriv->mac80211.vendor = PEER_ATH;
1210 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1211 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1212 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1213 rtlpriv->mac80211.vendor = PEER_BROAD;
1215 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1216 rtlpriv->mac80211.vendor = PEER_RAL;
1218 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1219 rtlpriv->mac80211.vendor = PEER_CISCO;
1221 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1222 rtlpriv->mac80211.vendor = PEER_MARV;
1229 static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
1232 struct ieee80211_mgmt *mgmt = (void *)data;
1233 struct octet_string vendor_ie;
1236 pos = (u8 *)mgmt->u.beacon.variable;
1239 if (pos[0] == 221) {
1240 vendor_ie.length = pos[1];
1241 vendor_ie.octet = &pos[2];
1242 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1246 if (pos + 2 + pos[1] > end)
1254 void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
1256 struct rtl_priv *rtlpriv = rtl_priv(hw);
1257 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1258 struct ieee80211_hdr *hdr = (void *)data;
1259 u32 vendor = PEER_UNKNOWN;
1261 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
1262 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
1263 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
1264 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
1265 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
1266 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
1267 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
1268 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
1269 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
1270 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
1271 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
1272 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
1273 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
1274 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
1275 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
1276 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
1278 if (mac->opmode != NL80211_IFTYPE_STATION)
1281 if (mac->link_state == MAC80211_NOLINK) {
1282 mac->vendor = PEER_UNKNOWN;
1286 if (mac->cnt_after_linked > 2)
1289 /* check if this really is a beacon */
1290 if (!ieee80211_is_beacon(hdr->frame_control))
1293 /* min. beacon length + FCS_LEN */
1294 if (len <= 40 + FCS_LEN)
1297 /* and only beacons from the associated BSSID, please */
1298 if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid))
1301 if (rtl_find_221_ie(hw, data, len))
1302 vendor = mac->vendor;
1304 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
1305 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
1306 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
1307 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
1308 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
1309 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
1310 vendor == PEER_ATH) {
1312 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ath find\n"));
1313 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
1314 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
1315 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
1316 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
1317 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
1318 vendor == PEER_RAL) {
1319 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ral findn\n"));
1321 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
1322 vendor == PEER_CISCO) {
1323 vendor = PEER_CISCO;
1324 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>cisco find\n"));
1325 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
1326 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
1327 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
1328 vendor == PEER_BROAD) {
1329 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>broad find\n"));
1330 vendor = PEER_BROAD;
1331 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
1332 vendor == PEER_MARV) {
1334 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>marv find\n"));
1337 mac->vendor = vendor;
1340 /*********************************************************
1344 *********************************************************/
1345 static ssize_t rtl_show_debug_level(struct device *d,
1346 struct device_attribute *attr, char *buf)
1348 struct ieee80211_hw *hw = dev_get_drvdata(d);
1349 struct rtl_priv *rtlpriv = rtl_priv(hw);
1351 return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
1354 static ssize_t rtl_store_debug_level(struct device *d,
1355 struct device_attribute *attr,
1356 const char *buf, size_t count)
1358 struct ieee80211_hw *hw = dev_get_drvdata(d);
1359 struct rtl_priv *rtlpriv = rtl_priv(hw);
1363 ret = strict_strtoul(buf, 0, &val);
1365 printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf);
1367 rtlpriv->dbg.global_debuglevel = val;
1368 printk(KERN_DEBUG "debuglevel:%x\n",
1369 rtlpriv->dbg.global_debuglevel);
1372 return strnlen(buf, count);
1375 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1376 rtl_show_debug_level, rtl_store_debug_level);
1378 static struct attribute *rtl_sysfs_entries[] = {
1380 &dev_attr_debug_level.attr,
1386 * "name" is folder name witch will be
1387 * put in device directory like :
1388 * sys/devices/pci0000:00/0000:00:1c.4/
1389 * 0000:06:00.0/rtl_sysfs
1391 struct attribute_group rtl_attribute_group = {
1393 .attrs = rtl_sysfs_entries,
1396 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
1397 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
1398 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
1399 MODULE_LICENSE("GPL");
1400 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
1402 static int __init rtl_core_module_init(void)
1404 if (rtl_rate_control_register())
1405 printk(KERN_ERR "rtlwifi: Unable to register rtl_rc,"
1406 "use default RC !!\n");
1411 static void __exit rtl_core_module_exit(void)
1414 rtl_rate_control_unregister();
1417 module_init(rtl_core_module_init);
1418 module_exit(rtl_core_module_exit);