Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | a8d7606 | 2012-01-07 20:46:42 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 4 | * |
| 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 Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 30 | #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 Finger | d273bb2 | 2012-01-27 13:59:25 -0600 | [diff] [blame] | 38 | #include <linux/ip.h> |
| 39 | #include <linux/module.h> |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 40 | #include <linux/udp.h> |
Larry Finger | d273bb2 | 2012-01-27 13:59:25 -0600 | [diff] [blame] | 41 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 42 | /* |
Tristan Pourcelot | e1fa746 | 2012-02-09 14:48:09 +0100 | [diff] [blame] | 43 | *NOTICE!!!: This file will be very big, we should |
| 44 | *keep it clear under following roles: |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 45 | * |
Tristan Pourcelot | e1fa746 | 2012-02-09 14:48:09 +0100 | [diff] [blame] | 46 | *This file include following parts, so, if you add new |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 47 | *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_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 56 | *6) IOT functions |
| 57 | *7) sysfs functions |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 58 | *8) vif functions |
| 59 | *9) ... |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 60 | */ |
| 61 | |
| 62 | /********************************************************* |
| 63 | * |
| 64 | * mac80211 init functions |
| 65 | * |
| 66 | *********************************************************/ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 67 | static struct ieee80211_channel rtl_channeltable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 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,}, |
| 82 | }; |
| 83 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 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,}, |
| 109 | }; |
| 110 | |
| 111 | static struct ieee80211_rate rtl_ratetable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 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,}, |
| 124 | }; |
| 125 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 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,}, |
| 135 | }; |
| 136 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 137 | static const struct ieee80211_supported_band rtl_band_2ghz = { |
| 138 | .band = IEEE80211_BAND_2GHZ, |
| 139 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 140 | .channels = rtl_channeltable_2g, |
| 141 | .n_channels = ARRAY_SIZE(rtl_channeltable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 142 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 143 | .bitrates = rtl_ratetable_2g, |
| 144 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 145 | |
| 146 | .ht_cap = {0}, |
| 147 | }; |
| 148 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 149 | static 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 | |
| 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 */ |
| 170 | }; |
| 171 | |
Larry Finger | 2a00def | 2012-07-11 14:32:33 -0500 | [diff] [blame] | 172 | u8 rtl_tid_to_ac(u8 tid) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 173 | { |
| 174 | return tid_to_ac[tid]; |
| 175 | } |
| 176 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 177 | static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, |
| 178 | struct ieee80211_sta_ht_cap *ht_cap) |
| 179 | { |
| 180 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 181 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 182 | |
| 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; |
| 188 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 189 | if (rtlpriv->rtlhal.disable_amsdu_8k) |
| 190 | ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; |
| 191 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 192 | /* |
| 193 | *Maximum length of AMPDU that the STA can receive. |
| 194 | *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) |
| 195 | */ |
| 196 | ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 197 | |
| 198 | /*Minimum MPDU start spacing , */ |
| 199 | ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 200 | |
| 201 | ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 202 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 203 | /*hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 204 | *base on ant_num |
| 205 | *rx_mask: RX mask |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 206 | *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7 |
| 207 | *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15 |
| 208 | *if rx_ant >= 3 rx_mask[2]= 0xff; |
| 209 | *if BW_40 rx_mask[4]= 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 210 | *highest supported RX rate |
| 211 | */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 212 | if (rtlpriv->dm.supp_phymode_switch) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 213 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 214 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, |
| 215 | "Support phy mode switch\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 216 | |
| 217 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 218 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 219 | ht_cap->mcs.rx_mask[4] = 0x01; |
| 220 | |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 221 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 222 | } else { |
| 223 | if (get_rf_type(rtlphy) == RF_1T2R || |
| 224 | get_rf_type(rtlphy) == RF_2T2R) { |
| 225 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 226 | "1T2R or 2T2R\n"); |
| 227 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 228 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 229 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 230 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 231 | ht_cap->mcs.rx_highest = |
| 232 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
| 233 | } else if (get_rf_type(rtlphy) == RF_1T1R) { |
| 234 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 235 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 236 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 237 | ht_cap->mcs.rx_mask[1] = 0x00; |
| 238 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 239 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 240 | ht_cap->mcs.rx_highest = |
| 241 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); |
| 242 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | static void _rtl_init_mac80211(struct ieee80211_hw *hw) |
| 247 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 248 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 249 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 250 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 251 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 252 | struct ieee80211_supported_band *sband; |
| 253 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 254 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 255 | if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset == |
| 256 | BAND_ON_BOTH) { |
| 257 | /* 1: 2.4 G bands */ |
| 258 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 259 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 260 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 261 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
| 262 | * to default value(1T1R) */ |
| 263 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz, |
| 264 | sizeof(struct ieee80211_supported_band)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 265 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 266 | /* <3> init ht cap base on ant_num */ |
| 267 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 268 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 269 | /* <4> set mac->sband to wiphy->sband */ |
| 270 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
| 271 | |
| 272 | /* 2: 5 G bands */ |
| 273 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 274 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); |
| 275 | |
| 276 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] |
| 277 | * to default value(1T1R) */ |
| 278 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz, |
| 279 | sizeof(struct ieee80211_supported_band)); |
| 280 | |
| 281 | /* <3> init ht cap base on ant_num */ |
| 282 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 283 | |
| 284 | /* <4> set mac->sband to wiphy->sband */ |
| 285 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; |
| 286 | } else { |
| 287 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
| 288 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 289 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); |
| 290 | |
| 291 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
| 292 | * to default value(1T1R) */ |
| 293 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), |
| 294 | &rtl_band_2ghz, |
| 295 | sizeof(struct ieee80211_supported_band)); |
| 296 | |
| 297 | /* <3> init ht cap base on ant_num */ |
| 298 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 299 | |
| 300 | /* <4> set mac->sband to wiphy->sband */ |
| 301 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
| 302 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 303 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 304 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); |
| 305 | |
| 306 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] |
| 307 | * to default value(1T1R) */ |
| 308 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), |
| 309 | &rtl_band_5ghz, |
| 310 | sizeof(struct ieee80211_supported_band)); |
| 311 | |
| 312 | /* <3> init ht cap base on ant_num */ |
| 313 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 314 | |
| 315 | /* <4> set mac->sband to wiphy->sband */ |
| 316 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; |
| 317 | } else { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 318 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n", |
| 319 | rtlhal->current_bandtype); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 320 | } |
| 321 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 322 | /* <5> set hw caps */ |
| 323 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 324 | IEEE80211_HW_RX_INCLUDES_FCS | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 325 | IEEE80211_HW_AMPDU_AGGREGATION | |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 326 | IEEE80211_HW_CONNECTION_MONITOR | |
| 327 | /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 328 | IEEE80211_HW_CONNECTION_MONITOR | |
| 329 | IEEE80211_HW_MFP_CAPABLE | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 330 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0; |
| 331 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 332 | /* swlps or hwlps has been set in diff chip in init_sw_vars */ |
| 333 | if (rtlpriv->psc.swctrl_lps) |
| 334 | hw->flags |= IEEE80211_HW_SUPPORTS_PS | |
| 335 | IEEE80211_HW_PS_NULLFUNC_STACK | |
| 336 | /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */ |
| 337 | 0; |
| 338 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 339 | hw->wiphy->interface_modes = |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 340 | BIT(NL80211_IFTYPE_AP) | |
| 341 | BIT(NL80211_IFTYPE_STATION) | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 342 | BIT(NL80211_IFTYPE_ADHOC) | |
| 343 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 344 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 345 | BIT(NL80211_IFTYPE_P2P_GO); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 346 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 347 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 348 | hw->wiphy->rts_threshold = 2347; |
| 349 | |
| 350 | hw->queues = AC_MAX; |
| 351 | hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; |
| 352 | |
| 353 | /* TODO: Correct this value for our hw */ |
| 354 | /* TODO: define these hard code value */ |
| 355 | hw->channel_change_time = 100; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 356 | hw->max_listen_interval = 10; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 357 | hw->max_rate_tries = 4; |
| 358 | /* hw->max_rates = 1; */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 359 | hw->sta_data_size = sizeof(struct rtl_sta_info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 360 | |
| 361 | /* <6> mac address */ |
| 362 | if (is_valid_ether_addr(rtlefuse->dev_addr)) { |
| 363 | SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); |
| 364 | } else { |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 365 | u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; |
| 366 | get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1); |
| 367 | SET_IEEE80211_PERM_ADDR(hw, rtlmac1); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | } |
| 371 | |
| 372 | static void _rtl_init_deferred_work(struct ieee80211_hw *hw) |
| 373 | { |
| 374 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 375 | |
| 376 | /* <1> timer */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 377 | setup_timer(&rtlpriv->works.watchdog_timer, |
| 378 | rtl_watch_dog_timer_callback, (unsigned long)hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 379 | setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer, |
| 380 | rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 381 | |
| 382 | /* <2> work queue */ |
| 383 | rtlpriv->works.hw = hw; |
John W. Linville | 3d986b2 | 2010-12-16 14:59:49 -0500 | [diff] [blame] | 384 | rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 385 | INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, |
| 386 | (void *)rtl_watchdog_wq_callback); |
| 387 | INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, |
| 388 | (void *)rtl_ips_nic_off_wq_callback); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 389 | INIT_DELAYED_WORK(&rtlpriv->works.ps_work, |
| 390 | (void *)rtl_swlps_wq_callback); |
| 391 | INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, |
| 392 | (void *)rtl_swlps_rfon_wq_callback); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 393 | INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, |
| 394 | (void *)rtl_fwevt_wq_callback); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 395 | |
| 396 | } |
| 397 | |
| 398 | void rtl_deinit_deferred_work(struct ieee80211_hw *hw) |
| 399 | { |
| 400 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 401 | |
| 402 | del_timer_sync(&rtlpriv->works.watchdog_timer); |
| 403 | |
| 404 | cancel_delayed_work(&rtlpriv->works.watchdog_wq); |
| 405 | cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 406 | cancel_delayed_work(&rtlpriv->works.ps_work); |
| 407 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 408 | cancel_delayed_work(&rtlpriv->works.fwevt_wq); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void rtl_init_rfkill(struct ieee80211_hw *hw) |
| 412 | { |
| 413 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 414 | |
| 415 | bool radio_state; |
| 416 | bool blocked; |
| 417 | u8 valid = 0; |
| 418 | |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 419 | /*set init state to on */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 420 | rtlpriv->rfkill.rfkill_state = true; |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 421 | wiphy_rfkill_set_hw_state(hw->wiphy, 0); |
| 422 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 423 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
| 424 | |
Larry Finger | e6d8a81 | 2010-12-21 19:40:40 -0600 | [diff] [blame] | 425 | if (valid) { |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 426 | pr_info("wireless switch is %s\n", |
| 427 | rtlpriv->rfkill.rfkill_state ? "on" : "off"); |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 428 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 429 | rtlpriv->rfkill.rfkill_state = radio_state; |
| 430 | |
| 431 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; |
| 432 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
| 433 | } |
| 434 | |
| 435 | wiphy_rfkill_start_polling(hw->wiphy); |
| 436 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 437 | EXPORT_SYMBOL(rtl_init_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 438 | |
| 439 | void rtl_deinit_rfkill(struct ieee80211_hw *hw) |
| 440 | { |
| 441 | wiphy_rfkill_stop_polling(hw->wiphy); |
| 442 | } |
| 443 | |
| 444 | int rtl_init_core(struct ieee80211_hw *hw) |
| 445 | { |
| 446 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 447 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 448 | |
| 449 | /* <1> init mac80211 */ |
| 450 | _rtl_init_mac80211(hw); |
| 451 | rtlmac->hw = hw; |
| 452 | |
| 453 | /* <2> rate control register */ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 454 | hw->rate_control_algorithm = "rtl_rc"; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 455 | |
| 456 | /* |
| 457 | * <3> init CRDA must come after init |
| 458 | * mac80211 hw in _rtl_init_mac80211. |
| 459 | */ |
| 460 | if (rtl_regd_init(hw, rtl_reg_notifier)) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 461 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 462 | return 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /* <4> locks */ |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 466 | mutex_init(&rtlpriv->locks.conf_mutex); |
Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 467 | mutex_init(&rtlpriv->locks.ps_mutex); |
Larry Finger | b9116b9a | 2011-12-16 21:17:16 -0600 | [diff] [blame] | 468 | spin_lock_init(&rtlpriv->locks.ips_lock); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 469 | spin_lock_init(&rtlpriv->locks.irq_th_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 470 | spin_lock_init(&rtlpriv->locks.irq_pci_lock); |
| 471 | spin_lock_init(&rtlpriv->locks.tx_lock); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 472 | spin_lock_init(&rtlpriv->locks.h2c_lock); |
| 473 | spin_lock_init(&rtlpriv->locks.rf_ps_lock); |
| 474 | spin_lock_init(&rtlpriv->locks.rf_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 475 | spin_lock_init(&rtlpriv->locks.waitq_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 476 | spin_lock_init(&rtlpriv->locks.entry_list_lock); |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 477 | spin_lock_init(&rtlpriv->locks.fw_ps_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 478 | spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 479 | spin_lock_init(&rtlpriv->locks.check_sendpkt_lock); |
| 480 | spin_lock_init(&rtlpriv->locks.fw_ps_lock); |
| 481 | spin_lock_init(&rtlpriv->locks.lps_lock); |
| 482 | |
| 483 | /* <5> init list */ |
| 484 | INIT_LIST_HEAD(&rtlpriv->entry_list); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 485 | |
| 486 | rtlmac->link_state = MAC80211_NOLINK; |
| 487 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 488 | /* <6> init deferred work */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 489 | _rtl_init_deferred_work(hw); |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | void rtl_deinit_core(struct ieee80211_hw *hw) |
| 495 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | void rtl_init_rx_config(struct ieee80211_hw *hw) |
| 499 | { |
| 500 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 501 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 502 | |
| 503 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /********************************************************* |
| 507 | * |
| 508 | * tx information functions |
| 509 | * |
| 510 | *********************************************************/ |
| 511 | static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, |
| 512 | struct rtl_tcb_desc *tcb_desc, |
| 513 | struct ieee80211_tx_info *info) |
| 514 | { |
| 515 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 516 | u8 rate_flag = info->control.rates[0].flags; |
| 517 | |
| 518 | tcb_desc->use_shortpreamble = false; |
| 519 | |
| 520 | /* 1M can only use Long Preamble. 11B spec */ |
| 521 | if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) |
| 522 | return; |
| 523 | else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 524 | tcb_desc->use_shortpreamble = true; |
| 525 | |
| 526 | return; |
| 527 | } |
| 528 | |
| 529 | static void _rtl_query_shortgi(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 530 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 531 | struct rtl_tcb_desc *tcb_desc, |
| 532 | struct ieee80211_tx_info *info) |
| 533 | { |
| 534 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 535 | u8 rate_flag = info->control.rates[0].flags; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 536 | u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 537 | tcb_desc->use_shortgi = false; |
| 538 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 539 | if (sta == NULL) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 540 | return; |
| 541 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 542 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; |
| 543 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; |
| 544 | |
| 545 | if (!(sta->ht_cap.ht_supported)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 546 | return; |
| 547 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 548 | if (!sgi_40 && !sgi_20) |
| 549 | return; |
| 550 | |
| 551 | if (mac->opmode == NL80211_IFTYPE_STATION) |
| 552 | bw_40 = mac->bw_40; |
| 553 | else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 554 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 555 | mac->opmode == NL80211_IFTYPE_MESH_POINT) |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 556 | bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 557 | |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 558 | if (bw_40 && sgi_40) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 559 | tcb_desc->use_shortgi = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 560 | else if ((bw_40 == false) && sgi_20) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 561 | tcb_desc->use_shortgi = true; |
| 562 | |
| 563 | if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) |
| 564 | tcb_desc->use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void _rtl_query_protection_mode(struct ieee80211_hw *hw, |
| 568 | struct rtl_tcb_desc *tcb_desc, |
| 569 | struct ieee80211_tx_info *info) |
| 570 | { |
| 571 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 572 | u8 rate_flag = info->control.rates[0].flags; |
| 573 | |
| 574 | /* Common Settings */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 575 | tcb_desc->rts_stbc = false; |
| 576 | tcb_desc->cts_enable = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 577 | tcb_desc->rts_sc = 0; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 578 | tcb_desc->rts_bw = false; |
| 579 | tcb_desc->rts_use_shortpreamble = false; |
| 580 | tcb_desc->rts_use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 581 | |
| 582 | if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
| 583 | /* Use CTS-to-SELF in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 584 | tcb_desc->rts_enable = true; |
| 585 | tcb_desc->cts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 586 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 587 | } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 588 | /* Use RTS-CTS in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 589 | tcb_desc->rts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 590 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 591 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 595 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 596 | struct rtl_tcb_desc *tcb_desc) |
| 597 | { |
| 598 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 599 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 600 | struct rtl_sta_info *sta_entry = NULL; |
| 601 | u8 ratr_index = 7; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 602 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 603 | if (sta) { |
| 604 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 605 | ratr_index = sta_entry->ratr_index; |
| 606 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 607 | if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 608 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 609 | tcb_desc->ratr_index = 0; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 610 | } else if (mac->opmode == NL80211_IFTYPE_ADHOC || |
| 611 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 612 | if (tcb_desc->multicast || tcb_desc->broadcast) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 613 | tcb_desc->hw_rate = |
| 614 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; |
| 615 | tcb_desc->use_driver_rate = 1; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 616 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 617 | } else { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 618 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 619 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 620 | } else if (mac->opmode == NL80211_IFTYPE_AP) { |
| 621 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 625 | if (rtlpriv->dm.useramask) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 626 | tcb_desc->ratr_index = ratr_index; |
| 627 | /* TODO we will differentiate adhoc and station future */ |
| 628 | if (mac->opmode == NL80211_IFTYPE_STATION || |
| 629 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 630 | tcb_desc->mac_id = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 631 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 632 | if (mac->mode == WIRELESS_MODE_N_24G) |
| 633 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB; |
| 634 | else if (mac->mode == WIRELESS_MODE_N_5G) |
| 635 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NG; |
| 636 | else if (mac->mode & WIRELESS_MODE_G) |
| 637 | tcb_desc->ratr_index = RATR_INX_WIRELESS_GB; |
| 638 | else if (mac->mode & WIRELESS_MODE_B) |
| 639 | tcb_desc->ratr_index = RATR_INX_WIRELESS_B; |
| 640 | else if (mac->mode & WIRELESS_MODE_A) |
| 641 | tcb_desc->ratr_index = RATR_INX_WIRELESS_G; |
| 642 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 643 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 644 | if (NULL != sta) { |
| 645 | if (sta->aid > 0) |
| 646 | tcb_desc->mac_id = sta->aid + 1; |
| 647 | else |
| 648 | tcb_desc->mac_id = 1; |
| 649 | } else { |
| 650 | tcb_desc->mac_id = 0; |
| 651 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 652 | } |
| 653 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 657 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 658 | struct rtl_tcb_desc *tcb_desc) |
| 659 | { |
| 660 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 661 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 662 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 663 | tcb_desc->packet_bw = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 664 | if (!sta) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 665 | return; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 666 | if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 667 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 668 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 669 | if (sta->bandwidth == IEEE80211_STA_RX_BW_20) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 670 | return; |
| 671 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 672 | if (!mac->bw_40 || !(sta->ht_cap.ht_supported)) |
| 673 | return; |
| 674 | } |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 675 | if (tcb_desc->multicast || tcb_desc->broadcast) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 676 | return; |
| 677 | |
| 678 | /*use legency rate, shall use 20MHz */ |
| 679 | if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) |
| 680 | return; |
| 681 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 682 | tcb_desc->packet_bw = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw) |
| 686 | { |
| 687 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 688 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 689 | u8 hw_rate; |
| 690 | |
| 691 | if (get_rf_type(rtlphy) == RF_2T2R) |
| 692 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; |
| 693 | else |
| 694 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; |
| 695 | |
| 696 | return hw_rate; |
| 697 | } |
| 698 | |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 699 | /* mac80211's rate_idx is like this: |
| 700 | * |
| 701 | * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ |
| 702 | * |
| 703 | * B/G rate: |
| 704 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 705 | * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11, |
| 706 | * |
| 707 | * N rate: |
| 708 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 709 | * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15 |
| 710 | * |
| 711 | * 5G band:rx_status->band == IEEE80211_BAND_5GHZ |
| 712 | * A rate: |
| 713 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 714 | * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7, |
| 715 | * |
| 716 | * N rate: |
| 717 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 718 | * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15 |
| 719 | */ |
| 720 | int rtlwifi_rate_mapping(struct ieee80211_hw *hw, |
| 721 | bool isht, u8 desc_rate, bool first_ampdu) |
| 722 | { |
| 723 | int rate_idx; |
| 724 | |
| 725 | if (false == isht) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 726 | if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) { |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 727 | switch (desc_rate) { |
| 728 | case DESC92_RATE1M: |
| 729 | rate_idx = 0; |
| 730 | break; |
| 731 | case DESC92_RATE2M: |
| 732 | rate_idx = 1; |
| 733 | break; |
| 734 | case DESC92_RATE5_5M: |
| 735 | rate_idx = 2; |
| 736 | break; |
| 737 | case DESC92_RATE11M: |
| 738 | rate_idx = 3; |
| 739 | break; |
| 740 | case DESC92_RATE6M: |
| 741 | rate_idx = 4; |
| 742 | break; |
| 743 | case DESC92_RATE9M: |
| 744 | rate_idx = 5; |
| 745 | break; |
| 746 | case DESC92_RATE12M: |
| 747 | rate_idx = 6; |
| 748 | break; |
| 749 | case DESC92_RATE18M: |
| 750 | rate_idx = 7; |
| 751 | break; |
| 752 | case DESC92_RATE24M: |
| 753 | rate_idx = 8; |
| 754 | break; |
| 755 | case DESC92_RATE36M: |
| 756 | rate_idx = 9; |
| 757 | break; |
| 758 | case DESC92_RATE48M: |
| 759 | rate_idx = 10; |
| 760 | break; |
| 761 | case DESC92_RATE54M: |
| 762 | rate_idx = 11; |
| 763 | break; |
| 764 | default: |
| 765 | rate_idx = 0; |
| 766 | break; |
| 767 | } |
| 768 | } else { |
| 769 | switch (desc_rate) { |
| 770 | case DESC92_RATE6M: |
| 771 | rate_idx = 0; |
| 772 | break; |
| 773 | case DESC92_RATE9M: |
| 774 | rate_idx = 1; |
| 775 | break; |
| 776 | case DESC92_RATE12M: |
| 777 | rate_idx = 2; |
| 778 | break; |
| 779 | case DESC92_RATE18M: |
| 780 | rate_idx = 3; |
| 781 | break; |
| 782 | case DESC92_RATE24M: |
| 783 | rate_idx = 4; |
| 784 | break; |
| 785 | case DESC92_RATE36M: |
| 786 | rate_idx = 5; |
| 787 | break; |
| 788 | case DESC92_RATE48M: |
| 789 | rate_idx = 6; |
| 790 | break; |
| 791 | case DESC92_RATE54M: |
| 792 | rate_idx = 7; |
| 793 | break; |
| 794 | default: |
| 795 | rate_idx = 0; |
| 796 | break; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | } else { |
| 801 | |
| 802 | switch (desc_rate) { |
| 803 | case DESC92_RATEMCS0: |
| 804 | rate_idx = 0; |
| 805 | break; |
| 806 | case DESC92_RATEMCS1: |
| 807 | rate_idx = 1; |
| 808 | break; |
| 809 | case DESC92_RATEMCS2: |
| 810 | rate_idx = 2; |
| 811 | break; |
| 812 | case DESC92_RATEMCS3: |
| 813 | rate_idx = 3; |
| 814 | break; |
| 815 | case DESC92_RATEMCS4: |
| 816 | rate_idx = 4; |
| 817 | break; |
| 818 | case DESC92_RATEMCS5: |
| 819 | rate_idx = 5; |
| 820 | break; |
| 821 | case DESC92_RATEMCS6: |
| 822 | rate_idx = 6; |
| 823 | break; |
| 824 | case DESC92_RATEMCS7: |
| 825 | rate_idx = 7; |
| 826 | break; |
| 827 | case DESC92_RATEMCS8: |
| 828 | rate_idx = 8; |
| 829 | break; |
| 830 | case DESC92_RATEMCS9: |
| 831 | rate_idx = 9; |
| 832 | break; |
| 833 | case DESC92_RATEMCS10: |
| 834 | rate_idx = 10; |
| 835 | break; |
| 836 | case DESC92_RATEMCS11: |
| 837 | rate_idx = 11; |
| 838 | break; |
| 839 | case DESC92_RATEMCS12: |
| 840 | rate_idx = 12; |
| 841 | break; |
| 842 | case DESC92_RATEMCS13: |
| 843 | rate_idx = 13; |
| 844 | break; |
| 845 | case DESC92_RATEMCS14: |
| 846 | rate_idx = 14; |
| 847 | break; |
| 848 | case DESC92_RATEMCS15: |
| 849 | rate_idx = 15; |
| 850 | break; |
| 851 | default: |
| 852 | rate_idx = 0; |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | return rate_idx; |
| 857 | } |
| 858 | EXPORT_SYMBOL(rtlwifi_rate_mapping); |
| 859 | |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 860 | bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 861 | { |
| 862 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 863 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 864 | __le16 fc = rtl_get_fc(skb); |
| 865 | |
| 866 | if (rtlpriv->dm.supp_phymode_switch && |
| 867 | mac->link_state < MAC80211_LINKED && |
| 868 | (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 869 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
| 870 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 871 | } |
| 872 | if (ieee80211_is_auth(fc)) { |
| 873 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n"); |
| 874 | rtl_ips_nic_on(hw); |
| 875 | |
| 876 | mac->link_state = MAC80211_LINKING; |
| 877 | /* Dual mac */ |
| 878 | rtlpriv->phy.need_iqk = true; |
| 879 | } |
| 880 | |
| 881 | return true; |
| 882 | } |
| 883 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 884 | void rtl_get_tcb_desc(struct ieee80211_hw *hw, |
| 885 | struct ieee80211_tx_info *info, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 886 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 887 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) |
| 888 | { |
| 889 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 890 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 891 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 892 | struct ieee80211_rate *txrate; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 893 | __le16 fc = hdr->frame_control; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 894 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 895 | txrate = ieee80211_get_tx_rate(hw, info); |
Larry Finger | e89f769 | 2012-04-06 16:54:17 -0500 | [diff] [blame] | 896 | if (txrate) |
| 897 | tcb_desc->hw_rate = txrate->hw_value; |
| 898 | else |
| 899 | tcb_desc->hw_rate = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 900 | |
| 901 | if (ieee80211_is_data(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 902 | /* |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 903 | *we set data rate INX 0 |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 904 | *in rtl_rc.c if skb is special data or |
| 905 | *mgt which need low data rate. |
| 906 | */ |
| 907 | |
| 908 | /* |
| 909 | *So tcb_desc->hw_rate is just used for |
| 910 | *special data and mgt frames |
| 911 | */ |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 912 | if (info->control.rates[0].idx == 0 || |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 913 | ieee80211_is_nullfunc(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 914 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 915 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 916 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 917 | tcb_desc->disable_ratefallback = 1; |
| 918 | } else { |
| 919 | /* |
| 920 | *because hw will nerver use hw_rate |
| 921 | *when tcb_desc->use_driver_rate = false |
| 922 | *so we never set highest N rate here, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 923 | *and N rate will all be controlled by FW |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 924 | *when tcb_desc->use_driver_rate = false |
| 925 | */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 926 | if (sta && (sta->ht_cap.ht_supported)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 927 | tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw); |
| 928 | } else { |
| 929 | if (rtlmac->mode == WIRELESS_MODE_B) { |
| 930 | tcb_desc->hw_rate = |
| 931 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; |
| 932 | } else { |
| 933 | tcb_desc->hw_rate = |
| 934 | rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 940 | tcb_desc->multicast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 941 | else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 942 | tcb_desc->broadcast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 943 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 944 | _rtl_txrate_selectmode(hw, sta, tcb_desc); |
| 945 | _rtl_query_bandwidth_mode(hw, sta, tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 946 | _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 947 | _rtl_query_shortgi(hw, sta, tcb_desc, info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 948 | _rtl_query_protection_mode(hw, tcb_desc, info); |
| 949 | } else { |
| 950 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 951 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 952 | tcb_desc->disable_ratefallback = 1; |
| 953 | tcb_desc->mac_id = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 954 | tcb_desc->packet_bw = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | EXPORT_SYMBOL(rtl_get_tcb_desc); |
| 958 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 959 | static bool addbareq_rx(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 960 | { |
| 961 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 962 | struct ieee80211_sta *sta = NULL; |
| 963 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
| 964 | struct rtl_sta_info *sta_entry = NULL; |
| 965 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 966 | u16 capab = 0, tid = 0; |
| 967 | struct rtl_tid_data *tid_data; |
| 968 | struct sk_buff *skb_delba = NULL; |
| 969 | struct ieee80211_rx_status rx_status = { 0 }; |
| 970 | |
| 971 | rcu_read_lock(); |
| 972 | sta = rtl_find_sta(hw, hdr->addr3); |
| 973 | if (sta == NULL) { |
| 974 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_EMERG, |
| 975 | "sta is NULL\n"); |
| 976 | rcu_read_unlock(); |
| 977 | return true; |
| 978 | } |
| 979 | |
| 980 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 981 | if (!sta_entry) { |
| 982 | rcu_read_unlock(); |
| 983 | return true; |
| 984 | } |
| 985 | capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 986 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 987 | tid_data = &sta_entry->tids[tid]; |
| 988 | if (tid_data->agg.rx_agg_state == RTL_RX_AGG_START) { |
| 989 | skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid); |
| 990 | if (skb_delba) { |
John W. Linville | 655d8e2 | 2013-04-10 14:09:54 -0400 | [diff] [blame] | 991 | rx_status.freq = hw->conf.chandef.chan->center_freq; |
| 992 | rx_status.band = hw->conf.chandef.chan->band; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 993 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 994 | rx_status.flag |= RX_FLAG_MACTIME_END; |
| 995 | rx_status.rate_idx = 0; |
| 996 | rx_status.signal = 50 + 10; |
| 997 | memcpy(IEEE80211_SKB_RXCB(skb_delba), &rx_status, |
| 998 | sizeof(rx_status)); |
| 999 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1000 | "fake del\n", skb_delba->data, |
| 1001 | skb_delba->len); |
| 1002 | ieee80211_rx_irqsafe(hw, skb_delba); |
| 1003 | } |
| 1004 | } |
| 1005 | rcu_read_unlock(); |
| 1006 | return false; |
| 1007 | } |
| 1008 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1009 | bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 1010 | { |
| 1011 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1012 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1013 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 1014 | __le16 fc = hdr->frame_control; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1015 | u8 *act = (u8 *)skb->data + MAC80211_3ADDR_LEN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1016 | u8 category; |
| 1017 | |
| 1018 | if (!ieee80211_is_action(fc)) |
| 1019 | return true; |
| 1020 | |
| 1021 | category = *act; |
| 1022 | act++; |
| 1023 | switch (category) { |
| 1024 | case ACT_CAT_BA: |
| 1025 | switch (*act) { |
| 1026 | case ACT_ADDBAREQ: |
| 1027 | if (mac->act_scanning) |
| 1028 | return false; |
| 1029 | |
| 1030 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1031 | "%s ACT_ADDBAREQ From :%pM\n", |
| 1032 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1033 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n", |
| 1034 | skb->data, skb->len); |
| 1035 | if (!is_tx) |
| 1036 | if (addbareq_rx(hw, skb)) |
| 1037 | return true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1038 | break; |
| 1039 | case ACT_ADDBARSP: |
| 1040 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1041 | "%s ACT_ADDBARSP From :%pM\n", |
| 1042 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1043 | break; |
| 1044 | case ACT_DELBA: |
| 1045 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1046 | "ACT_ADDBADEL From :%pM\n", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1047 | break; |
| 1048 | } |
| 1049 | break; |
| 1050 | default: |
| 1051 | break; |
| 1052 | } |
| 1053 | |
| 1054 | return true; |
| 1055 | } |
| 1056 | |
| 1057 | /*should call before software enc*/ |
| 1058 | u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 1059 | { |
| 1060 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1061 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1062 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1063 | u16 ether_type; |
| 1064 | u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); |
| 1065 | const struct iphdr *ip; |
| 1066 | |
| 1067 | if (!ieee80211_is_data(fc)) |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1068 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1069 | |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 1070 | ip = (const struct iphdr *)(skb->data + mac_hdr_len + |
| 1071 | SNAP_SIZE + PROTOC_TYPE_SIZE); |
| 1072 | ether_type = be16_to_cpup((__be16 *) |
| 1073 | (skb->data + mac_hdr_len + SNAP_SIZE)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1074 | |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 1075 | switch (ether_type) { |
| 1076 | case ETH_P_IP: { |
| 1077 | struct udphdr *udp; |
| 1078 | u16 src; |
| 1079 | u16 dst; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1080 | |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 1081 | if (ip->protocol != IPPROTO_UDP) |
| 1082 | return false; |
| 1083 | udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2)); |
| 1084 | src = be16_to_cpu(udp->source); |
| 1085 | dst = be16_to_cpu(udp->dest); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1086 | |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 1087 | /* If this case involves port 68 (UDP BOOTP client) connecting |
| 1088 | * with port 67 (UDP BOOTP server), then return true so that |
| 1089 | * the lowest speed is used. |
| 1090 | */ |
| 1091 | if (!((src == 68 && dst == 67) || (src == 67 && dst == 68))) |
| 1092 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1093 | |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 1094 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
| 1095 | "dhcp %s !!\n", is_tx ? "Tx" : "Rx"); |
| 1096 | break; |
| 1097 | } |
| 1098 | case ETH_P_ARP: |
| 1099 | break; |
| 1100 | case ETH_P_PAE: |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1101 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1102 | "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx"); |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 1103 | break; |
| 1104 | case ETH_P_IPV6: |
| 1105 | /* TODO: Is this right? */ |
| 1106 | return false; |
| 1107 | default: |
| 1108 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1109 | } |
Mark Cave-Ayland | dea4a82 | 2013-11-02 14:28:35 -0500 | [diff] [blame^] | 1110 | if (is_tx) { |
| 1111 | rtlpriv->enter_ps = false; |
| 1112 | schedule_work(&rtlpriv->works.lps_change_work); |
| 1113 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
| 1114 | } |
| 1115 | return true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /********************************************************* |
| 1119 | * |
| 1120 | * functions called by core.c |
| 1121 | * |
| 1122 | *********************************************************/ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1123 | int rtl_tx_agg_start(struct ieee80211_hw *hw, |
| 1124 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1125 | { |
| 1126 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1127 | struct rtl_tid_data *tid_data; |
| 1128 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1129 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1130 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1131 | if (sta == NULL) |
| 1132 | return -EINVAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1133 | |
| 1134 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1135 | return -EINVAL; |
| 1136 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1137 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1138 | if (!sta_entry) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1139 | return -ENXIO; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1140 | tid_data = &sta_entry->tids[tid]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1141 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1142 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d seq:%d\n", |
| 1143 | sta->addr, tid, tid_data->seq_number); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1144 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1145 | *ssn = tid_data->seq_number; |
| 1146 | tid_data->agg.agg_state = RTL_AGG_START; |
| 1147 | |
| 1148 | ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1149 | |
| 1150 | return 0; |
| 1151 | } |
| 1152 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1153 | int rtl_tx_agg_stop(struct ieee80211_hw *hw, |
| 1154 | struct ieee80211_sta *sta, u16 tid) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1155 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1156 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1157 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1158 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1159 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1160 | if (sta == NULL) |
| 1161 | return -EINVAL; |
| 1162 | |
| 1163 | if (!sta->addr) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1164 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1165 | return -EINVAL; |
| 1166 | } |
| 1167 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1168 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n", |
| 1169 | sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1170 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1171 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1172 | return -EINVAL; |
| 1173 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1174 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1175 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1176 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1177 | ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1178 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1179 | return 0; |
| 1180 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1181 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1182 | int rtl_rx_agg_start(struct ieee80211_hw *hw, |
| 1183 | struct ieee80211_sta *sta, u16 tid) |
| 1184 | { |
| 1185 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1186 | struct rtl_tid_data *tid_data; |
| 1187 | struct rtl_sta_info *sta_entry = NULL; |
| 1188 | |
| 1189 | if (sta == NULL) |
| 1190 | return -EINVAL; |
| 1191 | |
| 1192 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1193 | return -EINVAL; |
| 1194 | |
| 1195 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1196 | if (!sta_entry) |
| 1197 | return -ENXIO; |
| 1198 | tid_data = &sta_entry->tids[tid]; |
| 1199 | |
| 1200 | RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG, |
| 1201 | "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, |
| 1202 | tid_data->seq_number); |
| 1203 | |
| 1204 | tid_data->agg.rx_agg_state = RTL_RX_AGG_START; |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | int rtl_rx_agg_stop(struct ieee80211_hw *hw, |
| 1209 | struct ieee80211_sta *sta, u16 tid) |
| 1210 | { |
| 1211 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1212 | struct rtl_sta_info *sta_entry = NULL; |
| 1213 | |
| 1214 | if (sta == NULL) |
| 1215 | return -EINVAL; |
| 1216 | |
| 1217 | if (!sta->addr) { |
| 1218 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
| 1219 | return -EINVAL; |
| 1220 | } |
| 1221 | |
| 1222 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1223 | "on ra = %pM tid = %d\n", sta->addr, tid); |
| 1224 | |
| 1225 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1226 | return -EINVAL; |
| 1227 | |
| 1228 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1229 | sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP; |
| 1230 | |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1234 | int rtl_tx_agg_oper(struct ieee80211_hw *hw, |
| 1235 | struct ieee80211_sta *sta, u16 tid) |
| 1236 | { |
| 1237 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1238 | struct rtl_sta_info *sta_entry = NULL; |
| 1239 | |
| 1240 | if (sta == NULL) |
| 1241 | return -EINVAL; |
| 1242 | |
| 1243 | if (!sta->addr) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1244 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1245 | return -EINVAL; |
| 1246 | } |
| 1247 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1248 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n", |
| 1249 | sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1250 | |
| 1251 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1252 | return -EINVAL; |
| 1253 | |
| 1254 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1255 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | /********************************************************* |
| 1261 | * |
| 1262 | * wq & timer callback functions |
| 1263 | * |
| 1264 | *********************************************************/ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1265 | /* this function is used for roaming */ |
| 1266 | void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1267 | { |
| 1268 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1269 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1270 | |
| 1271 | if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION) |
| 1272 | return; |
| 1273 | |
| 1274 | if (rtlpriv->mac80211.link_state < MAC80211_LINKED) |
| 1275 | return; |
| 1276 | |
| 1277 | /* check if this really is a beacon */ |
| 1278 | if (!ieee80211_is_beacon(hdr->frame_control) && |
| 1279 | !ieee80211_is_probe_resp(hdr->frame_control)) |
| 1280 | return; |
| 1281 | |
| 1282 | /* min. beacon length + FCS_LEN */ |
| 1283 | if (skb->len <= 40 + FCS_LEN) |
| 1284 | return; |
| 1285 | |
| 1286 | /* and only beacons from the associated BSSID, please */ |
| 1287 | if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid)) |
| 1288 | return; |
| 1289 | |
| 1290 | rtlpriv->link_info.bcn_rx_inperiod++; |
| 1291 | } |
| 1292 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1293 | void rtl_watchdog_wq_callback(void *data) |
| 1294 | { |
| 1295 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, |
| 1296 | struct rtl_works, |
| 1297 | watchdog_wq); |
| 1298 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1299 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1300 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1301 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1302 | bool busytraffic = false; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1303 | bool tx_busy_traffic = false; |
| 1304 | bool rx_busy_traffic = false; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1305 | bool higher_busytraffic = false; |
| 1306 | bool higher_busyrxtraffic = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1307 | u8 idx, tid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1308 | u32 rx_cnt_inp4eriod = 0; |
| 1309 | u32 tx_cnt_inp4eriod = 0; |
| 1310 | u32 aver_rx_cnt_inperiod = 0; |
| 1311 | u32 aver_tx_cnt_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1312 | u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; |
| 1313 | u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1314 | |
| 1315 | if (is_hal_stop(rtlhal)) |
| 1316 | return; |
| 1317 | |
| 1318 | /* <1> Determine if action frame is allowed */ |
| 1319 | if (mac->link_state > MAC80211_NOLINK) { |
| 1320 | if (mac->cnt_after_linked < 20) |
| 1321 | mac->cnt_after_linked++; |
| 1322 | } else { |
| 1323 | mac->cnt_after_linked = 0; |
| 1324 | } |
| 1325 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1326 | /* |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 1327 | *<2> to check if traffic busy, if |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1328 | * busytraffic we don't change channel |
| 1329 | */ |
| 1330 | if (mac->link_state >= MAC80211_LINKED) { |
| 1331 | |
| 1332 | /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ |
| 1333 | for (idx = 0; idx <= 2; idx++) { |
| 1334 | rtlpriv->link_info.num_rx_in4period[idx] = |
| 1335 | rtlpriv->link_info.num_rx_in4period[idx + 1]; |
| 1336 | rtlpriv->link_info.num_tx_in4period[idx] = |
| 1337 | rtlpriv->link_info.num_tx_in4period[idx + 1]; |
| 1338 | } |
| 1339 | rtlpriv->link_info.num_rx_in4period[3] = |
| 1340 | rtlpriv->link_info.num_rx_inperiod; |
| 1341 | rtlpriv->link_info.num_tx_in4period[3] = |
| 1342 | rtlpriv->link_info.num_tx_inperiod; |
| 1343 | for (idx = 0; idx <= 3; idx++) { |
| 1344 | rx_cnt_inp4eriod += |
| 1345 | rtlpriv->link_info.num_rx_in4period[idx]; |
| 1346 | tx_cnt_inp4eriod += |
| 1347 | rtlpriv->link_info.num_tx_in4period[idx]; |
| 1348 | } |
| 1349 | aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; |
| 1350 | aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; |
| 1351 | |
| 1352 | /* (2) check traffic busy */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1353 | if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1354 | busytraffic = true; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1355 | if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod) |
| 1356 | rx_busy_traffic = true; |
| 1357 | else |
| 1358 | tx_busy_traffic = false; |
| 1359 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1360 | |
| 1361 | /* Higher Tx/Rx data. */ |
| 1362 | if (aver_rx_cnt_inperiod > 4000 || |
| 1363 | aver_tx_cnt_inperiod > 4000) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1364 | higher_busytraffic = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1365 | |
| 1366 | /* Extremely high Rx data. */ |
| 1367 | if (aver_rx_cnt_inperiod > 5000) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1368 | higher_busyrxtraffic = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /* check every tid's tx traffic */ |
| 1372 | for (tid = 0; tid <= 7; tid++) { |
| 1373 | for (idx = 0; idx <= 2; idx++) |
| 1374 | rtlpriv->link_info.tidtx_in4period[tid][idx] = |
| 1375 | rtlpriv->link_info.tidtx_in4period[tid] |
| 1376 | [idx + 1]; |
| 1377 | rtlpriv->link_info.tidtx_in4period[tid][3] = |
| 1378 | rtlpriv->link_info.tidtx_inperiod[tid]; |
| 1379 | |
| 1380 | for (idx = 0; idx <= 3; idx++) |
| 1381 | tidtx_inp4eriod[tid] += |
| 1382 | rtlpriv->link_info.tidtx_in4period[tid][idx]; |
| 1383 | aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; |
| 1384 | if (aver_tidtx_inperiod[tid] > 5000) |
| 1385 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
| 1386 | true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1387 | else |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1388 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
| 1389 | false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | if (((rtlpriv->link_info.num_rx_inperiod + |
| 1393 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 1394 | (rtlpriv->link_info.num_rx_inperiod > 2)) |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1395 | rtlpriv->enter_ps = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1396 | else |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1397 | rtlpriv->enter_ps = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1398 | |
| 1399 | /* LeisurePS only work in infra mode. */ |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1400 | schedule_work(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | rtlpriv->link_info.num_rx_inperiod = 0; |
| 1404 | rtlpriv->link_info.num_tx_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1405 | for (tid = 0; tid <= 7; tid++) |
| 1406 | rtlpriv->link_info.tidtx_inperiod[tid] = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1407 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1408 | rtlpriv->link_info.busytraffic = busytraffic; |
| 1409 | rtlpriv->link_info.higher_busytraffic = higher_busytraffic; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1410 | rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic; |
| 1411 | rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1412 | rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1413 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1414 | /* <3> DM */ |
| 1415 | rtlpriv->cfg->ops->dm_watchdog(hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1416 | |
| 1417 | /* <4> roaming */ |
| 1418 | if (mac->link_state == MAC80211_LINKED && |
| 1419 | mac->opmode == NL80211_IFTYPE_STATION) { |
| 1420 | if ((rtlpriv->link_info.bcn_rx_inperiod + |
| 1421 | rtlpriv->link_info.num_rx_inperiod) == 0) { |
| 1422 | rtlpriv->link_info.roam_times++; |
| 1423 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, |
| 1424 | "AP off for %d s\n", |
| 1425 | (rtlpriv->link_info.roam_times * 2)); |
| 1426 | |
| 1427 | /* if we can't recv beacon for 6s, we should |
| 1428 | * reconnect this AP |
| 1429 | */ |
| 1430 | if (rtlpriv->link_info.roam_times >= 3) { |
| 1431 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1432 | "AP off, try to reconnect now\n"); |
| 1433 | rtlpriv->link_info.roam_times = 0; |
| 1434 | ieee80211_connection_loss(rtlpriv->mac80211.vif); |
| 1435 | } |
| 1436 | } else { |
| 1437 | rtlpriv->link_info.roam_times = 0; |
| 1438 | } |
| 1439 | } |
| 1440 | rtlpriv->link_info.bcn_rx_inperiod = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | void rtl_watch_dog_timer_callback(unsigned long data) |
| 1444 | { |
| 1445 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 1446 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1447 | |
| 1448 | queue_delayed_work(rtlpriv->works.rtl_wq, |
| 1449 | &rtlpriv->works.watchdog_wq, 0); |
| 1450 | |
| 1451 | mod_timer(&rtlpriv->works.watchdog_timer, |
| 1452 | jiffies + MSECS(RTL_WATCH_DOG_TIME)); |
| 1453 | } |
| 1454 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1455 | void rtl_fwevt_wq_callback(void *data) |
| 1456 | { |
| 1457 | struct rtl_works *rtlworks = |
| 1458 | container_of_dwork_rtl(data, struct rtl_works, fwevt_wq); |
| 1459 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1460 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1461 | |
| 1462 | rtlpriv->cfg->ops->c2h_command_handle(hw); |
| 1463 | } |
| 1464 | |
| 1465 | void rtl_easy_concurrent_retrytimer_callback(unsigned long data) |
| 1466 | { |
| 1467 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 1468 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1469 | struct rtl_priv *buddy_priv = rtlpriv->buddy_priv; |
| 1470 | |
| 1471 | if (buddy_priv == NULL) |
| 1472 | return; |
| 1473 | |
| 1474 | rtlpriv->cfg->ops->dualmac_easy_concurrent(hw); |
| 1475 | } |
| 1476 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1477 | /********************************************************* |
| 1478 | * |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1479 | * frame process functions |
| 1480 | * |
| 1481 | *********************************************************/ |
| 1482 | u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) |
| 1483 | { |
| 1484 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 1485 | u8 *pos, *end; |
| 1486 | |
| 1487 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1488 | end = data + len; |
| 1489 | while (pos < end) { |
| 1490 | if (pos + 2 + pos[1] > end) |
| 1491 | return NULL; |
| 1492 | |
| 1493 | if (pos[0] == ie) |
| 1494 | return pos; |
| 1495 | |
| 1496 | pos += 2 + pos[1]; |
| 1497 | } |
| 1498 | return NULL; |
| 1499 | } |
| 1500 | |
| 1501 | /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ |
| 1502 | /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1503 | static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1504 | enum ieee80211_smps_mode smps, u8 *da, u8 *bssid) |
| 1505 | { |
| 1506 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 1507 | struct sk_buff *skb; |
| 1508 | struct ieee80211_mgmt *action_frame; |
| 1509 | |
| 1510 | /* 27 = header + category + action + smps mode */ |
| 1511 | skb = dev_alloc_skb(27 + hw->extra_tx_headroom); |
| 1512 | if (!skb) |
| 1513 | return NULL; |
| 1514 | |
| 1515 | skb_reserve(skb, hw->extra_tx_headroom); |
| 1516 | action_frame = (void *)skb_put(skb, 27); |
| 1517 | memset(action_frame, 0, 27); |
| 1518 | memcpy(action_frame->da, da, ETH_ALEN); |
| 1519 | memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); |
| 1520 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 1521 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1522 | IEEE80211_STYPE_ACTION); |
| 1523 | action_frame->u.action.category = WLAN_CATEGORY_HT; |
| 1524 | action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS; |
| 1525 | switch (smps) { |
| 1526 | case IEEE80211_SMPS_AUTOMATIC:/* 0 */ |
| 1527 | case IEEE80211_SMPS_NUM_MODES:/* 4 */ |
| 1528 | WARN_ON(1); |
| 1529 | case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ |
| 1530 | action_frame->u.action.u.ht_smps.smps_control = |
| 1531 | WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ |
| 1532 | break; |
| 1533 | case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ |
| 1534 | action_frame->u.action.u.ht_smps.smps_control = |
| 1535 | WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ |
| 1536 | break; |
| 1537 | case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ |
| 1538 | action_frame->u.action.u.ht_smps.smps_control = |
| 1539 | WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ |
| 1540 | break; |
| 1541 | } |
| 1542 | |
| 1543 | return skb; |
| 1544 | } |
| 1545 | |
| 1546 | int rtl_send_smps_action(struct ieee80211_hw *hw, |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1547 | struct ieee80211_sta *sta, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1548 | enum ieee80211_smps_mode smps) |
| 1549 | { |
| 1550 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1551 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1552 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1553 | struct sk_buff *skb = NULL; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1554 | struct rtl_tcb_desc tcb_desc; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1555 | u8 bssid[ETH_ALEN] = {0}; |
| 1556 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1557 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
| 1558 | |
| 1559 | if (rtlpriv->mac80211.act_scanning) |
| 1560 | goto err_free; |
| 1561 | |
| 1562 | if (!sta) |
| 1563 | goto err_free; |
| 1564 | |
| 1565 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) |
| 1566 | goto err_free; |
| 1567 | |
| 1568 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 1569 | goto err_free; |
| 1570 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1571 | if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP) |
| 1572 | memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN); |
| 1573 | else |
| 1574 | memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN); |
| 1575 | |
| 1576 | skb = rtl_make_smps_action(hw, smps, sta->addr, bssid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1577 | /* this is a type = mgmt * stype = action frame */ |
| 1578 | if (skb) { |
| 1579 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1580 | struct rtl_sta_info *sta_entry = |
| 1581 | (struct rtl_sta_info *) sta->drv_priv; |
| 1582 | sta_entry->mimo_ps = smps; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1583 | |
| 1584 | info->control.rates[0].idx = 0; |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1585 | info->band = hw->conf.chandef.chan->band; |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1586 | rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1587 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1588 | return 1; |
| 1589 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1590 | err_free: |
| 1591 | return 0; |
| 1592 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1593 | EXPORT_SYMBOL(rtl_send_smps_action); |
| 1594 | |
| 1595 | /* There seem to be issues in mac80211 regarding when del ba frames can be |
| 1596 | * received. As a work around, we make a fake del_ba if we receive a ba_req; |
| 1597 | * however, rx_agg was opened to let mac80211 release some ba related |
| 1598 | * resources. This del_ba is for tx only. |
| 1599 | */ |
| 1600 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, |
| 1601 | u8 *sa, u8 *bssid, u16 tid) |
| 1602 | { |
| 1603 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 1604 | struct sk_buff *skb; |
| 1605 | struct ieee80211_mgmt *action_frame; |
| 1606 | u16 params; |
| 1607 | |
| 1608 | /* 27 = header + category + action + smps mode */ |
| 1609 | skb = dev_alloc_skb(34 + hw->extra_tx_headroom); |
| 1610 | if (!skb) |
| 1611 | return NULL; |
| 1612 | |
| 1613 | skb_reserve(skb, hw->extra_tx_headroom); |
| 1614 | action_frame = (void *)skb_put(skb, 34); |
| 1615 | memset(action_frame, 0, 34); |
| 1616 | memcpy(action_frame->sa, sa, ETH_ALEN); |
| 1617 | memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN); |
| 1618 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 1619 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1620 | IEEE80211_STYPE_ACTION); |
| 1621 | action_frame->u.action.category = WLAN_CATEGORY_BACK; |
| 1622 | action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA; |
| 1623 | params = (u16)(1 << 11); /* bit 11 initiator */ |
| 1624 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
| 1625 | |
| 1626 | action_frame->u.action.u.delba.params = cpu_to_le16(params); |
| 1627 | action_frame->u.action.u.delba.reason_code = |
| 1628 | cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); |
| 1629 | |
| 1630 | return skb; |
| 1631 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1632 | |
| 1633 | /********************************************************* |
| 1634 | * |
| 1635 | * IOT functions |
| 1636 | * |
| 1637 | *********************************************************/ |
| 1638 | static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, |
| 1639 | struct octet_string vendor_ie) |
| 1640 | { |
| 1641 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1642 | bool matched = false; |
| 1643 | static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; |
| 1644 | static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; |
| 1645 | static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; |
| 1646 | static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; |
| 1647 | static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; |
| 1648 | static u8 racap[] = { 0x00, 0x0c, 0x43 }; |
| 1649 | static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; |
| 1650 | static u8 marvcap[] = { 0x00, 0x50, 0x43 }; |
| 1651 | |
| 1652 | if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || |
| 1653 | memcmp(vendor_ie.octet, athcap_2, 3) == 0) { |
| 1654 | rtlpriv->mac80211.vendor = PEER_ATH; |
| 1655 | matched = true; |
| 1656 | } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || |
| 1657 | memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || |
| 1658 | memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { |
| 1659 | rtlpriv->mac80211.vendor = PEER_BROAD; |
| 1660 | matched = true; |
| 1661 | } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { |
| 1662 | rtlpriv->mac80211.vendor = PEER_RAL; |
| 1663 | matched = true; |
| 1664 | } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { |
| 1665 | rtlpriv->mac80211.vendor = PEER_CISCO; |
| 1666 | matched = true; |
| 1667 | } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { |
| 1668 | rtlpriv->mac80211.vendor = PEER_MARV; |
| 1669 | matched = true; |
| 1670 | } |
| 1671 | |
| 1672 | return matched; |
| 1673 | } |
| 1674 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1675 | static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1676 | unsigned int len) |
| 1677 | { |
| 1678 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 1679 | struct octet_string vendor_ie; |
| 1680 | u8 *pos, *end; |
| 1681 | |
| 1682 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1683 | end = data + len; |
| 1684 | while (pos < end) { |
| 1685 | if (pos[0] == 221) { |
| 1686 | vendor_ie.length = pos[1]; |
| 1687 | vendor_ie.octet = &pos[2]; |
| 1688 | if (rtl_chk_vendor_ouisub(hw, vendor_ie)) |
| 1689 | return true; |
| 1690 | } |
| 1691 | |
| 1692 | if (pos + 2 + pos[1] > end) |
| 1693 | return false; |
| 1694 | |
| 1695 | pos += 2 + pos[1]; |
| 1696 | } |
| 1697 | return false; |
| 1698 | } |
| 1699 | |
| 1700 | void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) |
| 1701 | { |
| 1702 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1703 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1704 | struct ieee80211_hdr *hdr = (void *)data; |
| 1705 | u32 vendor = PEER_UNKNOWN; |
| 1706 | |
| 1707 | static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; |
| 1708 | static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; |
| 1709 | static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; |
| 1710 | static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; |
| 1711 | static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; |
| 1712 | static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; |
| 1713 | static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; |
| 1714 | static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; |
| 1715 | static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; |
| 1716 | static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; |
| 1717 | static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; |
| 1718 | static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; |
| 1719 | static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; |
| 1720 | static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; |
| 1721 | static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; |
| 1722 | static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; |
| 1723 | |
| 1724 | if (mac->opmode != NL80211_IFTYPE_STATION) |
| 1725 | return; |
| 1726 | |
| 1727 | if (mac->link_state == MAC80211_NOLINK) { |
| 1728 | mac->vendor = PEER_UNKNOWN; |
| 1729 | return; |
| 1730 | } |
| 1731 | |
| 1732 | if (mac->cnt_after_linked > 2) |
| 1733 | return; |
| 1734 | |
| 1735 | /* check if this really is a beacon */ |
| 1736 | if (!ieee80211_is_beacon(hdr->frame_control)) |
| 1737 | return; |
| 1738 | |
| 1739 | /* min. beacon length + FCS_LEN */ |
| 1740 | if (len <= 40 + FCS_LEN) |
| 1741 | return; |
| 1742 | |
| 1743 | /* and only beacons from the associated BSSID, please */ |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 1744 | if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid)) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1745 | return; |
| 1746 | |
| 1747 | if (rtl_find_221_ie(hw, data, len)) |
| 1748 | vendor = mac->vendor; |
| 1749 | |
| 1750 | if ((memcmp(mac->bssid, ap5_1, 3) == 0) || |
| 1751 | (memcmp(mac->bssid, ap5_2, 3) == 0) || |
| 1752 | (memcmp(mac->bssid, ap5_3, 3) == 0) || |
| 1753 | (memcmp(mac->bssid, ap5_4, 3) == 0) || |
| 1754 | (memcmp(mac->bssid, ap5_5, 3) == 0) || |
| 1755 | (memcmp(mac->bssid, ap5_6, 3) == 0) || |
| 1756 | vendor == PEER_ATH) { |
| 1757 | vendor = PEER_ATH; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1758 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1759 | } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || |
| 1760 | (memcmp(mac->bssid, ap4_5, 3) == 0) || |
| 1761 | (memcmp(mac->bssid, ap4_1, 3) == 0) || |
| 1762 | (memcmp(mac->bssid, ap4_2, 3) == 0) || |
| 1763 | (memcmp(mac->bssid, ap4_3, 3) == 0) || |
| 1764 | vendor == PEER_RAL) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1765 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1766 | vendor = PEER_RAL; |
| 1767 | } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || |
| 1768 | vendor == PEER_CISCO) { |
| 1769 | vendor = PEER_CISCO; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1770 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1771 | } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || |
| 1772 | (memcmp(mac->bssid, ap3_2, 3) == 0) || |
| 1773 | (memcmp(mac->bssid, ap3_3, 3) == 0) || |
| 1774 | vendor == PEER_BROAD) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1775 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1776 | vendor = PEER_BROAD; |
| 1777 | } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || |
| 1778 | vendor == PEER_MARV) { |
| 1779 | vendor = PEER_MARV; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1780 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | mac->vendor = vendor; |
| 1784 | } |
| 1785 | |
| 1786 | /********************************************************* |
| 1787 | * |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1788 | * sysfs functions |
| 1789 | * |
| 1790 | *********************************************************/ |
| 1791 | static ssize_t rtl_show_debug_level(struct device *d, |
| 1792 | struct device_attribute *attr, char *buf) |
| 1793 | { |
| 1794 | struct ieee80211_hw *hw = dev_get_drvdata(d); |
| 1795 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1796 | |
| 1797 | return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel); |
| 1798 | } |
| 1799 | |
| 1800 | static ssize_t rtl_store_debug_level(struct device *d, |
| 1801 | struct device_attribute *attr, |
| 1802 | const char *buf, size_t count) |
| 1803 | { |
| 1804 | struct ieee80211_hw *hw = dev_get_drvdata(d); |
| 1805 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1806 | unsigned long val; |
| 1807 | int ret; |
| 1808 | |
| 1809 | ret = strict_strtoul(buf, 0, &val); |
| 1810 | if (ret) { |
| 1811 | printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf); |
| 1812 | } else { |
| 1813 | rtlpriv->dbg.global_debuglevel = val; |
| 1814 | printk(KERN_DEBUG "debuglevel:%x\n", |
| 1815 | rtlpriv->dbg.global_debuglevel); |
| 1816 | } |
| 1817 | |
| 1818 | return strnlen(buf, count); |
| 1819 | } |
| 1820 | |
| 1821 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1822 | rtl_show_debug_level, rtl_store_debug_level); |
| 1823 | |
| 1824 | static struct attribute *rtl_sysfs_entries[] = { |
| 1825 | |
| 1826 | &dev_attr_debug_level.attr, |
| 1827 | |
| 1828 | NULL |
| 1829 | }; |
| 1830 | |
| 1831 | /* |
| 1832 | * "name" is folder name witch will be |
| 1833 | * put in device directory like : |
| 1834 | * sys/devices/pci0000:00/0000:00:1c.4/ |
| 1835 | * 0000:06:00.0/rtl_sysfs |
| 1836 | */ |
| 1837 | struct attribute_group rtl_attribute_group = { |
| 1838 | .name = "rtlsysfs", |
| 1839 | .attrs = rtl_sysfs_entries, |
| 1840 | }; |
| 1841 | |
| 1842 | MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>"); |
| 1843 | MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>"); |
| 1844 | MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>"); |
| 1845 | MODULE_LICENSE("GPL"); |
| 1846 | MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); |
| 1847 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1848 | struct rtl_global_var global_var = {}; |
| 1849 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1850 | static int __init rtl_core_module_init(void) |
| 1851 | { |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1852 | if (rtl_rate_control_register()) |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 1853 | pr_err("Unable to register rtl_rc, use default RC !!\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1854 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1855 | /* init some global vars */ |
| 1856 | INIT_LIST_HEAD(&global_var.glb_priv_list); |
| 1857 | spin_lock_init(&global_var.glb_list_lock); |
| 1858 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | static void __exit rtl_core_module_exit(void) |
| 1863 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1864 | /*RC*/ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1865 | rtl_rate_control_unregister(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | module_init(rtl_core_module_init); |
| 1869 | module_exit(rtl_core_module_exit); |