blob: ff784072fb4233a29a46a55bf21d75e094bb8d5c [file] [log] [blame]
Larry Finger0c817332010-12-08 11:12:31 -06001/******************************************************************************
2 *
Larry Fingera8d76062012-01-07 20:46:42 -06003 * Copyright(c) 2009-2012 Realtek Corporation.
Larry Finger0c817332010-12-08 11:12:31 -06004 *
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.
8 *
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
12 * more details.
13 *
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
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
28 *****************************************************************************/
29
Larry Finger0c817332010-12-08 11:12:31 -060030#include "wifi.h"
31#include "rc.h"
32#include "base.h"
33#include "efuse.h"
34#include "cam.h"
35#include "ps.h"
36#include "regd.h"
37
Larry Fingerd273bb22012-01-27 13:59:25 -060038#include <linux/ip.h>
39#include <linux/module.h>
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -050040#include <linux/udp.h>
Larry Fingerd273bb22012-01-27 13:59:25 -060041
Larry Finger0c817332010-12-08 11:12:31 -060042/*
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010043 *NOTICE!!!: This file will be very big, we should
44 *keep it clear under following roles:
Larry Finger0c817332010-12-08 11:12:31 -060045 *
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010046 *This file include following parts, so, if you add new
Larry Finger0c817332010-12-08 11:12:31 -060047 *functions into this file, please check which part it
48 *should includes. or check if you should add new part
49 *for this file:
50 *
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
Chaoming_Liacd48572011-04-25 12:52:54 -050056 *6) IOT functions
57 *7) sysfs functions
Larry Finger26634c42013-03-24 22:06:33 -050058 *8) vif functions
59 *9) ...
Larry Finger0c817332010-12-08 11:12:31 -060060 */
61
62/*********************************************************
63 *
64 * mac80211 init functions
65 *
66 *********************************************************/
Chaoming_Liacd48572011-04-25 12:52:54 -050067static struct ieee80211_channel rtl_channeltable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -060068 {.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,},
82};
83
Chaoming_Liacd48572011-04-25 12:52:54 -050084static 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,},
109};
110
111static struct ieee80211_rate rtl_ratetable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -0600112 {.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,},
124};
125
Chaoming_Liacd48572011-04-25 12:52:54 -0500126static 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,},
135};
136
Larry Finger0c817332010-12-08 11:12:31 -0600137static const struct ieee80211_supported_band rtl_band_2ghz = {
138 .band = IEEE80211_BAND_2GHZ,
139
Chaoming_Liacd48572011-04-25 12:52:54 -0500140 .channels = rtl_channeltable_2g,
141 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600142
Chaoming_Liacd48572011-04-25 12:52:54 -0500143 .bitrates = rtl_ratetable_2g,
144 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600145
146 .ht_cap = {0},
147};
148
Chaoming_Liacd48572011-04-25 12:52:54 -0500149static struct ieee80211_supported_band rtl_band_5ghz = {
150 .band = IEEE80211_BAND_5GHZ,
151
152 .channels = rtl_channeltable_5g,
153 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
154
155 .bitrates = rtl_ratetable_5g,
156 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
157
158 .ht_cap = {0},
159};
160
161static 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 */
170};
171
Larry Finger2a00def2012-07-11 14:32:33 -0500172u8 rtl_tid_to_ac(u8 tid)
Chaoming_Liacd48572011-04-25 12:52:54 -0500173{
174 return tid_to_ac[tid];
175}
Larry Finger6f334c22013-07-12 15:32:15 -0500176EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
Chaoming_Liacd48572011-04-25 12:52:54 -0500177
Larry Finger0c817332010-12-08 11:12:31 -0600178static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
179 struct ieee80211_sta_ht_cap *ht_cap)
180{
181 struct rtl_priv *rtlpriv = rtl_priv(hw);
182 struct rtl_phy *rtlphy = &(rtlpriv->phy);
183
184 ht_cap->ht_supported = true;
185 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
186 IEEE80211_HT_CAP_SGI_40 |
187 IEEE80211_HT_CAP_SGI_20 |
188 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
189
Chaoming_Liacd48572011-04-25 12:52:54 -0500190 if (rtlpriv->rtlhal.disable_amsdu_8k)
191 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
192
Larry Finger0c817332010-12-08 11:12:31 -0600193 /*
194 *Maximum length of AMPDU that the STA can receive.
195 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
196 */
197 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
198
199 /*Minimum MPDU start spacing , */
200 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
201
202 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
203
Larry Finger26634c42013-03-24 22:06:33 -0500204 /*hw->wiphy->bands[IEEE80211_BAND_2GHZ]
Larry Finger0c817332010-12-08 11:12:31 -0600205 *base on ant_num
206 *rx_mask: RX mask
Larry Finger26634c42013-03-24 22:06:33 -0500207 *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;
Larry Finger0c817332010-12-08 11:12:31 -0600211 *highest supported RX rate
212 */
Larry Finger26634c42013-03-24 22:06:33 -0500213 if (rtlpriv->dm.supp_phymode_switch) {
Larry Finger0c817332010-12-08 11:12:31 -0600214
Larry Finger26634c42013-03-24 22:06:33 -0500215 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
216 "Support phy mode switch\n");
Larry Finger0c817332010-12-08 11:12:31 -0600217
218 ht_cap->mcs.rx_mask[0] = 0xFF;
219 ht_cap->mcs.rx_mask[1] = 0xFF;
220 ht_cap->mcs.rx_mask[4] = 0x01;
221
Larry Finger17c9ac62011-02-19 16:29:57 -0600222 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
Larry Finger26634c42013-03-24 22:06:33 -0500223 } else {
224 if (get_rf_type(rtlphy) == RF_1T2R ||
225 get_rf_type(rtlphy) == RF_2T2R) {
226 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
227 "1T2R or 2T2R\n");
228 ht_cap->mcs.rx_mask[0] = 0xFF;
229 ht_cap->mcs.rx_mask[1] = 0xFF;
230 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600231
Larry Finger26634c42013-03-24 22:06:33 -0500232 ht_cap->mcs.rx_highest =
233 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
234 } else if (get_rf_type(rtlphy) == RF_1T1R) {
235 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
Larry Finger0c817332010-12-08 11:12:31 -0600236
Larry Finger26634c42013-03-24 22:06:33 -0500237 ht_cap->mcs.rx_mask[0] = 0xFF;
238 ht_cap->mcs.rx_mask[1] = 0x00;
239 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600240
Larry Finger26634c42013-03-24 22:06:33 -0500241 ht_cap->mcs.rx_highest =
242 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
243 }
Larry Finger0c817332010-12-08 11:12:31 -0600244 }
245}
246
247static void _rtl_init_mac80211(struct ieee80211_hw *hw)
248{
Chaoming_Liacd48572011-04-25 12:52:54 -0500249 struct rtl_priv *rtlpriv = rtl_priv(hw);
250 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
Larry Finger0c817332010-12-08 11:12:31 -0600251 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
252 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
253 struct ieee80211_supported_band *sband;
254
Larry Finger0c817332010-12-08 11:12:31 -0600255
Chaoming_Liacd48572011-04-25 12:52:54 -0500256 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset ==
257 BAND_ON_BOTH) {
258 /* 1: 2.4 G bands */
259 /* <1> use mac->bands as mem for hw->wiphy->bands */
260 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
Larry Finger0c817332010-12-08 11:12:31 -0600261
Chaoming_Liacd48572011-04-25 12:52:54 -0500262 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
263 * to default value(1T1R) */
264 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
265 sizeof(struct ieee80211_supported_band));
Larry Finger0c817332010-12-08 11:12:31 -0600266
Chaoming_Liacd48572011-04-25 12:52:54 -0500267 /* <3> init ht cap base on ant_num */
268 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
Larry Finger0c817332010-12-08 11:12:31 -0600269
Chaoming_Liacd48572011-04-25 12:52:54 -0500270 /* <4> set mac->sband to wiphy->sband */
271 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
272
273 /* 2: 5 G bands */
274 /* <1> use mac->bands as mem for hw->wiphy->bands */
275 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
276
277 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
278 * to default value(1T1R) */
279 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
280 sizeof(struct ieee80211_supported_band));
281
282 /* <3> init ht cap base on ant_num */
283 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
284
285 /* <4> set mac->sband to wiphy->sband */
286 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
287 } else {
288 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
289 /* <1> use mac->bands as mem for hw->wiphy->bands */
290 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
291
292 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
293 * to default value(1T1R) */
294 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
295 &rtl_band_2ghz,
296 sizeof(struct ieee80211_supported_band));
297
298 /* <3> init ht cap base on ant_num */
299 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
300
301 /* <4> set mac->sband to wiphy->sband */
302 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
303 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
304 /* <1> use mac->bands as mem for hw->wiphy->bands */
305 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
306
307 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
308 * to default value(1T1R) */
309 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
310 &rtl_band_5ghz,
311 sizeof(struct ieee80211_supported_band));
312
313 /* <3> init ht cap base on ant_num */
314 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
315
316 /* <4> set mac->sband to wiphy->sband */
317 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
318 } else {
Joe Perchesf30d7502012-01-04 19:40:41 -0800319 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n",
320 rtlhal->current_bandtype);
Chaoming_Liacd48572011-04-25 12:52:54 -0500321 }
322 }
Larry Finger0c817332010-12-08 11:12:31 -0600323 /* <5> set hw caps */
324 hw->flags = IEEE80211_HW_SIGNAL_DBM |
325 IEEE80211_HW_RX_INCLUDES_FCS |
Chaoming_Liacd48572011-04-25 12:52:54 -0500326 IEEE80211_HW_AMPDU_AGGREGATION |
Chaoming Li09e92f02011-10-11 21:28:48 -0500327 IEEE80211_HW_CONNECTION_MONITOR |
328 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
Larry Finger26634c42013-03-24 22:06:33 -0500329 IEEE80211_HW_CONNECTION_MONITOR |
330 IEEE80211_HW_MFP_CAPABLE |
Larry Finger0c817332010-12-08 11:12:31 -0600331 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
332
Chaoming_Liacd48572011-04-25 12:52:54 -0500333 /* swlps or hwlps has been set in diff chip in init_sw_vars */
334 if (rtlpriv->psc.swctrl_lps)
335 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
336 IEEE80211_HW_PS_NULLFUNC_STACK |
337 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
338 0;
339
Larry Finger0c817332010-12-08 11:12:31 -0600340 hw->wiphy->interface_modes =
Chaoming_Liacd48572011-04-25 12:52:54 -0500341 BIT(NL80211_IFTYPE_AP) |
342 BIT(NL80211_IFTYPE_STATION) |
Larry Finger26634c42013-03-24 22:06:33 -0500343 BIT(NL80211_IFTYPE_ADHOC) |
344 BIT(NL80211_IFTYPE_MESH_POINT) |
345 BIT(NL80211_IFTYPE_P2P_CLIENT) |
346 BIT(NL80211_IFTYPE_P2P_GO);
Larry Finger0c817332010-12-08 11:12:31 -0600347
Larry Finger26634c42013-03-24 22:06:33 -0500348 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Larry Finger0c817332010-12-08 11:12:31 -0600349 hw->wiphy->rts_threshold = 2347;
350
351 hw->queues = AC_MAX;
352 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
353
354 /* TODO: Correct this value for our hw */
355 /* TODO: define these hard code value */
356 hw->channel_change_time = 100;
Chaoming_Liacd48572011-04-25 12:52:54 -0500357 hw->max_listen_interval = 10;
Larry Finger0c817332010-12-08 11:12:31 -0600358 hw->max_rate_tries = 4;
359 /* hw->max_rates = 1; */
Chaoming_Liacd48572011-04-25 12:52:54 -0500360 hw->sta_data_size = sizeof(struct rtl_sta_info);
Larry Finger0c817332010-12-08 11:12:31 -0600361
362 /* <6> mac address */
363 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
364 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
365 } else {
Larry Fingerabfabc92011-11-17 12:14:44 -0600366 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
367 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
368 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
Larry Finger0c817332010-12-08 11:12:31 -0600369 }
370
371}
372
373static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
374{
375 struct rtl_priv *rtlpriv = rtl_priv(hw);
376
377 /* <1> timer */
Larry Finger0c817332010-12-08 11:12:31 -0600378 setup_timer(&rtlpriv->works.watchdog_timer,
379 rtl_watch_dog_timer_callback, (unsigned long)hw);
Larry Finger26634c42013-03-24 22:06:33 -0500380 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
381 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
Larry Finger0c817332010-12-08 11:12:31 -0600382
383 /* <2> work queue */
384 rtlpriv->works.hw = hw;
Kees Cookd8537542013-07-03 15:04:57 -0700385 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
Larry Finger0c817332010-12-08 11:12:31 -0600386 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
387 (void *)rtl_watchdog_wq_callback);
388 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
389 (void *)rtl_ips_nic_off_wq_callback);
Chaoming_Liacd48572011-04-25 12:52:54 -0500390 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
391 (void *)rtl_swlps_wq_callback);
392 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
393 (void *)rtl_swlps_rfon_wq_callback);
Larry Finger26634c42013-03-24 22:06:33 -0500394 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
395 (void *)rtl_fwevt_wq_callback);
Larry Finger0c817332010-12-08 11:12:31 -0600396
397}
398
399void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
400{
401 struct rtl_priv *rtlpriv = rtl_priv(hw);
402
403 del_timer_sync(&rtlpriv->works.watchdog_timer);
404
405 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
406 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
Chaoming_Liacd48572011-04-25 12:52:54 -0500407 cancel_delayed_work(&rtlpriv->works.ps_work);
408 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
Larry Finger26634c42013-03-24 22:06:33 -0500409 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
Larry Finger0c817332010-12-08 11:12:31 -0600410}
Larry Finger6f334c22013-07-12 15:32:15 -0500411EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
Larry Finger0c817332010-12-08 11:12:31 -0600412
413void rtl_init_rfkill(struct ieee80211_hw *hw)
414{
415 struct rtl_priv *rtlpriv = rtl_priv(hw);
416
417 bool radio_state;
418 bool blocked;
419 u8 valid = 0;
420
Chaoming Li228bdfc2011-04-10 18:30:23 -0500421 /*set init state to on */
Rusty Russell3db1cd52011-12-19 13:56:45 +0000422 rtlpriv->rfkill.rfkill_state = true;
Chaoming Li228bdfc2011-04-10 18:30:23 -0500423 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
424
Larry Finger0c817332010-12-08 11:12:31 -0600425 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
426
Larry Fingere6d8a812010-12-21 19:40:40 -0600427 if (valid) {
Joe Perches292b1192011-07-20 08:51:35 -0700428 pr_info("wireless switch is %s\n",
429 rtlpriv->rfkill.rfkill_state ? "on" : "off");
Chaoming Li228bdfc2011-04-10 18:30:23 -0500430
Larry Finger0c817332010-12-08 11:12:31 -0600431 rtlpriv->rfkill.rfkill_state = radio_state;
432
433 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
434 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
435 }
436
437 wiphy_rfkill_start_polling(hw->wiphy);
438}
Larry Fingerb0302ab2012-01-30 09:54:49 -0600439EXPORT_SYMBOL(rtl_init_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600440
441void rtl_deinit_rfkill(struct ieee80211_hw *hw)
442{
443 wiphy_rfkill_stop_polling(hw->wiphy);
444}
Larry Finger6f334c22013-07-12 15:32:15 -0500445EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600446
447int rtl_init_core(struct ieee80211_hw *hw)
448{
449 struct rtl_priv *rtlpriv = rtl_priv(hw);
450 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
451
452 /* <1> init mac80211 */
453 _rtl_init_mac80211(hw);
454 rtlmac->hw = hw;
455
456 /* <2> rate control register */
Chaoming Li375ff4c2011-02-28 16:40:28 -0600457 hw->rate_control_algorithm = "rtl_rc";
Larry Finger0c817332010-12-08 11:12:31 -0600458
459 /*
460 * <3> init CRDA must come after init
461 * mac80211 hw in _rtl_init_mac80211.
462 */
463 if (rtl_regd_init(hw, rtl_reg_notifier)) {
Joe Perchesf30d7502012-01-04 19:40:41 -0800464 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600465 return 1;
Larry Finger0c817332010-12-08 11:12:31 -0600466 }
467
468 /* <4> locks */
Larry Finger8a09d6d2010-12-16 11:13:57 -0600469 mutex_init(&rtlpriv->locks.conf_mutex);
Stanislaw Gruszka65393062011-12-12 12:43:24 +0100470 mutex_init(&rtlpriv->locks.ps_mutex);
Larry Fingerb9116b9a2011-12-16 21:17:16 -0600471 spin_lock_init(&rtlpriv->locks.ips_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600472 spin_lock_init(&rtlpriv->locks.irq_th_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500473 spin_lock_init(&rtlpriv->locks.irq_pci_lock);
474 spin_lock_init(&rtlpriv->locks.tx_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600475 spin_lock_init(&rtlpriv->locks.h2c_lock);
476 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
477 spin_lock_init(&rtlpriv->locks.rf_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500478 spin_lock_init(&rtlpriv->locks.waitq_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500479 spin_lock_init(&rtlpriv->locks.entry_list_lock);
Larry Fingere6deaf82013-03-24 22:06:55 -0500480 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500481 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500482 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
483 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
484 spin_lock_init(&rtlpriv->locks.lps_lock);
485
486 /* <5> init list */
487 INIT_LIST_HEAD(&rtlpriv->entry_list);
Larry Finger0c817332010-12-08 11:12:31 -0600488
489 rtlmac->link_state = MAC80211_NOLINK;
490
Larry Finger26634c42013-03-24 22:06:33 -0500491 /* <6> init deferred work */
Larry Finger0c817332010-12-08 11:12:31 -0600492 _rtl_init_deferred_work(hw);
493
494 return 0;
495}
Larry Finger6f334c22013-07-12 15:32:15 -0500496EXPORT_SYMBOL_GPL(rtl_init_core);
Larry Finger0c817332010-12-08 11:12:31 -0600497
498void rtl_deinit_core(struct ieee80211_hw *hw)
499{
Larry Finger0c817332010-12-08 11:12:31 -0600500}
Larry Finger6f334c22013-07-12 15:32:15 -0500501EXPORT_SYMBOL_GPL(rtl_deinit_core);
Larry Finger0c817332010-12-08 11:12:31 -0600502
503void rtl_init_rx_config(struct ieee80211_hw *hw)
504{
505 struct rtl_priv *rtlpriv = rtl_priv(hw);
506 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
507
508 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
Larry Finger0c817332010-12-08 11:12:31 -0600509}
Larry Finger6f334c22013-07-12 15:32:15 -0500510EXPORT_SYMBOL_GPL(rtl_init_rx_config);
Larry Finger0c817332010-12-08 11:12:31 -0600511
512/*********************************************************
513 *
514 * tx information functions
515 *
516 *********************************************************/
517static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
518 struct rtl_tcb_desc *tcb_desc,
519 struct ieee80211_tx_info *info)
520{
521 struct rtl_priv *rtlpriv = rtl_priv(hw);
522 u8 rate_flag = info->control.rates[0].flags;
523
524 tcb_desc->use_shortpreamble = false;
525
526 /* 1M can only use Long Preamble. 11B spec */
527 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
528 return;
529 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
530 tcb_desc->use_shortpreamble = true;
531
532 return;
533}
534
535static void _rtl_query_shortgi(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500536 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600537 struct rtl_tcb_desc *tcb_desc,
538 struct ieee80211_tx_info *info)
539{
540 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
541 u8 rate_flag = info->control.rates[0].flags;
Chaoming_Liacd48572011-04-25 12:52:54 -0500542 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600543 tcb_desc->use_shortgi = false;
544
Chaoming_Liacd48572011-04-25 12:52:54 -0500545 if (sta == NULL)
Larry Finger0c817332010-12-08 11:12:31 -0600546 return;
547
Chaoming_Liacd48572011-04-25 12:52:54 -0500548 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
549 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
550
551 if (!(sta->ht_cap.ht_supported))
Larry Finger0c817332010-12-08 11:12:31 -0600552 return;
553
Chaoming_Liacd48572011-04-25 12:52:54 -0500554 if (!sgi_40 && !sgi_20)
555 return;
556
557 if (mac->opmode == NL80211_IFTYPE_STATION)
558 bw_40 = mac->bw_40;
559 else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500560 mac->opmode == NL80211_IFTYPE_ADHOC ||
561 mac->opmode == NL80211_IFTYPE_MESH_POINT)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100562 bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
Chaoming_Liacd48572011-04-25 12:52:54 -0500563
Mike McCormacke10542c2011-06-20 10:47:51 +0900564 if (bw_40 && sgi_40)
Larry Finger0c817332010-12-08 11:12:31 -0600565 tcb_desc->use_shortgi = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500566 else if ((bw_40 == false) && sgi_20)
Larry Finger0c817332010-12-08 11:12:31 -0600567 tcb_desc->use_shortgi = true;
568
569 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
570 tcb_desc->use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600571}
572
573static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
574 struct rtl_tcb_desc *tcb_desc,
575 struct ieee80211_tx_info *info)
576{
577 struct rtl_priv *rtlpriv = rtl_priv(hw);
578 u8 rate_flag = info->control.rates[0].flags;
579
580 /* Common Settings */
Larry Finger7ea47242011-02-19 16:28:57 -0600581 tcb_desc->rts_stbc = false;
582 tcb_desc->cts_enable = false;
Larry Finger0c817332010-12-08 11:12:31 -0600583 tcb_desc->rts_sc = 0;
Larry Finger7ea47242011-02-19 16:28:57 -0600584 tcb_desc->rts_bw = false;
585 tcb_desc->rts_use_shortpreamble = false;
586 tcb_desc->rts_use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600587
588 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
589 /* Use CTS-to-SELF in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600590 tcb_desc->rts_enable = true;
591 tcb_desc->cts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600592 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
593 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
594 /* Use RTS-CTS in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600595 tcb_desc->rts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600596 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
597 }
Larry Finger0c817332010-12-08 11:12:31 -0600598}
599
600static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500601 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600602 struct rtl_tcb_desc *tcb_desc)
603{
604 struct rtl_priv *rtlpriv = rtl_priv(hw);
605 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500606 struct rtl_sta_info *sta_entry = NULL;
607 u8 ratr_index = 7;
Larry Finger0c817332010-12-08 11:12:31 -0600608
Chaoming_Liacd48572011-04-25 12:52:54 -0500609 if (sta) {
610 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
611 ratr_index = sta_entry->ratr_index;
612 }
Larry Finger0c817332010-12-08 11:12:31 -0600613 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500614 if (mac->opmode == NL80211_IFTYPE_STATION) {
Larry Finger0c817332010-12-08 11:12:31 -0600615 tcb_desc->ratr_index = 0;
Larry Finger26634c42013-03-24 22:06:33 -0500616 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
617 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger7ea47242011-02-19 16:28:57 -0600618 if (tcb_desc->multicast || tcb_desc->broadcast) {
Larry Finger0c817332010-12-08 11:12:31 -0600619 tcb_desc->hw_rate =
620 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
621 tcb_desc->use_driver_rate = 1;
Larry Finger26634c42013-03-24 22:06:33 -0500622 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600623 } else {
Larry Finger26634c42013-03-24 22:06:33 -0500624 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600625 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500626 } else if (mac->opmode == NL80211_IFTYPE_AP) {
627 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600628 }
629 }
630
Larry Finger7ea47242011-02-19 16:28:57 -0600631 if (rtlpriv->dm.useramask) {
Larry Finger26634c42013-03-24 22:06:33 -0500632 tcb_desc->ratr_index = ratr_index;
633 /* TODO we will differentiate adhoc and station future */
634 if (mac->opmode == NL80211_IFTYPE_STATION ||
635 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500636 tcb_desc->mac_id = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600637
Chaoming_Liacd48572011-04-25 12:52:54 -0500638 if (mac->mode == WIRELESS_MODE_N_24G)
639 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
640 else if (mac->mode == WIRELESS_MODE_N_5G)
641 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
642 else if (mac->mode & WIRELESS_MODE_G)
643 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
644 else if (mac->mode & WIRELESS_MODE_B)
645 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
646 else if (mac->mode & WIRELESS_MODE_A)
647 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
648 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500649 mac->opmode == NL80211_IFTYPE_ADHOC) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500650 if (NULL != sta) {
651 if (sta->aid > 0)
652 tcb_desc->mac_id = sta->aid + 1;
653 else
654 tcb_desc->mac_id = 1;
655 } else {
656 tcb_desc->mac_id = 0;
657 }
Larry Finger0c817332010-12-08 11:12:31 -0600658 }
659 }
Larry Finger0c817332010-12-08 11:12:31 -0600660}
661
662static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500663 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600664 struct rtl_tcb_desc *tcb_desc)
665{
666 struct rtl_priv *rtlpriv = rtl_priv(hw);
667 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
668
Larry Finger7ea47242011-02-19 16:28:57 -0600669 tcb_desc->packet_bw = false;
Chaoming_Liacd48572011-04-25 12:52:54 -0500670 if (!sta)
Larry Finger0c817332010-12-08 11:12:31 -0600671 return;
Chaoming_Liacd48572011-04-25 12:52:54 -0500672 if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500673 mac->opmode == NL80211_IFTYPE_ADHOC ||
674 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100675 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
Chaoming_Liacd48572011-04-25 12:52:54 -0500676 return;
677 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
678 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
679 return;
680 }
Larry Finger7ea47242011-02-19 16:28:57 -0600681 if (tcb_desc->multicast || tcb_desc->broadcast)
Larry Finger0c817332010-12-08 11:12:31 -0600682 return;
683
684 /*use legency rate, shall use 20MHz */
685 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
686 return;
687
Larry Finger7ea47242011-02-19 16:28:57 -0600688 tcb_desc->packet_bw = true;
Larry Finger0c817332010-12-08 11:12:31 -0600689}
690
691static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw)
692{
693 struct rtl_priv *rtlpriv = rtl_priv(hw);
694 struct rtl_phy *rtlphy = &(rtlpriv->phy);
695 u8 hw_rate;
696
697 if (get_rf_type(rtlphy) == RF_2T2R)
698 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
699 else
700 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
701
702 return hw_rate;
703}
704
Larry Finger7ad0ce32011-08-22 16:50:14 -0500705/* mac80211's rate_idx is like this:
706 *
707 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
708 *
709 * B/G rate:
710 * (rx_status->flag & RX_FLAG_HT) = 0,
711 * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11,
712 *
713 * N rate:
714 * (rx_status->flag & RX_FLAG_HT) = 1,
715 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
716 *
717 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
718 * A rate:
719 * (rx_status->flag & RX_FLAG_HT) = 0,
720 * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7,
721 *
722 * N rate:
723 * (rx_status->flag & RX_FLAG_HT) = 1,
724 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
725 */
726int rtlwifi_rate_mapping(struct ieee80211_hw *hw,
727 bool isht, u8 desc_rate, bool first_ampdu)
728{
729 int rate_idx;
730
731 if (false == isht) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100732 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
Larry Finger7ad0ce32011-08-22 16:50:14 -0500733 switch (desc_rate) {
734 case DESC92_RATE1M:
735 rate_idx = 0;
736 break;
737 case DESC92_RATE2M:
738 rate_idx = 1;
739 break;
740 case DESC92_RATE5_5M:
741 rate_idx = 2;
742 break;
743 case DESC92_RATE11M:
744 rate_idx = 3;
745 break;
746 case DESC92_RATE6M:
747 rate_idx = 4;
748 break;
749 case DESC92_RATE9M:
750 rate_idx = 5;
751 break;
752 case DESC92_RATE12M:
753 rate_idx = 6;
754 break;
755 case DESC92_RATE18M:
756 rate_idx = 7;
757 break;
758 case DESC92_RATE24M:
759 rate_idx = 8;
760 break;
761 case DESC92_RATE36M:
762 rate_idx = 9;
763 break;
764 case DESC92_RATE48M:
765 rate_idx = 10;
766 break;
767 case DESC92_RATE54M:
768 rate_idx = 11;
769 break;
770 default:
771 rate_idx = 0;
772 break;
773 }
774 } else {
775 switch (desc_rate) {
776 case DESC92_RATE6M:
777 rate_idx = 0;
778 break;
779 case DESC92_RATE9M:
780 rate_idx = 1;
781 break;
782 case DESC92_RATE12M:
783 rate_idx = 2;
784 break;
785 case DESC92_RATE18M:
786 rate_idx = 3;
787 break;
788 case DESC92_RATE24M:
789 rate_idx = 4;
790 break;
791 case DESC92_RATE36M:
792 rate_idx = 5;
793 break;
794 case DESC92_RATE48M:
795 rate_idx = 6;
796 break;
797 case DESC92_RATE54M:
798 rate_idx = 7;
799 break;
800 default:
801 rate_idx = 0;
802 break;
803 }
804 }
805
806 } else {
807
808 switch (desc_rate) {
809 case DESC92_RATEMCS0:
810 rate_idx = 0;
811 break;
812 case DESC92_RATEMCS1:
813 rate_idx = 1;
814 break;
815 case DESC92_RATEMCS2:
816 rate_idx = 2;
817 break;
818 case DESC92_RATEMCS3:
819 rate_idx = 3;
820 break;
821 case DESC92_RATEMCS4:
822 rate_idx = 4;
823 break;
824 case DESC92_RATEMCS5:
825 rate_idx = 5;
826 break;
827 case DESC92_RATEMCS6:
828 rate_idx = 6;
829 break;
830 case DESC92_RATEMCS7:
831 rate_idx = 7;
832 break;
833 case DESC92_RATEMCS8:
834 rate_idx = 8;
835 break;
836 case DESC92_RATEMCS9:
837 rate_idx = 9;
838 break;
839 case DESC92_RATEMCS10:
840 rate_idx = 10;
841 break;
842 case DESC92_RATEMCS11:
843 rate_idx = 11;
844 break;
845 case DESC92_RATEMCS12:
846 rate_idx = 12;
847 break;
848 case DESC92_RATEMCS13:
849 rate_idx = 13;
850 break;
851 case DESC92_RATEMCS14:
852 rate_idx = 14;
853 break;
854 case DESC92_RATEMCS15:
855 rate_idx = 15;
856 break;
857 default:
858 rate_idx = 0;
859 break;
860 }
861 }
862 return rate_idx;
863}
864EXPORT_SYMBOL(rtlwifi_rate_mapping);
865
Larry Finger0f015452012-10-25 13:46:46 -0500866bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
867{
868 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
869 struct rtl_priv *rtlpriv = rtl_priv(hw);
870 __le16 fc = rtl_get_fc(skb);
871
872 if (rtlpriv->dm.supp_phymode_switch &&
873 mac->link_state < MAC80211_LINKED &&
874 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
Larry Finger26634c42013-03-24 22:06:33 -0500875 if (rtlpriv->cfg->ops->chk_switch_dmdp)
876 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
Larry Finger0f015452012-10-25 13:46:46 -0500877 }
878 if (ieee80211_is_auth(fc)) {
879 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
880 rtl_ips_nic_on(hw);
881
882 mac->link_state = MAC80211_LINKING;
883 /* Dual mac */
884 rtlpriv->phy.need_iqk = true;
885 }
886
887 return true;
888}
Larry Finger6f334c22013-07-12 15:32:15 -0500889EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
Larry Finger0f015452012-10-25 13:46:46 -0500890
Larry Finger0c817332010-12-08 11:12:31 -0600891void rtl_get_tcb_desc(struct ieee80211_hw *hw,
892 struct ieee80211_tx_info *info,
Chaoming_Liacd48572011-04-25 12:52:54 -0500893 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600894 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
895{
896 struct rtl_priv *rtlpriv = rtl_priv(hw);
897 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500898 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -0600899 struct ieee80211_rate *txrate;
Larry Finger17c9ac62011-02-19 16:29:57 -0600900 __le16 fc = hdr->frame_control;
Larry Finger0c817332010-12-08 11:12:31 -0600901
Chaoming_Liacd48572011-04-25 12:52:54 -0500902 txrate = ieee80211_get_tx_rate(hw, info);
Larry Fingere89f7692012-04-06 16:54:17 -0500903 if (txrate)
904 tcb_desc->hw_rate = txrate->hw_value;
905 else
906 tcb_desc->hw_rate = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600907
908 if (ieee80211_is_data(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -0600909 /*
Chaoming_Liacd48572011-04-25 12:52:54 -0500910 *we set data rate INX 0
Larry Finger0c817332010-12-08 11:12:31 -0600911 *in rtl_rc.c if skb is special data or
912 *mgt which need low data rate.
913 */
914
915 /*
916 *So tcb_desc->hw_rate is just used for
917 *special data and mgt frames
918 */
Chaoming Li09e92f02011-10-11 21:28:48 -0500919 if (info->control.rates[0].idx == 0 ||
Chaoming_Liacd48572011-04-25 12:52:54 -0500920 ieee80211_is_nullfunc(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -0600921 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500922 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600923
Larry Finger0c817332010-12-08 11:12:31 -0600924 tcb_desc->disable_ratefallback = 1;
925 } else {
926 /*
927 *because hw will nerver use hw_rate
928 *when tcb_desc->use_driver_rate = false
929 *so we never set highest N rate here,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300930 *and N rate will all be controlled by FW
Larry Finger0c817332010-12-08 11:12:31 -0600931 *when tcb_desc->use_driver_rate = false
932 */
Chaoming_Liacd48572011-04-25 12:52:54 -0500933 if (sta && (sta->ht_cap.ht_supported)) {
Larry Finger0c817332010-12-08 11:12:31 -0600934 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw);
935 } else {
936 if (rtlmac->mode == WIRELESS_MODE_B) {
937 tcb_desc->hw_rate =
938 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
939 } else {
940 tcb_desc->hw_rate =
941 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
942 }
943 }
944 }
945
946 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -0600947 tcb_desc->multicast = 1;
Larry Finger0c817332010-12-08 11:12:31 -0600948 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -0600949 tcb_desc->broadcast = 1;
Larry Finger0c817332010-12-08 11:12:31 -0600950
Chaoming_Liacd48572011-04-25 12:52:54 -0500951 _rtl_txrate_selectmode(hw, sta, tcb_desc);
952 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
Larry Finger0c817332010-12-08 11:12:31 -0600953 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
Chaoming_Liacd48572011-04-25 12:52:54 -0500954 _rtl_query_shortgi(hw, sta, tcb_desc, info);
Larry Finger0c817332010-12-08 11:12:31 -0600955 _rtl_query_protection_mode(hw, tcb_desc, info);
956 } else {
957 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500958 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600959 tcb_desc->disable_ratefallback = 1;
960 tcb_desc->mac_id = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -0500961 tcb_desc->packet_bw = false;
Larry Finger0c817332010-12-08 11:12:31 -0600962 }
963}
964EXPORT_SYMBOL(rtl_get_tcb_desc);
965
Larry Finger26634c42013-03-24 22:06:33 -0500966static bool addbareq_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
967{
968 struct rtl_priv *rtlpriv = rtl_priv(hw);
969 struct ieee80211_sta *sta = NULL;
970 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
971 struct rtl_sta_info *sta_entry = NULL;
972 struct ieee80211_mgmt *mgmt = (void *)skb->data;
973 u16 capab = 0, tid = 0;
974 struct rtl_tid_data *tid_data;
975 struct sk_buff *skb_delba = NULL;
976 struct ieee80211_rx_status rx_status = { 0 };
977
978 rcu_read_lock();
979 sta = rtl_find_sta(hw, hdr->addr3);
980 if (sta == NULL) {
981 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_EMERG,
982 "sta is NULL\n");
983 rcu_read_unlock();
984 return true;
985 }
986
987 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
988 if (!sta_entry) {
989 rcu_read_unlock();
990 return true;
991 }
992 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
993 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
994 tid_data = &sta_entry->tids[tid];
995 if (tid_data->agg.rx_agg_state == RTL_RX_AGG_START) {
996 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
997 if (skb_delba) {
John W. Linville655d8e22013-04-10 14:09:54 -0400998 rx_status.freq = hw->conf.chandef.chan->center_freq;
999 rx_status.band = hw->conf.chandef.chan->band;
Larry Finger26634c42013-03-24 22:06:33 -05001000 rx_status.flag |= RX_FLAG_DECRYPTED;
1001 rx_status.flag |= RX_FLAG_MACTIME_END;
1002 rx_status.rate_idx = 0;
1003 rx_status.signal = 50 + 10;
1004 memcpy(IEEE80211_SKB_RXCB(skb_delba), &rx_status,
1005 sizeof(rx_status));
1006 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1007 "fake del\n", skb_delba->data,
1008 skb_delba->len);
1009 ieee80211_rx_irqsafe(hw, skb_delba);
1010 }
1011 }
1012 rcu_read_unlock();
1013 return false;
1014}
1015
Larry Finger0c817332010-12-08 11:12:31 -06001016bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1017{
1018 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001019 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001020 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger17c9ac62011-02-19 16:29:57 -06001021 __le16 fc = hdr->frame_control;
Joe Perches2c208892012-06-04 12:44:17 +00001022 u8 *act = (u8 *)skb->data + MAC80211_3ADDR_LEN;
Larry Finger0c817332010-12-08 11:12:31 -06001023 u8 category;
1024
1025 if (!ieee80211_is_action(fc))
1026 return true;
1027
1028 category = *act;
1029 act++;
1030 switch (category) {
1031 case ACT_CAT_BA:
1032 switch (*act) {
1033 case ACT_ADDBAREQ:
1034 if (mac->act_scanning)
1035 return false;
1036
1037 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001038 "%s ACT_ADDBAREQ From :%pM\n",
1039 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger26634c42013-03-24 22:06:33 -05001040 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
1041 skb->data, skb->len);
1042 if (!is_tx)
1043 if (addbareq_rx(hw, skb))
1044 return true;
Larry Finger0c817332010-12-08 11:12:31 -06001045 break;
1046 case ACT_ADDBARSP:
1047 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001048 "%s ACT_ADDBARSP From :%pM\n",
1049 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001050 break;
1051 case ACT_DELBA:
1052 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001053 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001054 break;
1055 }
1056 break;
1057 default:
1058 break;
1059 }
1060
1061 return true;
1062}
Larry Finger6f334c22013-07-12 15:32:15 -05001063EXPORT_SYMBOL_GPL(rtl_action_proc);
Larry Finger0c817332010-12-08 11:12:31 -06001064
1065/*should call before software enc*/
1066u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1067{
1068 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001069 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001070 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001071 u16 ether_type;
1072 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1073 const struct iphdr *ip;
1074
1075 if (!ieee80211_is_data(fc))
Larry Finger32473282011-03-27 16:19:57 -05001076 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001077
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001078 ip = (const struct iphdr *)(skb->data + mac_hdr_len +
1079 SNAP_SIZE + PROTOC_TYPE_SIZE);
1080 ether_type = be16_to_cpup((__be16 *)
1081 (skb->data + mac_hdr_len + SNAP_SIZE));
Larry Finger0c817332010-12-08 11:12:31 -06001082
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001083 switch (ether_type) {
1084 case ETH_P_IP: {
1085 struct udphdr *udp;
1086 u16 src;
1087 u16 dst;
Larry Finger0c817332010-12-08 11:12:31 -06001088
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001089 if (ip->protocol != IPPROTO_UDP)
1090 return false;
1091 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
1092 src = be16_to_cpu(udp->source);
1093 dst = be16_to_cpu(udp->dest);
Larry Finger0c817332010-12-08 11:12:31 -06001094
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001095 /* If this case involves port 68 (UDP BOOTP client) connecting
1096 * with port 67 (UDP BOOTP server), then return true so that
1097 * the lowest speed is used.
1098 */
1099 if (!((src == 68 && dst == 67) || (src == 67 && dst == 68)))
1100 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001101
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001102 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1103 "dhcp %s !!\n", is_tx ? "Tx" : "Rx");
1104 break;
1105 }
1106 case ETH_P_ARP:
1107 break;
1108 case ETH_P_PAE:
Larry Finger0c817332010-12-08 11:12:31 -06001109 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001110 "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx");
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001111 break;
1112 case ETH_P_IPV6:
1113 /* TODO: Is this right? */
1114 return false;
1115 default:
1116 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001117 }
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001118 if (is_tx) {
1119 rtlpriv->enter_ps = false;
1120 schedule_work(&rtlpriv->works.lps_change_work);
1121 ppsc->last_delaylps_stamp_jiffies = jiffies;
1122 }
1123 return true;
Larry Finger0c817332010-12-08 11:12:31 -06001124}
Larry Finger6f334c22013-07-12 15:32:15 -05001125EXPORT_SYMBOL_GPL(rtl_is_special_data);
Larry Finger0c817332010-12-08 11:12:31 -06001126
1127/*********************************************************
1128 *
1129 * functions called by core.c
1130 *
1131 *********************************************************/
Chaoming_Liacd48572011-04-25 12:52:54 -05001132int rtl_tx_agg_start(struct ieee80211_hw *hw,
1133 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Larry Finger0c817332010-12-08 11:12:31 -06001134{
1135 struct rtl_priv *rtlpriv = rtl_priv(hw);
1136 struct rtl_tid_data *tid_data;
1137 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001138 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001139
Chaoming_Liacd48572011-04-25 12:52:54 -05001140 if (sta == NULL)
1141 return -EINVAL;
Larry Finger0c817332010-12-08 11:12:31 -06001142
1143 if (unlikely(tid >= MAX_TID_COUNT))
1144 return -EINVAL;
1145
Chaoming_Liacd48572011-04-25 12:52:54 -05001146 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1147 if (!sta_entry)
Larry Finger0c817332010-12-08 11:12:31 -06001148 return -ENXIO;
Chaoming_Liacd48572011-04-25 12:52:54 -05001149 tid_data = &sta_entry->tids[tid];
Larry Finger0c817332010-12-08 11:12:31 -06001150
Joe Perchesf30d7502012-01-04 19:40:41 -08001151 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d seq:%d\n",
1152 sta->addr, tid, tid_data->seq_number);
Larry Finger0c817332010-12-08 11:12:31 -06001153
Chaoming_Liacd48572011-04-25 12:52:54 -05001154 *ssn = tid_data->seq_number;
1155 tid_data->agg.agg_state = RTL_AGG_START;
1156
1157 ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001158
1159 return 0;
1160}
1161
Chaoming_Liacd48572011-04-25 12:52:54 -05001162int rtl_tx_agg_stop(struct ieee80211_hw *hw,
1163 struct ieee80211_sta *sta, u16 tid)
Larry Finger0c817332010-12-08 11:12:31 -06001164{
Larry Finger0c817332010-12-08 11:12:31 -06001165 struct rtl_priv *rtlpriv = rtl_priv(hw);
1166 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001167 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001168
Chaoming_Liacd48572011-04-25 12:52:54 -05001169 if (sta == NULL)
1170 return -EINVAL;
1171
1172 if (!sta->addr) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001173 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
Larry Finger0c817332010-12-08 11:12:31 -06001174 return -EINVAL;
1175 }
1176
Joe Perchesf30d7502012-01-04 19:40:41 -08001177 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
1178 sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001179
Larry Finger0c817332010-12-08 11:12:31 -06001180 if (unlikely(tid >= MAX_TID_COUNT))
1181 return -EINVAL;
1182
Chaoming_Liacd48572011-04-25 12:52:54 -05001183 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001184 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
Larry Finger0c817332010-12-08 11:12:31 -06001185
Chaoming_Liacd48572011-04-25 12:52:54 -05001186 ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001187
Chaoming_Liacd48572011-04-25 12:52:54 -05001188 return 0;
1189}
Larry Finger0c817332010-12-08 11:12:31 -06001190
Larry Finger26634c42013-03-24 22:06:33 -05001191int rtl_rx_agg_start(struct ieee80211_hw *hw,
1192 struct ieee80211_sta *sta, u16 tid)
1193{
1194 struct rtl_priv *rtlpriv = rtl_priv(hw);
1195 struct rtl_tid_data *tid_data;
1196 struct rtl_sta_info *sta_entry = NULL;
1197
1198 if (sta == NULL)
1199 return -EINVAL;
1200
1201 if (unlikely(tid >= MAX_TID_COUNT))
1202 return -EINVAL;
1203
1204 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1205 if (!sta_entry)
1206 return -ENXIO;
1207 tid_data = &sta_entry->tids[tid];
1208
1209 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1210 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1211 tid_data->seq_number);
1212
1213 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1214 return 0;
1215}
1216
1217int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1218 struct ieee80211_sta *sta, u16 tid)
1219{
1220 struct rtl_priv *rtlpriv = rtl_priv(hw);
1221 struct rtl_sta_info *sta_entry = NULL;
1222
1223 if (sta == NULL)
1224 return -EINVAL;
1225
1226 if (!sta->addr) {
1227 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
1228 return -EINVAL;
1229 }
1230
1231 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1232 "on ra = %pM tid = %d\n", sta->addr, tid);
1233
1234 if (unlikely(tid >= MAX_TID_COUNT))
1235 return -EINVAL;
1236
1237 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1238 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1239
1240 return 0;
1241}
1242
Chaoming_Liacd48572011-04-25 12:52:54 -05001243int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1244 struct ieee80211_sta *sta, u16 tid)
1245{
1246 struct rtl_priv *rtlpriv = rtl_priv(hw);
Chaoming_Liacd48572011-04-25 12:52:54 -05001247 struct rtl_sta_info *sta_entry = NULL;
1248
1249 if (sta == NULL)
1250 return -EINVAL;
1251
1252 if (!sta->addr) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001253 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001254 return -EINVAL;
1255 }
1256
Joe Perchesf30d7502012-01-04 19:40:41 -08001257 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
1258 sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001259
1260 if (unlikely(tid >= MAX_TID_COUNT))
1261 return -EINVAL;
1262
1263 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001264 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
Larry Finger0c817332010-12-08 11:12:31 -06001265
1266 return 0;
1267}
1268
1269/*********************************************************
1270 *
1271 * wq & timer callback functions
1272 *
1273 *********************************************************/
Larry Finger26634c42013-03-24 22:06:33 -05001274/* this function is used for roaming */
1275void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1276{
1277 struct rtl_priv *rtlpriv = rtl_priv(hw);
1278 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1279
1280 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1281 return;
1282
1283 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1284 return;
1285
1286 /* check if this really is a beacon */
1287 if (!ieee80211_is_beacon(hdr->frame_control) &&
1288 !ieee80211_is_probe_resp(hdr->frame_control))
1289 return;
1290
1291 /* min. beacon length + FCS_LEN */
1292 if (skb->len <= 40 + FCS_LEN)
1293 return;
1294
1295 /* and only beacons from the associated BSSID, please */
Joe Perches7367d0b2013-09-01 11:51:23 -07001296 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
Larry Finger26634c42013-03-24 22:06:33 -05001297 return;
1298
1299 rtlpriv->link_info.bcn_rx_inperiod++;
1300}
Larry Finger6f334c22013-07-12 15:32:15 -05001301EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
Larry Finger26634c42013-03-24 22:06:33 -05001302
Larry Finger0c817332010-12-08 11:12:31 -06001303void rtl_watchdog_wq_callback(void *data)
1304{
1305 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1306 struct rtl_works,
1307 watchdog_wq);
1308 struct ieee80211_hw *hw = rtlworks->hw;
1309 struct rtl_priv *rtlpriv = rtl_priv(hw);
1310 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1311 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Larry Finger7ea47242011-02-19 16:28:57 -06001312 bool busytraffic = false;
Larry Finger26634c42013-03-24 22:06:33 -05001313 bool tx_busy_traffic = false;
1314 bool rx_busy_traffic = false;
Larry Finger7ea47242011-02-19 16:28:57 -06001315 bool higher_busytraffic = false;
1316 bool higher_busyrxtraffic = false;
Chaoming_Liacd48572011-04-25 12:52:54 -05001317 u8 idx, tid;
Larry Finger0c817332010-12-08 11:12:31 -06001318 u32 rx_cnt_inp4eriod = 0;
1319 u32 tx_cnt_inp4eriod = 0;
1320 u32 aver_rx_cnt_inperiod = 0;
1321 u32 aver_tx_cnt_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001322 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1323 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
Larry Finger0c817332010-12-08 11:12:31 -06001324
1325 if (is_hal_stop(rtlhal))
1326 return;
1327
1328 /* <1> Determine if action frame is allowed */
1329 if (mac->link_state > MAC80211_NOLINK) {
1330 if (mac->cnt_after_linked < 20)
1331 mac->cnt_after_linked++;
1332 } else {
1333 mac->cnt_after_linked = 0;
1334 }
1335
Larry Finger0c817332010-12-08 11:12:31 -06001336 /*
Chaoming Li09e92f02011-10-11 21:28:48 -05001337 *<2> to check if traffic busy, if
Larry Finger0c817332010-12-08 11:12:31 -06001338 * busytraffic we don't change channel
1339 */
1340 if (mac->link_state >= MAC80211_LINKED) {
1341
1342 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1343 for (idx = 0; idx <= 2; idx++) {
1344 rtlpriv->link_info.num_rx_in4period[idx] =
1345 rtlpriv->link_info.num_rx_in4period[idx + 1];
1346 rtlpriv->link_info.num_tx_in4period[idx] =
1347 rtlpriv->link_info.num_tx_in4period[idx + 1];
1348 }
1349 rtlpriv->link_info.num_rx_in4period[3] =
1350 rtlpriv->link_info.num_rx_inperiod;
1351 rtlpriv->link_info.num_tx_in4period[3] =
1352 rtlpriv->link_info.num_tx_inperiod;
1353 for (idx = 0; idx <= 3; idx++) {
1354 rx_cnt_inp4eriod +=
1355 rtlpriv->link_info.num_rx_in4period[idx];
1356 tx_cnt_inp4eriod +=
1357 rtlpriv->link_info.num_tx_in4period[idx];
1358 }
1359 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1360 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1361
1362 /* (2) check traffic busy */
Larry Finger26634c42013-03-24 22:06:33 -05001363 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
Larry Finger7ea47242011-02-19 16:28:57 -06001364 busytraffic = true;
Larry Finger26634c42013-03-24 22:06:33 -05001365 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1366 rx_busy_traffic = true;
1367 else
1368 tx_busy_traffic = false;
1369 }
Larry Finger0c817332010-12-08 11:12:31 -06001370
1371 /* Higher Tx/Rx data. */
1372 if (aver_rx_cnt_inperiod > 4000 ||
1373 aver_tx_cnt_inperiod > 4000) {
Larry Finger7ea47242011-02-19 16:28:57 -06001374 higher_busytraffic = true;
Larry Finger0c817332010-12-08 11:12:31 -06001375
1376 /* Extremely high Rx data. */
1377 if (aver_rx_cnt_inperiod > 5000)
Larry Finger7ea47242011-02-19 16:28:57 -06001378 higher_busyrxtraffic = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001379 }
1380
1381 /* check every tid's tx traffic */
1382 for (tid = 0; tid <= 7; tid++) {
1383 for (idx = 0; idx <= 2; idx++)
1384 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1385 rtlpriv->link_info.tidtx_in4period[tid]
1386 [idx + 1];
1387 rtlpriv->link_info.tidtx_in4period[tid][3] =
1388 rtlpriv->link_info.tidtx_inperiod[tid];
1389
1390 for (idx = 0; idx <= 3; idx++)
1391 tidtx_inp4eriod[tid] +=
1392 rtlpriv->link_info.tidtx_in4period[tid][idx];
1393 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1394 if (aver_tidtx_inperiod[tid] > 5000)
1395 rtlpriv->link_info.higher_busytxtraffic[tid] =
1396 true;
Larry Finger0c817332010-12-08 11:12:31 -06001397 else
Chaoming_Liacd48572011-04-25 12:52:54 -05001398 rtlpriv->link_info.higher_busytxtraffic[tid] =
1399 false;
Larry Finger0c817332010-12-08 11:12:31 -06001400 }
1401
1402 if (((rtlpriv->link_info.num_rx_inperiod +
1403 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1404 (rtlpriv->link_info.num_rx_inperiod > 2))
Larry Fingera2699132013-03-24 22:06:41 -05001405 rtlpriv->enter_ps = true;
Larry Finger0c817332010-12-08 11:12:31 -06001406 else
Larry Fingera2699132013-03-24 22:06:41 -05001407 rtlpriv->enter_ps = false;
Larry Finger0c817332010-12-08 11:12:31 -06001408
1409 /* LeisurePS only work in infra mode. */
Larry Fingera2699132013-03-24 22:06:41 -05001410 schedule_work(&rtlpriv->works.lps_change_work);
Larry Finger0c817332010-12-08 11:12:31 -06001411 }
1412
1413 rtlpriv->link_info.num_rx_inperiod = 0;
1414 rtlpriv->link_info.num_tx_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001415 for (tid = 0; tid <= 7; tid++)
1416 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001417
Larry Finger7ea47242011-02-19 16:28:57 -06001418 rtlpriv->link_info.busytraffic = busytraffic;
1419 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
Larry Finger26634c42013-03-24 22:06:33 -05001420 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1421 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
Larry Finger7ea47242011-02-19 16:28:57 -06001422 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
Larry Finger0c817332010-12-08 11:12:31 -06001423
Chaoming_Liacd48572011-04-25 12:52:54 -05001424 /* <3> DM */
1425 rtlpriv->cfg->ops->dm_watchdog(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001426
1427 /* <4> roaming */
1428 if (mac->link_state == MAC80211_LINKED &&
1429 mac->opmode == NL80211_IFTYPE_STATION) {
1430 if ((rtlpriv->link_info.bcn_rx_inperiod +
1431 rtlpriv->link_info.num_rx_inperiod) == 0) {
1432 rtlpriv->link_info.roam_times++;
1433 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1434 "AP off for %d s\n",
1435 (rtlpriv->link_info.roam_times * 2));
1436
1437 /* if we can't recv beacon for 6s, we should
1438 * reconnect this AP
1439 */
1440 if (rtlpriv->link_info.roam_times >= 3) {
1441 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1442 "AP off, try to reconnect now\n");
1443 rtlpriv->link_info.roam_times = 0;
1444 ieee80211_connection_loss(rtlpriv->mac80211.vif);
1445 }
1446 } else {
1447 rtlpriv->link_info.roam_times = 0;
1448 }
1449 }
1450 rtlpriv->link_info.bcn_rx_inperiod = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001451}
1452
1453void rtl_watch_dog_timer_callback(unsigned long data)
1454{
1455 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1456 struct rtl_priv *rtlpriv = rtl_priv(hw);
1457
1458 queue_delayed_work(rtlpriv->works.rtl_wq,
1459 &rtlpriv->works.watchdog_wq, 0);
1460
1461 mod_timer(&rtlpriv->works.watchdog_timer,
1462 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1463}
1464
Larry Finger26634c42013-03-24 22:06:33 -05001465void rtl_fwevt_wq_callback(void *data)
1466{
1467 struct rtl_works *rtlworks =
1468 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
1469 struct ieee80211_hw *hw = rtlworks->hw;
1470 struct rtl_priv *rtlpriv = rtl_priv(hw);
1471
1472 rtlpriv->cfg->ops->c2h_command_handle(hw);
1473}
1474
1475void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
1476{
1477 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1478 struct rtl_priv *rtlpriv = rtl_priv(hw);
1479 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
1480
1481 if (buddy_priv == NULL)
1482 return;
1483
1484 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
1485}
1486
Larry Finger0c817332010-12-08 11:12:31 -06001487/*********************************************************
1488 *
Chaoming_Liacd48572011-04-25 12:52:54 -05001489 * frame process functions
1490 *
1491 *********************************************************/
1492u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1493{
1494 struct ieee80211_mgmt *mgmt = (void *)data;
1495 u8 *pos, *end;
1496
1497 pos = (u8 *)mgmt->u.beacon.variable;
1498 end = data + len;
1499 while (pos < end) {
1500 if (pos + 2 + pos[1] > end)
1501 return NULL;
1502
1503 if (pos[0] == ie)
1504 return pos;
1505
1506 pos += 2 + pos[1];
1507 }
1508 return NULL;
1509}
1510
1511/* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1512/* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
Larry Fingerd3bb1422011-04-25 13:23:20 -05001513static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -05001514 enum ieee80211_smps_mode smps, u8 *da, u8 *bssid)
1515{
1516 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1517 struct sk_buff *skb;
1518 struct ieee80211_mgmt *action_frame;
1519
1520 /* 27 = header + category + action + smps mode */
1521 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1522 if (!skb)
1523 return NULL;
1524
1525 skb_reserve(skb, hw->extra_tx_headroom);
1526 action_frame = (void *)skb_put(skb, 27);
1527 memset(action_frame, 0, 27);
1528 memcpy(action_frame->da, da, ETH_ALEN);
1529 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1530 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1531 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1532 IEEE80211_STYPE_ACTION);
1533 action_frame->u.action.category = WLAN_CATEGORY_HT;
1534 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1535 switch (smps) {
1536 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1537 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1538 WARN_ON(1);
1539 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1540 action_frame->u.action.u.ht_smps.smps_control =
1541 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1542 break;
1543 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1544 action_frame->u.action.u.ht_smps.smps_control =
1545 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1546 break;
1547 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1548 action_frame->u.action.u.ht_smps.smps_control =
1549 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1550 break;
1551 }
1552
1553 return skb;
1554}
1555
1556int rtl_send_smps_action(struct ieee80211_hw *hw,
Larry Finger26634c42013-03-24 22:06:33 -05001557 struct ieee80211_sta *sta,
Chaoming_Liacd48572011-04-25 12:52:54 -05001558 enum ieee80211_smps_mode smps)
1559{
1560 struct rtl_priv *rtlpriv = rtl_priv(hw);
1561 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1562 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Larry Finger26634c42013-03-24 22:06:33 -05001563 struct sk_buff *skb = NULL;
Chaoming_Liacd48572011-04-25 12:52:54 -05001564 struct rtl_tcb_desc tcb_desc;
Larry Finger26634c42013-03-24 22:06:33 -05001565 u8 bssid[ETH_ALEN] = {0};
1566
Chaoming_Liacd48572011-04-25 12:52:54 -05001567 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1568
1569 if (rtlpriv->mac80211.act_scanning)
1570 goto err_free;
1571
1572 if (!sta)
1573 goto err_free;
1574
1575 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1576 goto err_free;
1577
1578 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1579 goto err_free;
1580
Larry Finger26634c42013-03-24 22:06:33 -05001581 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
1582 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
1583 else
1584 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
1585
1586 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001587 /* this is a type = mgmt * stype = action frame */
1588 if (skb) {
1589 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1590 struct rtl_sta_info *sta_entry =
1591 (struct rtl_sta_info *) sta->drv_priv;
1592 sta_entry->mimo_ps = smps;
Chaoming_Liacd48572011-04-25 12:52:54 -05001593
1594 info->control.rates[0].idx = 0;
Karl Beldan675a0b02013-03-25 16:26:57 +01001595 info->band = hw->conf.chandef.chan->band;
Thomas Huehn36323f82012-07-23 21:33:42 +02001596 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
Chaoming_Liacd48572011-04-25 12:52:54 -05001597 }
Larry Finger26634c42013-03-24 22:06:33 -05001598 return 1;
1599
Chaoming_Liacd48572011-04-25 12:52:54 -05001600err_free:
1601 return 0;
1602}
Larry Finger26634c42013-03-24 22:06:33 -05001603EXPORT_SYMBOL(rtl_send_smps_action);
1604
Larry Finger4f4826d2013-09-26 13:25:27 -05001605void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
1606{
1607 struct rtl_priv *rtlpriv = rtl_priv(hw);
1608 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1609 enum io_type iotype;
1610
1611 if (!is_hal_stop(rtlhal)) {
1612 switch (operation) {
1613 case SCAN_OPT_BACKUP:
1614 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
1615 rtlpriv->cfg->ops->set_hw_reg(hw,
1616 HW_VAR_IO_CMD,
1617 (u8 *)&iotype);
1618 break;
1619 case SCAN_OPT_RESTORE:
1620 iotype = IO_CMD_RESUME_DM_BY_SCAN;
1621 rtlpriv->cfg->ops->set_hw_reg(hw,
1622 HW_VAR_IO_CMD,
1623 (u8 *)&iotype);
1624 break;
1625 default:
1626 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1627 "Unknown Scan Backup operation.\n");
1628 break;
1629 }
1630 }
1631}
1632EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
1633
Larry Finger26634c42013-03-24 22:06:33 -05001634/* There seem to be issues in mac80211 regarding when del ba frames can be
1635 * received. As a work around, we make a fake del_ba if we receive a ba_req;
1636 * however, rx_agg was opened to let mac80211 release some ba related
1637 * resources. This del_ba is for tx only.
1638 */
1639struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
1640 u8 *sa, u8 *bssid, u16 tid)
1641{
1642 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1643 struct sk_buff *skb;
1644 struct ieee80211_mgmt *action_frame;
1645 u16 params;
1646
1647 /* 27 = header + category + action + smps mode */
1648 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
1649 if (!skb)
1650 return NULL;
1651
1652 skb_reserve(skb, hw->extra_tx_headroom);
1653 action_frame = (void *)skb_put(skb, 34);
1654 memset(action_frame, 0, 34);
1655 memcpy(action_frame->sa, sa, ETH_ALEN);
1656 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
1657 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1658 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1659 IEEE80211_STYPE_ACTION);
1660 action_frame->u.action.category = WLAN_CATEGORY_BACK;
1661 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1662 params = (u16)(1 << 11); /* bit 11 initiator */
1663 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1664
1665 action_frame->u.action.u.delba.params = cpu_to_le16(params);
1666 action_frame->u.action.u.delba.reason_code =
1667 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
1668
1669 return skb;
1670}
Chaoming_Liacd48572011-04-25 12:52:54 -05001671
1672/*********************************************************
1673 *
1674 * IOT functions
1675 *
1676 *********************************************************/
1677static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
1678 struct octet_string vendor_ie)
1679{
1680 struct rtl_priv *rtlpriv = rtl_priv(hw);
1681 bool matched = false;
1682 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1683 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1684 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1685 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1686 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1687 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1688 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1689 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1690
1691 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1692 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1693 rtlpriv->mac80211.vendor = PEER_ATH;
1694 matched = true;
1695 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1696 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1697 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1698 rtlpriv->mac80211.vendor = PEER_BROAD;
1699 matched = true;
1700 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1701 rtlpriv->mac80211.vendor = PEER_RAL;
1702 matched = true;
1703 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1704 rtlpriv->mac80211.vendor = PEER_CISCO;
1705 matched = true;
1706 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1707 rtlpriv->mac80211.vendor = PEER_MARV;
1708 matched = true;
1709 }
1710
1711 return matched;
1712}
1713
Larry Fingerd3bb1422011-04-25 13:23:20 -05001714static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
Chaoming_Liacd48572011-04-25 12:52:54 -05001715 unsigned int len)
1716{
1717 struct ieee80211_mgmt *mgmt = (void *)data;
1718 struct octet_string vendor_ie;
1719 u8 *pos, *end;
1720
1721 pos = (u8 *)mgmt->u.beacon.variable;
1722 end = data + len;
1723 while (pos < end) {
1724 if (pos[0] == 221) {
1725 vendor_ie.length = pos[1];
1726 vendor_ie.octet = &pos[2];
1727 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1728 return true;
1729 }
1730
1731 if (pos + 2 + pos[1] > end)
1732 return false;
1733
1734 pos += 2 + pos[1];
1735 }
1736 return false;
1737}
1738
1739void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
1740{
1741 struct rtl_priv *rtlpriv = rtl_priv(hw);
1742 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1743 struct ieee80211_hdr *hdr = (void *)data;
1744 u32 vendor = PEER_UNKNOWN;
1745
1746 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
1747 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
1748 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
1749 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
1750 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
1751 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
1752 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
1753 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
1754 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
1755 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
1756 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
1757 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
1758 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
1759 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
1760 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
1761 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
1762
1763 if (mac->opmode != NL80211_IFTYPE_STATION)
1764 return;
1765
1766 if (mac->link_state == MAC80211_NOLINK) {
1767 mac->vendor = PEER_UNKNOWN;
1768 return;
1769 }
1770
1771 if (mac->cnt_after_linked > 2)
1772 return;
1773
1774 /* check if this really is a beacon */
1775 if (!ieee80211_is_beacon(hdr->frame_control))
1776 return;
1777
1778 /* min. beacon length + FCS_LEN */
1779 if (len <= 40 + FCS_LEN)
1780 return;
1781
1782 /* and only beacons from the associated BSSID, please */
Joe Perches2e42e472012-05-09 17:17:46 +00001783 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
Chaoming_Liacd48572011-04-25 12:52:54 -05001784 return;
1785
1786 if (rtl_find_221_ie(hw, data, len))
1787 vendor = mac->vendor;
1788
1789 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
1790 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
1791 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
1792 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
1793 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
1794 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
1795 vendor == PEER_ATH) {
1796 vendor = PEER_ATH;
Joe Perchesf30d7502012-01-04 19:40:41 -08001797 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001798 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
1799 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
1800 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
1801 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
1802 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
1803 vendor == PEER_RAL) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001804 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001805 vendor = PEER_RAL;
1806 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
1807 vendor == PEER_CISCO) {
1808 vendor = PEER_CISCO;
Joe Perchesf30d7502012-01-04 19:40:41 -08001809 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001810 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
1811 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
1812 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
1813 vendor == PEER_BROAD) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001814 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001815 vendor = PEER_BROAD;
1816 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
1817 vendor == PEER_MARV) {
1818 vendor = PEER_MARV;
Joe Perchesf30d7502012-01-04 19:40:41 -08001819 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001820 }
1821
1822 mac->vendor = vendor;
1823}
Larry Finger6f334c22013-07-12 15:32:15 -05001824EXPORT_SYMBOL_GPL(rtl_recognize_peer);
Chaoming_Liacd48572011-04-25 12:52:54 -05001825
1826/*********************************************************
1827 *
Larry Finger0c817332010-12-08 11:12:31 -06001828 * sysfs functions
1829 *
1830 *********************************************************/
1831static ssize_t rtl_show_debug_level(struct device *d,
1832 struct device_attribute *attr, char *buf)
1833{
1834 struct ieee80211_hw *hw = dev_get_drvdata(d);
1835 struct rtl_priv *rtlpriv = rtl_priv(hw);
1836
1837 return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
1838}
1839
1840static ssize_t rtl_store_debug_level(struct device *d,
1841 struct device_attribute *attr,
1842 const char *buf, size_t count)
1843{
1844 struct ieee80211_hw *hw = dev_get_drvdata(d);
1845 struct rtl_priv *rtlpriv = rtl_priv(hw);
1846 unsigned long val;
1847 int ret;
1848
Jingoo Han27d7f472013-05-31 21:24:06 +00001849 ret = kstrtoul(buf, 0, &val);
Larry Finger0c817332010-12-08 11:12:31 -06001850 if (ret) {
1851 printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf);
1852 } else {
1853 rtlpriv->dbg.global_debuglevel = val;
1854 printk(KERN_DEBUG "debuglevel:%x\n",
1855 rtlpriv->dbg.global_debuglevel);
1856 }
1857
1858 return strnlen(buf, count);
1859}
1860
1861static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1862 rtl_show_debug_level, rtl_store_debug_level);
1863
1864static struct attribute *rtl_sysfs_entries[] = {
1865
1866 &dev_attr_debug_level.attr,
1867
1868 NULL
1869};
1870
1871/*
1872 * "name" is folder name witch will be
1873 * put in device directory like :
1874 * sys/devices/pci0000:00/0000:00:1c.4/
1875 * 0000:06:00.0/rtl_sysfs
1876 */
1877struct attribute_group rtl_attribute_group = {
1878 .name = "rtlsysfs",
1879 .attrs = rtl_sysfs_entries,
1880};
Larry Finger6f334c22013-07-12 15:32:15 -05001881EXPORT_SYMBOL_GPL(rtl_attribute_group);
Larry Finger0c817332010-12-08 11:12:31 -06001882
1883MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
1884MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
1885MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
1886MODULE_LICENSE("GPL");
1887MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
1888
Larry Finger6f334c22013-07-12 15:32:15 -05001889struct rtl_global_var rtl_global_var = {};
1890EXPORT_SYMBOL_GPL(rtl_global_var);
Larry Finger26634c42013-03-24 22:06:33 -05001891
Larry Finger0c817332010-12-08 11:12:31 -06001892static int __init rtl_core_module_init(void)
1893{
Chaoming Li375ff4c2011-02-28 16:40:28 -06001894 if (rtl_rate_control_register())
Joe Perches292b1192011-07-20 08:51:35 -07001895 pr_err("Unable to register rtl_rc, use default RC !!\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001896
Larry Finger26634c42013-03-24 22:06:33 -05001897 /* init some global vars */
Larry Finger6f334c22013-07-12 15:32:15 -05001898 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
1899 spin_lock_init(&rtl_global_var.glb_list_lock);
Larry Finger26634c42013-03-24 22:06:33 -05001900
Larry Finger0c817332010-12-08 11:12:31 -06001901 return 0;
1902}
1903
1904static void __exit rtl_core_module_exit(void)
1905{
Chaoming_Liacd48572011-04-25 12:52:54 -05001906 /*RC*/
Chaoming Li375ff4c2011-02-28 16:40:28 -06001907 rtl_rate_control_unregister();
Larry Finger0c817332010-12-08 11:12:31 -06001908}
1909
1910module_init(rtl_core_module_init);
1911module_exit(rtl_core_module_exit);