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>
34 #include <linux/udp.h>
44 *NOTICE!!!: This file will be very big, we hsould
45 *keep it clear under follwing roles:
47 *This file include follwing part, so, if you add new
48 *functions into this file, please check which part it
49 *should includes. or check if you should add new part
52 *1) mac80211 init functions
53 *2) tx information functions
54 *3) functions called by core.c
55 *4) wq & timer callback functions
56 *5) frame process functions
62 /*********************************************************
64 * mac80211 init functions
66 *********************************************************/
67 static struct ieee80211_channel rtl_channeltable_2g[] = {
68 {.center_freq = 2412, .hw_value = 1,},
69 {.center_freq = 2417, .hw_value = 2,},
70 {.center_freq = 2422, .hw_value = 3,},
71 {.center_freq = 2427, .hw_value = 4,},
72 {.center_freq = 2432, .hw_value = 5,},
73 {.center_freq = 2437, .hw_value = 6,},
74 {.center_freq = 2442, .hw_value = 7,},
75 {.center_freq = 2447, .hw_value = 8,},
76 {.center_freq = 2452, .hw_value = 9,},
77 {.center_freq = 2457, .hw_value = 10,},
78 {.center_freq = 2462, .hw_value = 11,},
79 {.center_freq = 2467, .hw_value = 12,},
80 {.center_freq = 2472, .hw_value = 13,},
81 {.center_freq = 2484, .hw_value = 14,},
84 static struct ieee80211_channel rtl_channeltable_5g[] = {
85 {.center_freq = 5180, .hw_value = 36,},
86 {.center_freq = 5200, .hw_value = 40,},
87 {.center_freq = 5220, .hw_value = 44,},
88 {.center_freq = 5240, .hw_value = 48,},
89 {.center_freq = 5260, .hw_value = 52,},
90 {.center_freq = 5280, .hw_value = 56,},
91 {.center_freq = 5300, .hw_value = 60,},
92 {.center_freq = 5320, .hw_value = 64,},
93 {.center_freq = 5500, .hw_value = 100,},
94 {.center_freq = 5520, .hw_value = 104,},
95 {.center_freq = 5540, .hw_value = 108,},
96 {.center_freq = 5560, .hw_value = 112,},
97 {.center_freq = 5580, .hw_value = 116,},
98 {.center_freq = 5600, .hw_value = 120,},
99 {.center_freq = 5620, .hw_value = 124,},
100 {.center_freq = 5640, .hw_value = 128,},
101 {.center_freq = 5660, .hw_value = 132,},
102 {.center_freq = 5680, .hw_value = 136,},
103 {.center_freq = 5700, .hw_value = 140,},
104 {.center_freq = 5745, .hw_value = 149,},
105 {.center_freq = 5765, .hw_value = 153,},
106 {.center_freq = 5785, .hw_value = 157,},
107 {.center_freq = 5805, .hw_value = 161,},
108 {.center_freq = 5825, .hw_value = 165,},
111 static struct ieee80211_rate rtl_ratetable_2g[] = {
112 {.bitrate = 10, .hw_value = 0x00,},
113 {.bitrate = 20, .hw_value = 0x01,},
114 {.bitrate = 55, .hw_value = 0x02,},
115 {.bitrate = 110, .hw_value = 0x03,},
116 {.bitrate = 60, .hw_value = 0x04,},
117 {.bitrate = 90, .hw_value = 0x05,},
118 {.bitrate = 120, .hw_value = 0x06,},
119 {.bitrate = 180, .hw_value = 0x07,},
120 {.bitrate = 240, .hw_value = 0x08,},
121 {.bitrate = 360, .hw_value = 0x09,},
122 {.bitrate = 480, .hw_value = 0x0a,},
123 {.bitrate = 540, .hw_value = 0x0b,},
126 static struct ieee80211_rate rtl_ratetable_5g[] = {
127 {.bitrate = 60, .hw_value = 0x04,},
128 {.bitrate = 90, .hw_value = 0x05,},
129 {.bitrate = 120, .hw_value = 0x06,},
130 {.bitrate = 180, .hw_value = 0x07,},
131 {.bitrate = 240, .hw_value = 0x08,},
132 {.bitrate = 360, .hw_value = 0x09,},
133 {.bitrate = 480, .hw_value = 0x0a,},
134 {.bitrate = 540, .hw_value = 0x0b,},
137 static const struct ieee80211_supported_band rtl_band_2ghz = {
138 .band = IEEE80211_BAND_2GHZ,
140 .channels = rtl_channeltable_2g,
141 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
143 .bitrates = rtl_ratetable_2g,
144 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
149 static struct ieee80211_supported_band rtl_band_5ghz = {
150 .band = IEEE80211_BAND_5GHZ,
152 .channels = rtl_channeltable_5g,
153 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
155 .bitrates = rtl_ratetable_5g,
156 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
161 static const u8 tid_to_ac[] = {
162 2, /* IEEE80211_AC_BE */
163 3, /* IEEE80211_AC_BK */
164 3, /* IEEE80211_AC_BK */
165 2, /* IEEE80211_AC_BE */
166 1, /* IEEE80211_AC_VI */
167 1, /* IEEE80211_AC_VI */
168 0, /* IEEE80211_AC_VO */
169 0, /* IEEE80211_AC_VO */
172 u8 rtl_tid_to_ac(struct ieee80211_hw *hw, u8 tid)
174 return tid_to_ac[tid];
177 static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
178 struct ieee80211_sta_ht_cap *ht_cap)
180 struct rtl_priv *rtlpriv = rtl_priv(hw);
181 struct rtl_phy *rtlphy = &(rtlpriv->phy);
183 ht_cap->ht_supported = true;
184 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
185 IEEE80211_HT_CAP_SGI_40 |
186 IEEE80211_HT_CAP_SGI_20 |
187 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
189 if (rtlpriv->rtlhal.disable_amsdu_8k)
190 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
193 *Maximum length of AMPDU that the STA can receive.
194 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
196 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
198 /*Minimum MPDU start spacing , */
199 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
201 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
204 *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
207 *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7
208 *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15
209 *if rx_ant >=3 rx_mask[2]=0xff;
210 *if BW_40 rx_mask[4]=0x01;
211 *highest supported RX rate
213 if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_2T2R) {
215 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("1T2R or 2T2R\n"));
217 ht_cap->mcs.rx_mask[0] = 0xFF;
218 ht_cap->mcs.rx_mask[1] = 0xFF;
219 ht_cap->mcs.rx_mask[4] = 0x01;
221 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
222 } else if (get_rf_type(rtlphy) == RF_1T1R) {
224 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("1T1R\n"));
226 ht_cap->mcs.rx_mask[0] = 0xFF;
227 ht_cap->mcs.rx_mask[1] = 0x00;
228 ht_cap->mcs.rx_mask[4] = 0x01;
230 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
234 static void _rtl_init_mac80211(struct ieee80211_hw *hw)
236 struct rtl_priv *rtlpriv = rtl_priv(hw);
237 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
238 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
239 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
240 struct ieee80211_supported_band *sband;
243 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset ==
246 /* <1> use mac->bands as mem for hw->wiphy->bands */
247 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
249 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
250 * to default value(1T1R) */
251 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
252 sizeof(struct ieee80211_supported_band));
254 /* <3> init ht cap base on ant_num */
255 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
257 /* <4> set mac->sband to wiphy->sband */
258 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
261 /* <1> use mac->bands as mem for hw->wiphy->bands */
262 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
264 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
265 * to default value(1T1R) */
266 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
267 sizeof(struct ieee80211_supported_band));
269 /* <3> init ht cap base on ant_num */
270 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
272 /* <4> set mac->sband to wiphy->sband */
273 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
275 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
276 /* <1> use mac->bands as mem for hw->wiphy->bands */
277 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
279 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
280 * to default value(1T1R) */
281 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
283 sizeof(struct ieee80211_supported_band));
285 /* <3> init ht cap base on ant_num */
286 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
288 /* <4> set mac->sband to wiphy->sband */
289 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
290 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
291 /* <1> use mac->bands as mem for hw->wiphy->bands */
292 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
294 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
295 * to default value(1T1R) */
296 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
298 sizeof(struct ieee80211_supported_band));
300 /* <3> init ht cap base on ant_num */
301 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
303 /* <4> set mac->sband to wiphy->sband */
304 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
306 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
308 rtlhal->current_bandtype));
311 /* <5> set hw caps */
312 hw->flags = IEEE80211_HW_SIGNAL_DBM |
313 IEEE80211_HW_RX_INCLUDES_FCS |
314 IEEE80211_HW_BEACON_FILTER |
315 IEEE80211_HW_AMPDU_AGGREGATION |
316 IEEE80211_HW_CONNECTION_MONITOR |
317 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
318 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
320 /* swlps or hwlps has been set in diff chip in init_sw_vars */
321 if (rtlpriv->psc.swctrl_lps)
322 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
323 IEEE80211_HW_PS_NULLFUNC_STACK |
324 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
327 hw->wiphy->interface_modes =
328 BIT(NL80211_IFTYPE_AP) |
329 BIT(NL80211_IFTYPE_STATION) |
330 BIT(NL80211_IFTYPE_ADHOC);
332 hw->wiphy->rts_threshold = 2347;
335 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
337 /* TODO: Correct this value for our hw */
338 /* TODO: define these hard code value */
339 hw->channel_change_time = 100;
340 hw->max_listen_interval = 10;
341 hw->max_rate_tries = 4;
342 /* hw->max_rates = 1; */
343 hw->sta_data_size = sizeof(struct rtl_sta_info);
345 /* <6> mac address */
346 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
347 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
349 u8 rtlmac[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
350 get_random_bytes((rtlmac + (ETH_ALEN - 1)), 1);
351 SET_IEEE80211_PERM_ADDR(hw, rtlmac);
356 static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
358 struct rtl_priv *rtlpriv = rtl_priv(hw);
361 init_timer(&rtlpriv->works.watchdog_timer);
362 setup_timer(&rtlpriv->works.watchdog_timer,
363 rtl_watch_dog_timer_callback, (unsigned long)hw);
366 rtlpriv->works.hw = hw;
367 rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0);
368 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
369 (void *)rtl_watchdog_wq_callback);
370 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
371 (void *)rtl_ips_nic_off_wq_callback);
372 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
373 (void *)rtl_swlps_wq_callback);
374 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
375 (void *)rtl_swlps_rfon_wq_callback);
379 void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
381 struct rtl_priv *rtlpriv = rtl_priv(hw);
383 del_timer_sync(&rtlpriv->works.watchdog_timer);
385 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
386 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
387 cancel_delayed_work(&rtlpriv->works.ps_work);
388 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
391 void rtl_init_rfkill(struct ieee80211_hw *hw)
393 struct rtl_priv *rtlpriv = rtl_priv(hw);
399 /*set init state to on */
400 rtlpriv->rfkill.rfkill_state = 1;
401 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
403 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
406 pr_info("wireless switch is %s\n",
407 rtlpriv->rfkill.rfkill_state ? "on" : "off");
409 rtlpriv->rfkill.rfkill_state = radio_state;
411 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
412 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
415 wiphy_rfkill_start_polling(hw->wiphy);
418 void rtl_deinit_rfkill(struct ieee80211_hw *hw)
420 wiphy_rfkill_stop_polling(hw->wiphy);
423 int rtl_init_core(struct ieee80211_hw *hw)
425 struct rtl_priv *rtlpriv = rtl_priv(hw);
426 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
428 /* <1> init mac80211 */
429 _rtl_init_mac80211(hw);
432 /* <2> rate control register */
433 hw->rate_control_algorithm = "rtl_rc";
436 * <3> init CRDA must come after init
437 * mac80211 hw in _rtl_init_mac80211.
439 if (rtl_regd_init(hw, rtl_reg_notifier)) {
440 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("REGD init failed\n"));
443 /* CRDA regd hint must after init CRDA */
444 if (regulatory_hint(hw->wiphy, rtlpriv->regd.alpha2)) {
445 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
446 ("regulatory_hint fail\n"));
451 mutex_init(&rtlpriv->locks.conf_mutex);
452 spin_lock_init(&rtlpriv->locks.ips_lock);
453 spin_lock_init(&rtlpriv->locks.irq_th_lock);
454 spin_lock_init(&rtlpriv->locks.h2c_lock);
455 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
456 spin_lock_init(&rtlpriv->locks.rf_lock);
457 spin_lock_init(&rtlpriv->locks.lps_lock);
458 spin_lock_init(&rtlpriv->locks.waitq_lock);
459 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
461 rtlmac->link_state = MAC80211_NOLINK;
463 /* <5> init deferred work */
464 _rtl_init_deferred_work(hw);
469 void rtl_deinit_core(struct ieee80211_hw *hw)
473 void rtl_init_rx_config(struct ieee80211_hw *hw)
475 struct rtl_priv *rtlpriv = rtl_priv(hw);
476 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
478 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
481 /*********************************************************
483 * tx information functions
485 *********************************************************/
486 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
487 struct rtl_tcb_desc *tcb_desc,
488 struct ieee80211_tx_info *info)
490 struct rtl_priv *rtlpriv = rtl_priv(hw);
491 u8 rate_flag = info->control.rates[0].flags;
493 tcb_desc->use_shortpreamble = false;
495 /* 1M can only use Long Preamble. 11B spec */
496 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
498 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
499 tcb_desc->use_shortpreamble = true;
504 static void _rtl_query_shortgi(struct ieee80211_hw *hw,
505 struct ieee80211_sta *sta,
506 struct rtl_tcb_desc *tcb_desc,
507 struct ieee80211_tx_info *info)
509 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
510 u8 rate_flag = info->control.rates[0].flags;
511 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
512 tcb_desc->use_shortgi = false;
517 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
518 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
520 if (!(sta->ht_cap.ht_supported))
523 if (!sgi_40 && !sgi_20)
526 if (mac->opmode == NL80211_IFTYPE_STATION)
528 else if (mac->opmode == NL80211_IFTYPE_AP ||
529 mac->opmode == NL80211_IFTYPE_ADHOC)
530 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
533 tcb_desc->use_shortgi = true;
534 else if ((bw_40 == false) && sgi_20)
535 tcb_desc->use_shortgi = true;
537 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
538 tcb_desc->use_shortgi = false;
541 static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
542 struct rtl_tcb_desc *tcb_desc,
543 struct ieee80211_tx_info *info)
545 struct rtl_priv *rtlpriv = rtl_priv(hw);
546 u8 rate_flag = info->control.rates[0].flags;
548 /* Common Settings */
549 tcb_desc->rts_stbc = false;
550 tcb_desc->cts_enable = false;
551 tcb_desc->rts_sc = 0;
552 tcb_desc->rts_bw = false;
553 tcb_desc->rts_use_shortpreamble = false;
554 tcb_desc->rts_use_shortgi = false;
556 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
557 /* Use CTS-to-SELF in protection mode. */
558 tcb_desc->rts_enable = true;
559 tcb_desc->cts_enable = true;
560 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
561 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
562 /* Use RTS-CTS in protection mode. */
563 tcb_desc->rts_enable = true;
564 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
568 static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
569 struct ieee80211_sta *sta,
570 struct rtl_tcb_desc *tcb_desc)
572 struct rtl_priv *rtlpriv = rtl_priv(hw);
573 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
574 struct rtl_sta_info *sta_entry = NULL;
578 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
579 ratr_index = sta_entry->ratr_index;
581 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
582 if (mac->opmode == NL80211_IFTYPE_STATION) {
583 tcb_desc->ratr_index = 0;
584 } else if (mac->opmode == NL80211_IFTYPE_ADHOC) {
585 if (tcb_desc->multicast || tcb_desc->broadcast) {
587 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
588 tcb_desc->use_driver_rate = 1;
592 tcb_desc->ratr_index = ratr_index;
593 } else if (mac->opmode == NL80211_IFTYPE_AP) {
594 tcb_desc->ratr_index = ratr_index;
598 if (rtlpriv->dm.useramask) {
599 /* TODO we will differentiate adhoc and station futrue */
600 if (mac->opmode == NL80211_IFTYPE_STATION) {
601 tcb_desc->mac_id = 0;
603 if (mac->mode == WIRELESS_MODE_N_24G)
604 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
605 else if (mac->mode == WIRELESS_MODE_N_5G)
606 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
607 else if (mac->mode & WIRELESS_MODE_G)
608 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
609 else if (mac->mode & WIRELESS_MODE_B)
610 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
611 else if (mac->mode & WIRELESS_MODE_A)
612 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
613 } else if (mac->opmode == NL80211_IFTYPE_AP ||
614 mac->opmode == NL80211_IFTYPE_ADHOC) {
617 tcb_desc->mac_id = sta->aid + 1;
619 tcb_desc->mac_id = 1;
621 tcb_desc->mac_id = 0;
628 static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
629 struct ieee80211_sta *sta,
630 struct rtl_tcb_desc *tcb_desc)
632 struct rtl_priv *rtlpriv = rtl_priv(hw);
633 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
635 tcb_desc->packet_bw = false;
638 if (mac->opmode == NL80211_IFTYPE_AP ||
639 mac->opmode == NL80211_IFTYPE_ADHOC) {
640 if (!(sta->ht_cap.ht_supported) ||
641 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
643 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
644 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
647 if (tcb_desc->multicast || tcb_desc->broadcast)
650 /*use legency rate, shall use 20MHz */
651 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
654 tcb_desc->packet_bw = true;
657 static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw)
659 struct rtl_priv *rtlpriv = rtl_priv(hw);
660 struct rtl_phy *rtlphy = &(rtlpriv->phy);
663 if (get_rf_type(rtlphy) == RF_2T2R)
664 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
666 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
671 /* mac80211's rate_idx is like this:
673 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
676 * (rx_status->flag & RX_FLAG_HT) = 0,
677 * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11,
680 * (rx_status->flag & RX_FLAG_HT) = 1,
681 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
683 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
685 * (rx_status->flag & RX_FLAG_HT) = 0,
686 * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7,
689 * (rx_status->flag & RX_FLAG_HT) = 1,
690 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
692 int rtlwifi_rate_mapping(struct ieee80211_hw *hw,
693 bool isht, u8 desc_rate, bool first_ampdu)
698 if (IEEE80211_BAND_2GHZ == hw->conf.channel->band) {
706 case DESC92_RATE5_5M:
775 case DESC92_RATEMCS0:
778 case DESC92_RATEMCS1:
781 case DESC92_RATEMCS2:
784 case DESC92_RATEMCS3:
787 case DESC92_RATEMCS4:
790 case DESC92_RATEMCS5:
793 case DESC92_RATEMCS6:
796 case DESC92_RATEMCS7:
799 case DESC92_RATEMCS8:
802 case DESC92_RATEMCS9:
805 case DESC92_RATEMCS10:
808 case DESC92_RATEMCS11:
811 case DESC92_RATEMCS12:
814 case DESC92_RATEMCS13:
817 case DESC92_RATEMCS14:
820 case DESC92_RATEMCS15:
830 EXPORT_SYMBOL(rtlwifi_rate_mapping);
832 void rtl_get_tcb_desc(struct ieee80211_hw *hw,
833 struct ieee80211_tx_info *info,
834 struct ieee80211_sta *sta,
835 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
837 struct rtl_priv *rtlpriv = rtl_priv(hw);
838 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
839 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
840 struct ieee80211_rate *txrate;
841 __le16 fc = hdr->frame_control;
843 txrate = ieee80211_get_tx_rate(hw, info);
844 tcb_desc->hw_rate = txrate->hw_value;
846 if (ieee80211_is_data(fc)) {
848 *we set data rate INX 0
849 *in rtl_rc.c if skb is special data or
850 *mgt which need low data rate.
854 *So tcb_desc->hw_rate is just used for
855 *special data and mgt frames
857 if (info->control.rates[0].idx == 0 ||
858 ieee80211_is_nullfunc(fc)) {
859 tcb_desc->use_driver_rate = true;
860 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
862 tcb_desc->disable_ratefallback = 1;
865 *because hw will nerver use hw_rate
866 *when tcb_desc->use_driver_rate = false
867 *so we never set highest N rate here,
868 *and N rate will all be controlled by FW
869 *when tcb_desc->use_driver_rate = false
871 if (sta && (sta->ht_cap.ht_supported)) {
872 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw);
874 if (rtlmac->mode == WIRELESS_MODE_B) {
876 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
879 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
884 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
885 tcb_desc->multicast = 1;
886 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
887 tcb_desc->broadcast = 1;
889 _rtl_txrate_selectmode(hw, sta, tcb_desc);
890 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
891 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
892 _rtl_query_shortgi(hw, sta, tcb_desc, info);
893 _rtl_query_protection_mode(hw, tcb_desc, info);
895 tcb_desc->use_driver_rate = true;
896 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
897 tcb_desc->disable_ratefallback = 1;
898 tcb_desc->mac_id = 0;
899 tcb_desc->packet_bw = false;
902 EXPORT_SYMBOL(rtl_get_tcb_desc);
904 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
906 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
907 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
908 struct rtl_priv *rtlpriv = rtl_priv(hw);
909 __le16 fc = hdr->frame_control;
910 u8 *act = (u8 *) (((u8 *) skb->data + MAC80211_3ADDR_LEN));
913 if (!ieee80211_is_action(fc))
922 if (mac->act_scanning)
925 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
926 ("%s ACT_ADDBAREQ From :%pM\n",
927 is_tx ? "Tx" : "Rx", hdr->addr2));
930 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
931 ("%s ACT_ADDBARSP From :%pM\n",
932 is_tx ? "Tx" : "Rx", hdr->addr2));
935 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
936 ("ACT_ADDBADEL From :%pM\n", hdr->addr2));
947 /*should call before software enc*/
948 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
950 struct rtl_priv *rtlpriv = rtl_priv(hw);
951 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
952 __le16 fc = rtl_get_fc(skb);
954 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
955 const struct iphdr *ip;
957 if (!ieee80211_is_data(fc))
960 ip = (const struct iphdr *)(skb->data + mac_hdr_len +
961 SNAP_SIZE + PROTOC_TYPE_SIZE);
962 ether_type = be16_to_cpup((__be16 *)
963 (skb->data + mac_hdr_len + SNAP_SIZE));
965 switch (ether_type) {
971 if (ip->protocol != IPPROTO_UDP)
973 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
974 src = be16_to_cpu(udp->source);
975 dst = be16_to_cpu(udp->dest);
977 /* If this case involves port 68 (UDP BOOTP client) connecting
978 * with port 67 (UDP BOOTP server), then return true so that
979 * the lowest speed is used.
981 if (!((src == 68 && dst == 67) || (src == 67 && dst == 68)))
984 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
985 ("dhcp %s !!\n", is_tx ? "Tx" : "Rx"));
991 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
992 ("802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx"));
995 /* TODO: Is this right? */
1002 ppsc->last_delaylps_stamp_jiffies = jiffies;
1007 /*********************************************************
1009 * functions called by core.c
1011 *********************************************************/
1012 int rtl_tx_agg_start(struct ieee80211_hw *hw,
1013 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1015 struct rtl_priv *rtlpriv = rtl_priv(hw);
1016 struct rtl_tid_data *tid_data;
1017 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1018 struct rtl_sta_info *sta_entry = NULL;
1023 if (unlikely(tid >= MAX_TID_COUNT))
1026 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1029 tid_data = &sta_entry->tids[tid];
1031 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1032 ("on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1033 tid_data->seq_number));
1035 *ssn = tid_data->seq_number;
1036 tid_data->agg.agg_state = RTL_AGG_START;
1038 ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
1043 int rtl_tx_agg_stop(struct ieee80211_hw *hw,
1044 struct ieee80211_sta *sta, u16 tid)
1046 struct rtl_priv *rtlpriv = rtl_priv(hw);
1047 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1048 struct rtl_sta_info *sta_entry = NULL;
1054 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
1058 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1059 ("on ra = %pM tid = %d\n", sta->addr, tid));
1061 if (unlikely(tid >= MAX_TID_COUNT))
1064 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1065 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
1067 ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
1072 int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1073 struct ieee80211_sta *sta, u16 tid)
1075 struct rtl_priv *rtlpriv = rtl_priv(hw);
1076 struct rtl_sta_info *sta_entry = NULL;
1082 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
1086 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1087 ("on ra = %pM tid = %d\n", sta->addr, tid));
1089 if (unlikely(tid >= MAX_TID_COUNT))
1092 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1093 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
1098 /*********************************************************
1100 * wq & timer callback functions
1102 *********************************************************/
1103 void rtl_watchdog_wq_callback(void *data)
1105 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1108 struct ieee80211_hw *hw = rtlworks->hw;
1109 struct rtl_priv *rtlpriv = rtl_priv(hw);
1110 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1111 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1112 bool busytraffic = false;
1113 bool higher_busytraffic = false;
1114 bool higher_busyrxtraffic = false;
1116 u32 rx_cnt_inp4eriod = 0;
1117 u32 tx_cnt_inp4eriod = 0;
1118 u32 aver_rx_cnt_inperiod = 0;
1119 u32 aver_tx_cnt_inperiod = 0;
1120 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1121 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
1122 bool enter_ps = false;
1124 if (is_hal_stop(rtlhal))
1127 /* <1> Determine if action frame is allowed */
1128 if (mac->link_state > MAC80211_NOLINK) {
1129 if (mac->cnt_after_linked < 20)
1130 mac->cnt_after_linked++;
1132 mac->cnt_after_linked = 0;
1136 *<2> to check if traffic busy, if
1137 * busytraffic we don't change channel
1139 if (mac->link_state >= MAC80211_LINKED) {
1141 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1142 for (idx = 0; idx <= 2; idx++) {
1143 rtlpriv->link_info.num_rx_in4period[idx] =
1144 rtlpriv->link_info.num_rx_in4period[idx + 1];
1145 rtlpriv->link_info.num_tx_in4period[idx] =
1146 rtlpriv->link_info.num_tx_in4period[idx + 1];
1148 rtlpriv->link_info.num_rx_in4period[3] =
1149 rtlpriv->link_info.num_rx_inperiod;
1150 rtlpriv->link_info.num_tx_in4period[3] =
1151 rtlpriv->link_info.num_tx_inperiod;
1152 for (idx = 0; idx <= 3; idx++) {
1154 rtlpriv->link_info.num_rx_in4period[idx];
1156 rtlpriv->link_info.num_tx_in4period[idx];
1158 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1159 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1161 /* (2) check traffic busy */
1162 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100)
1165 /* Higher Tx/Rx data. */
1166 if (aver_rx_cnt_inperiod > 4000 ||
1167 aver_tx_cnt_inperiod > 4000) {
1168 higher_busytraffic = true;
1170 /* Extremely high Rx data. */
1171 if (aver_rx_cnt_inperiod > 5000)
1172 higher_busyrxtraffic = true;
1175 /* check every tid's tx traffic */
1176 for (tid = 0; tid <= 7; tid++) {
1177 for (idx = 0; idx <= 2; idx++)
1178 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1179 rtlpriv->link_info.tidtx_in4period[tid]
1181 rtlpriv->link_info.tidtx_in4period[tid][3] =
1182 rtlpriv->link_info.tidtx_inperiod[tid];
1184 for (idx = 0; idx <= 3; idx++)
1185 tidtx_inp4eriod[tid] +=
1186 rtlpriv->link_info.tidtx_in4period[tid][idx];
1187 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1188 if (aver_tidtx_inperiod[tid] > 5000)
1189 rtlpriv->link_info.higher_busytxtraffic[tid] =
1192 rtlpriv->link_info.higher_busytxtraffic[tid] =
1196 if (((rtlpriv->link_info.num_rx_inperiod +
1197 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1198 (rtlpriv->link_info.num_rx_inperiod > 2))
1203 /* LeisurePS only work in infra mode. */
1210 rtlpriv->link_info.num_rx_inperiod = 0;
1211 rtlpriv->link_info.num_tx_inperiod = 0;
1212 for (tid = 0; tid <= 7; tid++)
1213 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
1215 rtlpriv->link_info.busytraffic = busytraffic;
1216 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
1217 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
1220 rtlpriv->cfg->ops->dm_watchdog(hw);
1223 void rtl_watch_dog_timer_callback(unsigned long data)
1225 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1226 struct rtl_priv *rtlpriv = rtl_priv(hw);
1228 queue_delayed_work(rtlpriv->works.rtl_wq,
1229 &rtlpriv->works.watchdog_wq, 0);
1231 mod_timer(&rtlpriv->works.watchdog_timer,
1232 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1235 /*********************************************************
1237 * frame process functions
1239 *********************************************************/
1240 u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1242 struct ieee80211_mgmt *mgmt = (void *)data;
1245 pos = (u8 *)mgmt->u.beacon.variable;
1248 if (pos + 2 + pos[1] > end)
1259 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1260 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1261 static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
1262 enum ieee80211_smps_mode smps, u8 *da, u8 *bssid)
1264 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1265 struct sk_buff *skb;
1266 struct ieee80211_mgmt *action_frame;
1268 /* 27 = header + category + action + smps mode */
1269 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1273 skb_reserve(skb, hw->extra_tx_headroom);
1274 action_frame = (void *)skb_put(skb, 27);
1275 memset(action_frame, 0, 27);
1276 memcpy(action_frame->da, da, ETH_ALEN);
1277 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1278 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1279 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1280 IEEE80211_STYPE_ACTION);
1281 action_frame->u.action.category = WLAN_CATEGORY_HT;
1282 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1284 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1285 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1287 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1288 action_frame->u.action.u.ht_smps.smps_control =
1289 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1291 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1292 action_frame->u.action.u.ht_smps.smps_control =
1293 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1295 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1296 action_frame->u.action.u.ht_smps.smps_control =
1297 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1304 int rtl_send_smps_action(struct ieee80211_hw *hw,
1305 struct ieee80211_sta *sta, u8 *da, u8 *bssid,
1306 enum ieee80211_smps_mode smps)
1308 struct rtl_priv *rtlpriv = rtl_priv(hw);
1309 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1310 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1311 struct sk_buff *skb = rtl_make_smps_action(hw, smps, da, bssid);
1312 struct rtl_tcb_desc tcb_desc;
1313 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1315 if (rtlpriv->mac80211.act_scanning)
1321 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1324 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1327 /* this is a type = mgmt * stype = action frame */
1329 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1330 struct rtl_sta_info *sta_entry =
1331 (struct rtl_sta_info *) sta->drv_priv;
1332 sta_entry->mimo_ps = smps;
1333 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
1335 info->control.rates[0].idx = 0;
1336 info->control.sta = sta;
1337 info->band = hw->conf.channel->band;
1338 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
1344 /*********************************************************
1348 *********************************************************/
1349 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
1350 struct octet_string vendor_ie)
1352 struct rtl_priv *rtlpriv = rtl_priv(hw);
1353 bool matched = false;
1354 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1355 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1356 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1357 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1358 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1359 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1360 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1361 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1363 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1364 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1365 rtlpriv->mac80211.vendor = PEER_ATH;
1367 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1368 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1369 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1370 rtlpriv->mac80211.vendor = PEER_BROAD;
1372 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1373 rtlpriv->mac80211.vendor = PEER_RAL;
1375 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1376 rtlpriv->mac80211.vendor = PEER_CISCO;
1378 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1379 rtlpriv->mac80211.vendor = PEER_MARV;
1386 static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
1389 struct ieee80211_mgmt *mgmt = (void *)data;
1390 struct octet_string vendor_ie;
1393 pos = (u8 *)mgmt->u.beacon.variable;
1396 if (pos[0] == 221) {
1397 vendor_ie.length = pos[1];
1398 vendor_ie.octet = &pos[2];
1399 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1403 if (pos + 2 + pos[1] > end)
1411 void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
1413 struct rtl_priv *rtlpriv = rtl_priv(hw);
1414 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1415 struct ieee80211_hdr *hdr = (void *)data;
1416 u32 vendor = PEER_UNKNOWN;
1418 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
1419 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
1420 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
1421 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
1422 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
1423 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
1424 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
1425 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
1426 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
1427 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
1428 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
1429 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
1430 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
1431 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
1432 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
1433 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
1435 if (mac->opmode != NL80211_IFTYPE_STATION)
1438 if (mac->link_state == MAC80211_NOLINK) {
1439 mac->vendor = PEER_UNKNOWN;
1443 if (mac->cnt_after_linked > 2)
1446 /* check if this really is a beacon */
1447 if (!ieee80211_is_beacon(hdr->frame_control))
1450 /* min. beacon length + FCS_LEN */
1451 if (len <= 40 + FCS_LEN)
1454 /* and only beacons from the associated BSSID, please */
1455 if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid))
1458 if (rtl_find_221_ie(hw, data, len))
1459 vendor = mac->vendor;
1461 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
1462 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
1463 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
1464 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
1465 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
1466 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
1467 vendor == PEER_ATH) {
1469 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ath find\n"));
1470 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
1471 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
1472 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
1473 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
1474 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
1475 vendor == PEER_RAL) {
1476 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ral findn\n"));
1478 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
1479 vendor == PEER_CISCO) {
1480 vendor = PEER_CISCO;
1481 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>cisco find\n"));
1482 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
1483 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
1484 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
1485 vendor == PEER_BROAD) {
1486 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>broad find\n"));
1487 vendor = PEER_BROAD;
1488 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
1489 vendor == PEER_MARV) {
1491 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>marv find\n"));
1494 mac->vendor = vendor;
1497 /*********************************************************
1501 *********************************************************/
1502 static ssize_t rtl_show_debug_level(struct device *d,
1503 struct device_attribute *attr, char *buf)
1505 struct ieee80211_hw *hw = dev_get_drvdata(d);
1506 struct rtl_priv *rtlpriv = rtl_priv(hw);
1508 return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
1511 static ssize_t rtl_store_debug_level(struct device *d,
1512 struct device_attribute *attr,
1513 const char *buf, size_t count)
1515 struct ieee80211_hw *hw = dev_get_drvdata(d);
1516 struct rtl_priv *rtlpriv = rtl_priv(hw);
1520 ret = strict_strtoul(buf, 0, &val);
1522 printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf);
1524 rtlpriv->dbg.global_debuglevel = val;
1525 printk(KERN_DEBUG "debuglevel:%x\n",
1526 rtlpriv->dbg.global_debuglevel);
1529 return strnlen(buf, count);
1532 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1533 rtl_show_debug_level, rtl_store_debug_level);
1535 static struct attribute *rtl_sysfs_entries[] = {
1537 &dev_attr_debug_level.attr,
1543 * "name" is folder name witch will be
1544 * put in device directory like :
1545 * sys/devices/pci0000:00/0000:00:1c.4/
1546 * 0000:06:00.0/rtl_sysfs
1548 struct attribute_group rtl_attribute_group = {
1550 .attrs = rtl_sysfs_entries,
1553 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
1554 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
1555 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
1556 MODULE_LICENSE("GPL");
1557 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
1559 static int __init rtl_core_module_init(void)
1561 if (rtl_rate_control_register())
1562 pr_err("Unable to register rtl_rc, use default RC !!\n");
1567 static void __exit rtl_core_module_exit(void)
1570 rtl_rate_control_unregister();
1573 module_init(rtl_core_module_init);
1574 module_exit(rtl_core_module_exit);