| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
|  | 3 | * Copyright(c) 2009-2010  Realtek Corporation. | 
|  | 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 |  | 
|  | 30 | #include <linux/ip.h> | 
|  | 31 | #include "wifi.h" | 
|  | 32 | #include "rc.h" | 
|  | 33 | #include "base.h" | 
|  | 34 | #include "efuse.h" | 
|  | 35 | #include "cam.h" | 
|  | 36 | #include "ps.h" | 
|  | 37 | #include "regd.h" | 
|  | 38 |  | 
|  | 39 | /* | 
|  | 40 | *NOTICE!!!: This file will be very big, we hsould | 
|  | 41 | *keep it clear under follwing roles: | 
|  | 42 | * | 
|  | 43 | *This file include follwing part, so, if you add new | 
|  | 44 | *functions into this file, please check which part it | 
|  | 45 | *should includes. or check if you should add new part | 
|  | 46 | *for this file: | 
|  | 47 | * | 
|  | 48 | *1) mac80211 init functions | 
|  | 49 | *2) tx information functions | 
|  | 50 | *3) functions called by core.c | 
|  | 51 | *4) wq & timer callback functions | 
|  | 52 | *5) frame process functions | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 53 | *6) IOT functions | 
|  | 54 | *7) sysfs functions | 
|  | 55 | *8) ... | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 56 | */ | 
|  | 57 |  | 
|  | 58 | /********************************************************* | 
|  | 59 | * | 
|  | 60 | * mac80211 init functions | 
|  | 61 | * | 
|  | 62 | *********************************************************/ | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 63 | static struct ieee80211_channel rtl_channeltable_2g[] = { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 64 | {.center_freq = 2412, .hw_value = 1,}, | 
|  | 65 | {.center_freq = 2417, .hw_value = 2,}, | 
|  | 66 | {.center_freq = 2422, .hw_value = 3,}, | 
|  | 67 | {.center_freq = 2427, .hw_value = 4,}, | 
|  | 68 | {.center_freq = 2432, .hw_value = 5,}, | 
|  | 69 | {.center_freq = 2437, .hw_value = 6,}, | 
|  | 70 | {.center_freq = 2442, .hw_value = 7,}, | 
|  | 71 | {.center_freq = 2447, .hw_value = 8,}, | 
|  | 72 | {.center_freq = 2452, .hw_value = 9,}, | 
|  | 73 | {.center_freq = 2457, .hw_value = 10,}, | 
|  | 74 | {.center_freq = 2462, .hw_value = 11,}, | 
|  | 75 | {.center_freq = 2467, .hw_value = 12,}, | 
|  | 76 | {.center_freq = 2472, .hw_value = 13,}, | 
|  | 77 | {.center_freq = 2484, .hw_value = 14,}, | 
|  | 78 | }; | 
|  | 79 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 80 | static struct ieee80211_channel rtl_channeltable_5g[] = { | 
|  | 81 | {.center_freq = 5180, .hw_value = 36,}, | 
|  | 82 | {.center_freq = 5200, .hw_value = 40,}, | 
|  | 83 | {.center_freq = 5220, .hw_value = 44,}, | 
|  | 84 | {.center_freq = 5240, .hw_value = 48,}, | 
|  | 85 | {.center_freq = 5260, .hw_value = 52,}, | 
|  | 86 | {.center_freq = 5280, .hw_value = 56,}, | 
|  | 87 | {.center_freq = 5300, .hw_value = 60,}, | 
|  | 88 | {.center_freq = 5320, .hw_value = 64,}, | 
|  | 89 | {.center_freq = 5500, .hw_value = 100,}, | 
|  | 90 | {.center_freq = 5520, .hw_value = 104,}, | 
|  | 91 | {.center_freq = 5540, .hw_value = 108,}, | 
|  | 92 | {.center_freq = 5560, .hw_value = 112,}, | 
|  | 93 | {.center_freq = 5580, .hw_value = 116,}, | 
|  | 94 | {.center_freq = 5600, .hw_value = 120,}, | 
|  | 95 | {.center_freq = 5620, .hw_value = 124,}, | 
|  | 96 | {.center_freq = 5640, .hw_value = 128,}, | 
|  | 97 | {.center_freq = 5660, .hw_value = 132,}, | 
|  | 98 | {.center_freq = 5680, .hw_value = 136,}, | 
|  | 99 | {.center_freq = 5700, .hw_value = 140,}, | 
|  | 100 | {.center_freq = 5745, .hw_value = 149,}, | 
|  | 101 | {.center_freq = 5765, .hw_value = 153,}, | 
|  | 102 | {.center_freq = 5785, .hw_value = 157,}, | 
|  | 103 | {.center_freq = 5805, .hw_value = 161,}, | 
|  | 104 | {.center_freq = 5825, .hw_value = 165,}, | 
|  | 105 | }; | 
|  | 106 |  | 
|  | 107 | static struct ieee80211_rate rtl_ratetable_2g[] = { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 108 | {.bitrate = 10, .hw_value = 0x00,}, | 
|  | 109 | {.bitrate = 20, .hw_value = 0x01,}, | 
|  | 110 | {.bitrate = 55, .hw_value = 0x02,}, | 
|  | 111 | {.bitrate = 110, .hw_value = 0x03,}, | 
|  | 112 | {.bitrate = 60, .hw_value = 0x04,}, | 
|  | 113 | {.bitrate = 90, .hw_value = 0x05,}, | 
|  | 114 | {.bitrate = 120, .hw_value = 0x06,}, | 
|  | 115 | {.bitrate = 180, .hw_value = 0x07,}, | 
|  | 116 | {.bitrate = 240, .hw_value = 0x08,}, | 
|  | 117 | {.bitrate = 360, .hw_value = 0x09,}, | 
|  | 118 | {.bitrate = 480, .hw_value = 0x0a,}, | 
|  | 119 | {.bitrate = 540, .hw_value = 0x0b,}, | 
|  | 120 | }; | 
|  | 121 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 122 | static struct ieee80211_rate rtl_ratetable_5g[] = { | 
|  | 123 | {.bitrate = 60, .hw_value = 0x04,}, | 
|  | 124 | {.bitrate = 90, .hw_value = 0x05,}, | 
|  | 125 | {.bitrate = 120, .hw_value = 0x06,}, | 
|  | 126 | {.bitrate = 180, .hw_value = 0x07,}, | 
|  | 127 | {.bitrate = 240, .hw_value = 0x08,}, | 
|  | 128 | {.bitrate = 360, .hw_value = 0x09,}, | 
|  | 129 | {.bitrate = 480, .hw_value = 0x0a,}, | 
|  | 130 | {.bitrate = 540, .hw_value = 0x0b,}, | 
|  | 131 | }; | 
|  | 132 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 133 | static const struct ieee80211_supported_band rtl_band_2ghz = { | 
|  | 134 | .band = IEEE80211_BAND_2GHZ, | 
|  | 135 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 136 | .channels = rtl_channeltable_2g, | 
|  | 137 | .n_channels = ARRAY_SIZE(rtl_channeltable_2g), | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 138 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 139 | .bitrates = rtl_ratetable_2g, | 
|  | 140 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g), | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 141 |  | 
|  | 142 | .ht_cap = {0}, | 
|  | 143 | }; | 
|  | 144 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 145 | static struct ieee80211_supported_band rtl_band_5ghz = { | 
|  | 146 | .band = IEEE80211_BAND_5GHZ, | 
|  | 147 |  | 
|  | 148 | .channels = rtl_channeltable_5g, | 
|  | 149 | .n_channels = ARRAY_SIZE(rtl_channeltable_5g), | 
|  | 150 |  | 
|  | 151 | .bitrates = rtl_ratetable_5g, | 
|  | 152 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g), | 
|  | 153 |  | 
|  | 154 | .ht_cap = {0}, | 
|  | 155 | }; | 
|  | 156 |  | 
|  | 157 | static const u8 tid_to_ac[] = { | 
|  | 158 | 2, /* IEEE80211_AC_BE */ | 
|  | 159 | 3, /* IEEE80211_AC_BK */ | 
|  | 160 | 3, /* IEEE80211_AC_BK */ | 
|  | 161 | 2, /* IEEE80211_AC_BE */ | 
|  | 162 | 1, /* IEEE80211_AC_VI */ | 
|  | 163 | 1, /* IEEE80211_AC_VI */ | 
|  | 164 | 0, /* IEEE80211_AC_VO */ | 
|  | 165 | 0, /* IEEE80211_AC_VO */ | 
|  | 166 | }; | 
|  | 167 |  | 
|  | 168 | u8 rtl_tid_to_ac(struct ieee80211_hw *hw, u8 tid) | 
|  | 169 | { | 
|  | 170 | return tid_to_ac[tid]; | 
|  | 171 | } | 
|  | 172 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 173 | static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, | 
|  | 174 | struct ieee80211_sta_ht_cap *ht_cap) | 
|  | 175 | { | 
|  | 176 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 177 | struct rtl_phy *rtlphy = &(rtlpriv->phy); | 
|  | 178 |  | 
|  | 179 | ht_cap->ht_supported = true; | 
|  | 180 | ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | | 
|  | 181 | IEEE80211_HT_CAP_SGI_40 | | 
|  | 182 | IEEE80211_HT_CAP_SGI_20 | | 
|  | 183 | IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; | 
|  | 184 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 185 | if (rtlpriv->rtlhal.disable_amsdu_8k) | 
|  | 186 | ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; | 
|  | 187 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 188 | /* | 
|  | 189 | *Maximum length of AMPDU that the STA can receive. | 
|  | 190 | *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) | 
|  | 191 | */ | 
|  | 192 | ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | 
|  | 193 |  | 
|  | 194 | /*Minimum MPDU start spacing , */ | 
|  | 195 | ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; | 
|  | 196 |  | 
|  | 197 | ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | 
|  | 198 |  | 
|  | 199 | /* | 
|  | 200 | *hw->wiphy->bands[IEEE80211_BAND_2GHZ] | 
|  | 201 | *base on ant_num | 
|  | 202 | *rx_mask: RX mask | 
|  | 203 | *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7 | 
|  | 204 | *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15 | 
|  | 205 | *if rx_ant >=3 rx_mask[2]=0xff; | 
|  | 206 | *if BW_40 rx_mask[4]=0x01; | 
|  | 207 | *highest supported RX rate | 
|  | 208 | */ | 
|  | 209 | if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_2T2R) { | 
|  | 210 |  | 
|  | 211 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("1T2R or 2T2R\n")); | 
|  | 212 |  | 
|  | 213 | ht_cap->mcs.rx_mask[0] = 0xFF; | 
|  | 214 | ht_cap->mcs.rx_mask[1] = 0xFF; | 
|  | 215 | ht_cap->mcs.rx_mask[4] = 0x01; | 
|  | 216 |  | 
| Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 217 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 218 | } else if (get_rf_type(rtlphy) == RF_1T1R) { | 
|  | 219 |  | 
|  | 220 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("1T1R\n")); | 
|  | 221 |  | 
|  | 222 | ht_cap->mcs.rx_mask[0] = 0xFF; | 
|  | 223 | ht_cap->mcs.rx_mask[1] = 0x00; | 
|  | 224 | ht_cap->mcs.rx_mask[4] = 0x01; | 
|  | 225 |  | 
| Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 226 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 227 | } | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | static void _rtl_init_mac80211(struct ieee80211_hw *hw) | 
|  | 231 | { | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 232 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 233 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 234 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); | 
|  | 235 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | 
|  | 236 | struct ieee80211_supported_band *sband; | 
|  | 237 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 238 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 239 | if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset == | 
|  | 240 | BAND_ON_BOTH) { | 
|  | 241 | /* 1: 2.4 G bands */ | 
|  | 242 | /* <1> use  mac->bands as mem for hw->wiphy->bands */ | 
|  | 243 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 244 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 245 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] | 
|  | 246 | * to default value(1T1R) */ | 
|  | 247 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz, | 
|  | 248 | sizeof(struct ieee80211_supported_band)); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 249 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 250 | /* <3> init ht cap base on ant_num */ | 
|  | 251 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 252 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 253 | /* <4> set mac->sband to wiphy->sband */ | 
|  | 254 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; | 
|  | 255 |  | 
|  | 256 | /* 2: 5 G bands */ | 
|  | 257 | /* <1> use  mac->bands as mem for hw->wiphy->bands */ | 
|  | 258 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); | 
|  | 259 |  | 
|  | 260 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] | 
|  | 261 | * to default value(1T1R) */ | 
|  | 262 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz, | 
|  | 263 | sizeof(struct ieee80211_supported_band)); | 
|  | 264 |  | 
|  | 265 | /* <3> init ht cap base on ant_num */ | 
|  | 266 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); | 
|  | 267 |  | 
|  | 268 | /* <4> set mac->sband to wiphy->sband */ | 
|  | 269 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; | 
|  | 270 | } else { | 
|  | 271 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { | 
|  | 272 | /* <1> use  mac->bands as mem for hw->wiphy->bands */ | 
|  | 273 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); | 
|  | 274 |  | 
|  | 275 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] | 
|  | 276 | * to default value(1T1R) */ | 
|  | 277 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), | 
|  | 278 | &rtl_band_2ghz, | 
|  | 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_2GHZ] = sband; | 
|  | 286 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { | 
|  | 287 | /* <1> use  mac->bands as mem for hw->wiphy->bands */ | 
|  | 288 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); | 
|  | 289 |  | 
|  | 290 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] | 
|  | 291 | * to default value(1T1R) */ | 
|  | 292 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), | 
|  | 293 | &rtl_band_5ghz, | 
|  | 294 | sizeof(struct ieee80211_supported_band)); | 
|  | 295 |  | 
|  | 296 | /* <3> init ht cap base on ant_num */ | 
|  | 297 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); | 
|  | 298 |  | 
|  | 299 | /* <4> set mac->sband to wiphy->sband */ | 
|  | 300 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; | 
|  | 301 | } else { | 
|  | 302 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, | 
|  | 303 | ("Err BAND %d\n", | 
|  | 304 | rtlhal->current_bandtype)); | 
|  | 305 | } | 
|  | 306 | } | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 307 | /* <5> set hw caps */ | 
|  | 308 | hw->flags = IEEE80211_HW_SIGNAL_DBM | | 
|  | 309 | IEEE80211_HW_RX_INCLUDES_FCS | | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 310 | IEEE80211_HW_BEACON_FILTER | | 
|  | 311 | IEEE80211_HW_AMPDU_AGGREGATION | | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 312 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0; | 
|  | 313 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 314 | /* swlps or hwlps has been set in diff chip in init_sw_vars */ | 
|  | 315 | if (rtlpriv->psc.swctrl_lps) | 
|  | 316 | hw->flags |= IEEE80211_HW_SUPPORTS_PS | | 
|  | 317 | IEEE80211_HW_PS_NULLFUNC_STACK | | 
|  | 318 | /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */ | 
|  | 319 | 0; | 
|  | 320 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 321 | hw->wiphy->interface_modes = | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 322 | BIT(NL80211_IFTYPE_AP) | | 
|  | 323 | BIT(NL80211_IFTYPE_STATION) | | 
|  | 324 | BIT(NL80211_IFTYPE_ADHOC); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 325 |  | 
|  | 326 | hw->wiphy->rts_threshold = 2347; | 
|  | 327 |  | 
|  | 328 | hw->queues = AC_MAX; | 
|  | 329 | hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; | 
|  | 330 |  | 
|  | 331 | /* TODO: Correct this value for our hw */ | 
|  | 332 | /* TODO: define these hard code value */ | 
|  | 333 | hw->channel_change_time = 100; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 334 | hw->max_listen_interval = 10; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 335 | hw->max_rate_tries = 4; | 
|  | 336 | /* hw->max_rates = 1; */ | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 337 | hw->sta_data_size = sizeof(struct rtl_sta_info); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 338 |  | 
|  | 339 | /* <6> mac address */ | 
|  | 340 | if (is_valid_ether_addr(rtlefuse->dev_addr)) { | 
|  | 341 | SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); | 
|  | 342 | } else { | 
|  | 343 | u8 rtlmac[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; | 
|  | 344 | get_random_bytes((rtlmac + (ETH_ALEN - 1)), 1); | 
|  | 345 | SET_IEEE80211_PERM_ADDR(hw, rtlmac); | 
|  | 346 | } | 
|  | 347 |  | 
|  | 348 | } | 
|  | 349 |  | 
|  | 350 | static void _rtl_init_deferred_work(struct ieee80211_hw *hw) | 
|  | 351 | { | 
|  | 352 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 353 |  | 
|  | 354 | /* <1> timer */ | 
|  | 355 | init_timer(&rtlpriv->works.watchdog_timer); | 
|  | 356 | setup_timer(&rtlpriv->works.watchdog_timer, | 
|  | 357 | rtl_watch_dog_timer_callback, (unsigned long)hw); | 
|  | 358 |  | 
|  | 359 | /* <2> work queue */ | 
|  | 360 | rtlpriv->works.hw = hw; | 
| John W. Linville | 3d986b2 | 2010-12-16 14:59:49 -0500 | [diff] [blame] | 361 | rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 362 | INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, | 
|  | 363 | (void *)rtl_watchdog_wq_callback); | 
|  | 364 | INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, | 
|  | 365 | (void *)rtl_ips_nic_off_wq_callback); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 366 | INIT_DELAYED_WORK(&rtlpriv->works.ps_work, | 
|  | 367 | (void *)rtl_swlps_wq_callback); | 
|  | 368 | INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, | 
|  | 369 | (void *)rtl_swlps_rfon_wq_callback); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 370 |  | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | void rtl_deinit_deferred_work(struct ieee80211_hw *hw) | 
|  | 374 | { | 
|  | 375 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 376 |  | 
|  | 377 | del_timer_sync(&rtlpriv->works.watchdog_timer); | 
|  | 378 |  | 
|  | 379 | cancel_delayed_work(&rtlpriv->works.watchdog_wq); | 
|  | 380 | cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 381 | cancel_delayed_work(&rtlpriv->works.ps_work); | 
|  | 382 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 383 | } | 
|  | 384 |  | 
|  | 385 | void rtl_init_rfkill(struct ieee80211_hw *hw) | 
|  | 386 | { | 
|  | 387 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 388 |  | 
|  | 389 | bool radio_state; | 
|  | 390 | bool blocked; | 
|  | 391 | u8 valid = 0; | 
|  | 392 |  | 
| Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 393 | /*set init state to on */ | 
|  | 394 | rtlpriv->rfkill.rfkill_state = 1; | 
|  | 395 | wiphy_rfkill_set_hw_state(hw->wiphy, 0); | 
|  | 396 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 397 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); | 
|  | 398 |  | 
| Larry Finger | e6d8a81 | 2010-12-21 19:40:40 -0600 | [diff] [blame] | 399 | if (valid) { | 
| Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 400 | printk(KERN_INFO "rtlwifi: wireless switch is %s\n", | 
|  | 401 | rtlpriv->rfkill.rfkill_state ? "on" : "off"); | 
|  | 402 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 403 | rtlpriv->rfkill.rfkill_state = radio_state; | 
|  | 404 |  | 
|  | 405 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; | 
|  | 406 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); | 
|  | 407 | } | 
|  | 408 |  | 
|  | 409 | wiphy_rfkill_start_polling(hw->wiphy); | 
|  | 410 | } | 
|  | 411 |  | 
|  | 412 | void rtl_deinit_rfkill(struct ieee80211_hw *hw) | 
|  | 413 | { | 
|  | 414 | wiphy_rfkill_stop_polling(hw->wiphy); | 
|  | 415 | } | 
|  | 416 |  | 
|  | 417 | int rtl_init_core(struct ieee80211_hw *hw) | 
|  | 418 | { | 
|  | 419 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 420 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); | 
|  | 421 |  | 
|  | 422 | /* <1> init mac80211 */ | 
|  | 423 | _rtl_init_mac80211(hw); | 
|  | 424 | rtlmac->hw = hw; | 
|  | 425 |  | 
|  | 426 | /* <2> rate control register */ | 
| Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 427 | hw->rate_control_algorithm = "rtl_rc"; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 428 |  | 
|  | 429 | /* | 
|  | 430 | * <3> init CRDA must come after init | 
|  | 431 | * mac80211 hw  in _rtl_init_mac80211. | 
|  | 432 | */ | 
|  | 433 | if (rtl_regd_init(hw, rtl_reg_notifier)) { | 
|  | 434 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("REGD init failed\n")); | 
|  | 435 | return 1; | 
|  | 436 | } else { | 
|  | 437 | /* CRDA regd hint must after init CRDA */ | 
|  | 438 | if (regulatory_hint(hw->wiphy, rtlpriv->regd.alpha2)) { | 
|  | 439 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, | 
|  | 440 | ("regulatory_hint fail\n")); | 
|  | 441 | } | 
|  | 442 | } | 
|  | 443 |  | 
|  | 444 | /* <4> locks */ | 
| Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 445 | mutex_init(&rtlpriv->locks.conf_mutex); | 
| Larry Finger | d704300 | 2010-12-17 19:36:25 -0600 | [diff] [blame] | 446 | spin_lock_init(&rtlpriv->locks.ips_lock); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 447 | spin_lock_init(&rtlpriv->locks.irq_th_lock); | 
|  | 448 | spin_lock_init(&rtlpriv->locks.h2c_lock); | 
|  | 449 | spin_lock_init(&rtlpriv->locks.rf_ps_lock); | 
|  | 450 | spin_lock_init(&rtlpriv->locks.rf_lock); | 
|  | 451 | spin_lock_init(&rtlpriv->locks.lps_lock); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 452 | spin_lock_init(&rtlpriv->locks.waitq_lock); | 
|  | 453 | spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 454 |  | 
|  | 455 | rtlmac->link_state = MAC80211_NOLINK; | 
|  | 456 |  | 
|  | 457 | /* <5> init deferred work */ | 
|  | 458 | _rtl_init_deferred_work(hw); | 
|  | 459 |  | 
|  | 460 | return 0; | 
|  | 461 | } | 
|  | 462 |  | 
|  | 463 | void rtl_deinit_core(struct ieee80211_hw *hw) | 
|  | 464 | { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 465 | } | 
|  | 466 |  | 
|  | 467 | void rtl_init_rx_config(struct ieee80211_hw *hw) | 
|  | 468 | { | 
|  | 469 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 470 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 471 |  | 
|  | 472 | 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] | 473 | } | 
|  | 474 |  | 
|  | 475 | /********************************************************* | 
|  | 476 | * | 
|  | 477 | * tx information functions | 
|  | 478 | * | 
|  | 479 | *********************************************************/ | 
|  | 480 | static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, | 
|  | 481 | struct rtl_tcb_desc *tcb_desc, | 
|  | 482 | struct ieee80211_tx_info *info) | 
|  | 483 | { | 
|  | 484 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 485 | u8 rate_flag = info->control.rates[0].flags; | 
|  | 486 |  | 
|  | 487 | tcb_desc->use_shortpreamble = false; | 
|  | 488 |  | 
|  | 489 | /* 1M can only use Long Preamble. 11B spec */ | 
|  | 490 | if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) | 
|  | 491 | return; | 
|  | 492 | else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) | 
|  | 493 | tcb_desc->use_shortpreamble = true; | 
|  | 494 |  | 
|  | 495 | return; | 
|  | 496 | } | 
|  | 497 |  | 
|  | 498 | static void _rtl_query_shortgi(struct ieee80211_hw *hw, | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 499 | struct ieee80211_sta *sta, | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 500 | struct rtl_tcb_desc *tcb_desc, | 
|  | 501 | struct ieee80211_tx_info *info) | 
|  | 502 | { | 
|  | 503 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 504 | u8 rate_flag = info->control.rates[0].flags; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 505 | u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 506 | tcb_desc->use_shortgi = false; | 
|  | 507 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 508 | if (sta == NULL) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 509 | return; | 
|  | 510 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 511 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; | 
|  | 512 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; | 
|  | 513 |  | 
|  | 514 | if (!(sta->ht_cap.ht_supported)) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 515 | return; | 
|  | 516 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 517 | if (!sgi_40 && !sgi_20) | 
|  | 518 | return; | 
|  | 519 |  | 
|  | 520 | if (mac->opmode == NL80211_IFTYPE_STATION) | 
|  | 521 | bw_40 = mac->bw_40; | 
|  | 522 | else if (mac->opmode == NL80211_IFTYPE_AP || | 
|  | 523 | mac->opmode == NL80211_IFTYPE_ADHOC) | 
|  | 524 | bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; | 
|  | 525 |  | 
|  | 526 | if ((bw_40 == true) && sgi_40) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 527 | tcb_desc->use_shortgi = true; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 528 | else if ((bw_40 == false) && sgi_20) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 529 | tcb_desc->use_shortgi = true; | 
|  | 530 |  | 
|  | 531 | if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) | 
|  | 532 | tcb_desc->use_shortgi = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 533 | } | 
|  | 534 |  | 
|  | 535 | static void _rtl_query_protection_mode(struct ieee80211_hw *hw, | 
|  | 536 | struct rtl_tcb_desc *tcb_desc, | 
|  | 537 | struct ieee80211_tx_info *info) | 
|  | 538 | { | 
|  | 539 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 540 | u8 rate_flag = info->control.rates[0].flags; | 
|  | 541 |  | 
|  | 542 | /* Common Settings */ | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 543 | tcb_desc->rts_stbc = false; | 
|  | 544 | tcb_desc->cts_enable = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 545 | tcb_desc->rts_sc = 0; | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 546 | tcb_desc->rts_bw = false; | 
|  | 547 | tcb_desc->rts_use_shortpreamble = false; | 
|  | 548 | tcb_desc->rts_use_shortgi = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 549 |  | 
|  | 550 | if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { | 
|  | 551 | /* Use CTS-to-SELF in protection mode. */ | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 552 | tcb_desc->rts_enable = true; | 
|  | 553 | tcb_desc->cts_enable = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 554 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; | 
|  | 555 | } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { | 
|  | 556 | /* Use RTS-CTS in protection mode. */ | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 557 | tcb_desc->rts_enable = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 558 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; | 
|  | 559 | } | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 560 | } | 
|  | 561 |  | 
|  | 562 | static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 563 | struct ieee80211_sta *sta, | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 564 | struct rtl_tcb_desc *tcb_desc) | 
|  | 565 | { | 
|  | 566 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 567 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 568 | struct rtl_sta_info *sta_entry = NULL; | 
|  | 569 | u8 ratr_index = 7; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 570 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 571 | if (sta) { | 
|  | 572 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; | 
|  | 573 | ratr_index = sta_entry->ratr_index; | 
|  | 574 | } | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 575 | if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 576 | if (mac->opmode == NL80211_IFTYPE_STATION) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 577 | tcb_desc->ratr_index = 0; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 578 | } else if (mac->opmode == NL80211_IFTYPE_ADHOC) { | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 579 | if (tcb_desc->multicast || tcb_desc->broadcast) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 580 | tcb_desc->hw_rate = | 
|  | 581 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; | 
|  | 582 | tcb_desc->use_driver_rate = 1; | 
|  | 583 | } else { | 
|  | 584 | /* TODO */ | 
|  | 585 | } | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 586 | tcb_desc->ratr_index = ratr_index; | 
|  | 587 | } else if (mac->opmode == NL80211_IFTYPE_AP) { | 
|  | 588 | tcb_desc->ratr_index = ratr_index; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 589 | } | 
|  | 590 | } | 
|  | 591 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 592 | if (rtlpriv->dm.useramask) { | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 593 | /* TODO we will differentiate adhoc and station futrue  */ | 
|  | 594 | if (mac->opmode == NL80211_IFTYPE_STATION) { | 
|  | 595 | tcb_desc->mac_id = 0; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 596 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 597 | if (mac->mode == WIRELESS_MODE_N_24G) | 
|  | 598 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB; | 
|  | 599 | else if (mac->mode == WIRELESS_MODE_N_5G) | 
|  | 600 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NG; | 
|  | 601 | else if (mac->mode & WIRELESS_MODE_G) | 
|  | 602 | tcb_desc->ratr_index = RATR_INX_WIRELESS_GB; | 
|  | 603 | else if (mac->mode & WIRELESS_MODE_B) | 
|  | 604 | tcb_desc->ratr_index = RATR_INX_WIRELESS_B; | 
|  | 605 | else if (mac->mode & WIRELESS_MODE_A) | 
|  | 606 | tcb_desc->ratr_index = RATR_INX_WIRELESS_G; | 
|  | 607 | } else if (mac->opmode == NL80211_IFTYPE_AP || | 
|  | 608 | mac->opmode == NL80211_IFTYPE_ADHOC) { | 
|  | 609 | if (NULL != sta) { | 
|  | 610 | if (sta->aid > 0) | 
|  | 611 | tcb_desc->mac_id = sta->aid + 1; | 
|  | 612 | else | 
|  | 613 | tcb_desc->mac_id = 1; | 
|  | 614 | } else { | 
|  | 615 | tcb_desc->mac_id = 0; | 
|  | 616 | } | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 617 | } | 
|  | 618 | } | 
|  | 619 |  | 
|  | 620 | } | 
|  | 621 |  | 
|  | 622 | static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 623 | struct ieee80211_sta *sta, | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 624 | struct rtl_tcb_desc *tcb_desc) | 
|  | 625 | { | 
|  | 626 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 627 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 628 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 629 | tcb_desc->packet_bw = false; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 630 | if (!sta) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 631 | return; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 632 | if (mac->opmode == NL80211_IFTYPE_AP || | 
|  | 633 | mac->opmode == NL80211_IFTYPE_ADHOC) { | 
|  | 634 | if (!(sta->ht_cap.ht_supported) || | 
|  | 635 | !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) | 
|  | 636 | return; | 
|  | 637 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { | 
|  | 638 | if (!mac->bw_40 || !(sta->ht_cap.ht_supported)) | 
|  | 639 | return; | 
|  | 640 | } | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 641 | if (tcb_desc->multicast || tcb_desc->broadcast) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 642 | return; | 
|  | 643 |  | 
|  | 644 | /*use legency rate, shall use 20MHz */ | 
|  | 645 | if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) | 
|  | 646 | return; | 
|  | 647 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 648 | tcb_desc->packet_bw = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 649 | } | 
|  | 650 |  | 
|  | 651 | static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw) | 
|  | 652 | { | 
|  | 653 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 654 | struct rtl_phy *rtlphy = &(rtlpriv->phy); | 
|  | 655 | u8 hw_rate; | 
|  | 656 |  | 
|  | 657 | if (get_rf_type(rtlphy) == RF_2T2R) | 
|  | 658 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; | 
|  | 659 | else | 
|  | 660 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; | 
|  | 661 |  | 
|  | 662 | return hw_rate; | 
|  | 663 | } | 
|  | 664 |  | 
|  | 665 | void rtl_get_tcb_desc(struct ieee80211_hw *hw, | 
|  | 666 | struct ieee80211_tx_info *info, | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 667 | struct ieee80211_sta *sta, | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 668 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) | 
|  | 669 | { | 
|  | 670 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 671 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 672 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 673 | struct ieee80211_rate *txrate; | 
| Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 674 | __le16 fc = hdr->frame_control; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 675 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 676 | txrate = ieee80211_get_tx_rate(hw, info); | 
|  | 677 | tcb_desc->hw_rate = txrate->hw_value; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 678 |  | 
|  | 679 | if (ieee80211_is_data(fc)) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 680 | /* | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 681 | *we set data rate INX 0 | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 682 | *in rtl_rc.c   if skb is special data or | 
|  | 683 | *mgt which need low data rate. | 
|  | 684 | */ | 
|  | 685 |  | 
|  | 686 | /* | 
|  | 687 | *So tcb_desc->hw_rate is just used for | 
|  | 688 | *special data and mgt frames | 
|  | 689 | */ | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 690 | if (info->control.rates[0].idx == 0 && | 
|  | 691 | ieee80211_is_nullfunc(fc)) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 692 | tcb_desc->use_driver_rate = true; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 693 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 694 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 695 | tcb_desc->disable_ratefallback = 1; | 
|  | 696 | } else { | 
|  | 697 | /* | 
|  | 698 | *because hw will nerver use hw_rate | 
|  | 699 | *when tcb_desc->use_driver_rate = false | 
|  | 700 | *so we never set highest N rate here, | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 701 | *and N rate will all be controlled by FW | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 702 | *when tcb_desc->use_driver_rate = false | 
|  | 703 | */ | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 704 | if (sta && (sta->ht_cap.ht_supported)) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 705 | tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw); | 
|  | 706 | } else { | 
|  | 707 | if (rtlmac->mode == WIRELESS_MODE_B) { | 
|  | 708 | tcb_desc->hw_rate = | 
|  | 709 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; | 
|  | 710 | } else { | 
|  | 711 | tcb_desc->hw_rate = | 
|  | 712 | rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; | 
|  | 713 | } | 
|  | 714 | } | 
|  | 715 | } | 
|  | 716 |  | 
|  | 717 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 718 | tcb_desc->multicast = 1; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 719 | else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr))) | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 720 | tcb_desc->broadcast = 1; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 721 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 722 | _rtl_txrate_selectmode(hw, sta, tcb_desc); | 
|  | 723 | _rtl_query_bandwidth_mode(hw, sta, tcb_desc); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 724 | _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 725 | _rtl_query_shortgi(hw, sta, tcb_desc, info); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 726 | _rtl_query_protection_mode(hw, tcb_desc, info); | 
|  | 727 | } else { | 
|  | 728 | tcb_desc->use_driver_rate = true; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 729 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 730 | tcb_desc->disable_ratefallback = 1; | 
|  | 731 | tcb_desc->mac_id = 0; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 732 | tcb_desc->packet_bw = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 733 | } | 
|  | 734 | } | 
|  | 735 | EXPORT_SYMBOL(rtl_get_tcb_desc); | 
|  | 736 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 737 | bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) | 
|  | 738 | { | 
|  | 739 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 740 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 741 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
| Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 742 | __le16 fc = hdr->frame_control; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 743 | u8 *act = (u8 *) (((u8 *) skb->data + MAC80211_3ADDR_LEN)); | 
|  | 744 | u8 category; | 
|  | 745 |  | 
|  | 746 | if (!ieee80211_is_action(fc)) | 
|  | 747 | return true; | 
|  | 748 |  | 
|  | 749 | category = *act; | 
|  | 750 | act++; | 
|  | 751 | switch (category) { | 
|  | 752 | case ACT_CAT_BA: | 
|  | 753 | switch (*act) { | 
|  | 754 | case ACT_ADDBAREQ: | 
|  | 755 | if (mac->act_scanning) | 
|  | 756 | return false; | 
|  | 757 |  | 
|  | 758 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | 
|  | 759 | ("%s ACT_ADDBAREQ From :" MAC_FMT "\n", | 
|  | 760 | is_tx ? "Tx" : "Rx", MAC_ARG(hdr->addr2))); | 
|  | 761 | break; | 
|  | 762 | case ACT_ADDBARSP: | 
|  | 763 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | 
|  | 764 | ("%s ACT_ADDBARSP From :" MAC_FMT "\n", | 
|  | 765 | is_tx ? "Tx" : "Rx", MAC_ARG(hdr->addr2))); | 
|  | 766 | break; | 
|  | 767 | case ACT_DELBA: | 
|  | 768 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | 
|  | 769 | ("ACT_ADDBADEL From :" MAC_FMT "\n", | 
|  | 770 | MAC_ARG(hdr->addr2))); | 
|  | 771 | break; | 
|  | 772 | } | 
|  | 773 | break; | 
|  | 774 | default: | 
|  | 775 | break; | 
|  | 776 | } | 
|  | 777 |  | 
|  | 778 | return true; | 
|  | 779 | } | 
|  | 780 |  | 
|  | 781 | /*should call before software enc*/ | 
|  | 782 | u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) | 
|  | 783 | { | 
|  | 784 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 785 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 786 | __le16 fc = rtl_get_fc(skb); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 787 | u16 ether_type; | 
|  | 788 | u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); | 
|  | 789 | const struct iphdr *ip; | 
|  | 790 |  | 
|  | 791 | if (!ieee80211_is_data(fc)) | 
| Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 792 | return false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 793 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 794 |  | 
|  | 795 | ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len + | 
|  | 796 | SNAP_SIZE + PROTOC_TYPE_SIZE); | 
|  | 797 | ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE); | 
| Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 798 | /*	ether_type = ntohs(ether_type); */ | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 799 |  | 
|  | 800 | if (ETH_P_IP == ether_type) { | 
|  | 801 | if (IPPROTO_UDP == ip->protocol) { | 
|  | 802 | struct udphdr *udp = (struct udphdr *)((u8 *) ip + | 
|  | 803 | (ip->ihl << 2)); | 
|  | 804 | if (((((u8 *) udp)[1] == 68) && | 
|  | 805 | (((u8 *) udp)[3] == 67)) || | 
|  | 806 | ((((u8 *) udp)[1] == 67) && | 
|  | 807 | (((u8 *) udp)[3] == 68))) { | 
|  | 808 | /* | 
|  | 809 | * 68 : UDP BOOTP client | 
|  | 810 | * 67 : UDP BOOTP server | 
|  | 811 | */ | 
|  | 812 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), | 
|  | 813 | DBG_DMESG, ("dhcp %s !!\n", | 
|  | 814 | (is_tx) ? "Tx" : "Rx")); | 
|  | 815 |  | 
|  | 816 | if (is_tx) { | 
|  | 817 | rtl_lps_leave(hw); | 
|  | 818 | ppsc->last_delaylps_stamp_jiffies = | 
|  | 819 | jiffies; | 
|  | 820 | } | 
|  | 821 |  | 
|  | 822 | return true; | 
|  | 823 | } | 
|  | 824 | } | 
|  | 825 | } else if (ETH_P_ARP == ether_type) { | 
|  | 826 | if (is_tx) { | 
|  | 827 | rtl_lps_leave(hw); | 
|  | 828 | ppsc->last_delaylps_stamp_jiffies = jiffies; | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | return true; | 
|  | 832 | } else if (ETH_P_PAE == ether_type) { | 
|  | 833 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | 
|  | 834 | ("802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx")); | 
|  | 835 |  | 
|  | 836 | if (is_tx) { | 
|  | 837 | rtl_lps_leave(hw); | 
|  | 838 | ppsc->last_delaylps_stamp_jiffies = jiffies; | 
|  | 839 | } | 
|  | 840 |  | 
|  | 841 | return true; | 
| Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 842 | } else if (ETH_P_IPV6 == ether_type) { | 
|  | 843 | /* IPv6 */ | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 844 | return true; | 
|  | 845 | } | 
|  | 846 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 847 | return false; | 
|  | 848 | } | 
|  | 849 |  | 
|  | 850 | /********************************************************* | 
|  | 851 | * | 
|  | 852 | * functions called by core.c | 
|  | 853 | * | 
|  | 854 | *********************************************************/ | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 855 | int rtl_tx_agg_start(struct ieee80211_hw *hw, | 
|  | 856 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 857 | { | 
|  | 858 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 859 | struct rtl_tid_data *tid_data; | 
|  | 860 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 861 | struct rtl_sta_info *sta_entry = NULL; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 862 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 863 | if (sta == NULL) | 
|  | 864 | return -EINVAL; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 865 |  | 
|  | 866 | if (unlikely(tid >= MAX_TID_COUNT)) | 
|  | 867 | return -EINVAL; | 
|  | 868 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 869 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; | 
|  | 870 | if (!sta_entry) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 871 | return -ENXIO; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 872 | tid_data = &sta_entry->tids[tid]; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 873 |  | 
|  | 874 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 875 | ("on ra = %pM tid = %d seq:%d\n", sta->addr, tid, | 
|  | 876 | tid_data->seq_number)); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 877 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 878 | *ssn = tid_data->seq_number; | 
|  | 879 | tid_data->agg.agg_state = RTL_AGG_START; | 
|  | 880 |  | 
|  | 881 | ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 882 |  | 
|  | 883 | return 0; | 
|  | 884 | } | 
|  | 885 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 886 | int rtl_tx_agg_stop(struct ieee80211_hw *hw, | 
|  | 887 | struct ieee80211_sta *sta, u16 tid) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 888 | { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 889 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 890 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 891 | struct rtl_tid_data *tid_data; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 892 | struct rtl_sta_info *sta_entry = NULL; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 893 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 894 | if (sta == NULL) | 
|  | 895 | return -EINVAL; | 
|  | 896 |  | 
|  | 897 | if (!sta->addr) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 898 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n")); | 
|  | 899 | return -EINVAL; | 
|  | 900 | } | 
|  | 901 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 902 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, | 
|  | 903 | ("on ra = %pM tid = %d\n", sta->addr, tid)); | 
|  | 904 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 905 | if (unlikely(tid >= MAX_TID_COUNT)) | 
|  | 906 | return -EINVAL; | 
|  | 907 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 908 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; | 
|  | 909 | tid_data = &sta_entry->tids[tid]; | 
|  | 910 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 911 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 912 | ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 913 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 914 | return 0; | 
|  | 915 | } | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 916 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 917 | int rtl_tx_agg_oper(struct ieee80211_hw *hw, | 
|  | 918 | struct ieee80211_sta *sta, u16 tid) | 
|  | 919 | { | 
|  | 920 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 921 | struct rtl_tid_data *tid_data; | 
|  | 922 | struct rtl_sta_info *sta_entry = NULL; | 
|  | 923 |  | 
|  | 924 | if (sta == NULL) | 
|  | 925 | return -EINVAL; | 
|  | 926 |  | 
|  | 927 | if (!sta->addr) { | 
|  | 928 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n")); | 
|  | 929 | return -EINVAL; | 
|  | 930 | } | 
|  | 931 |  | 
|  | 932 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, | 
|  | 933 | ("on ra = %pM tid = %d\n", sta->addr, tid)); | 
|  | 934 |  | 
|  | 935 | if (unlikely(tid >= MAX_TID_COUNT)) | 
|  | 936 | return -EINVAL; | 
|  | 937 |  | 
|  | 938 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; | 
|  | 939 | tid_data = &sta_entry->tids[tid]; | 
|  | 940 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 941 |  | 
|  | 942 | return 0; | 
|  | 943 | } | 
|  | 944 |  | 
|  | 945 | /********************************************************* | 
|  | 946 | * | 
|  | 947 | * wq & timer callback functions | 
|  | 948 | * | 
|  | 949 | *********************************************************/ | 
|  | 950 | void rtl_watchdog_wq_callback(void *data) | 
|  | 951 | { | 
|  | 952 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, | 
|  | 953 | struct rtl_works, | 
|  | 954 | watchdog_wq); | 
|  | 955 | struct ieee80211_hw *hw = rtlworks->hw; | 
|  | 956 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 957 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
|  | 958 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 959 | bool busytraffic = false; | 
|  | 960 | bool higher_busytraffic = false; | 
|  | 961 | bool higher_busyrxtraffic = false; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 962 | u8 idx, tid; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 963 | u32 rx_cnt_inp4eriod = 0; | 
|  | 964 | u32 tx_cnt_inp4eriod = 0; | 
|  | 965 | u32 aver_rx_cnt_inperiod = 0; | 
|  | 966 | u32 aver_tx_cnt_inperiod = 0; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 967 | u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; | 
|  | 968 | u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 969 | bool enter_ps = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 970 |  | 
|  | 971 | if (is_hal_stop(rtlhal)) | 
|  | 972 | return; | 
|  | 973 |  | 
|  | 974 | /* <1> Determine if action frame is allowed */ | 
|  | 975 | if (mac->link_state > MAC80211_NOLINK) { | 
|  | 976 | if (mac->cnt_after_linked < 20) | 
|  | 977 | mac->cnt_after_linked++; | 
|  | 978 | } else { | 
|  | 979 | mac->cnt_after_linked = 0; | 
|  | 980 | } | 
|  | 981 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 982 | /* | 
|  | 983 | *<3> to check if traffic busy, if | 
|  | 984 | * busytraffic we don't change channel | 
|  | 985 | */ | 
|  | 986 | if (mac->link_state >= MAC80211_LINKED) { | 
|  | 987 |  | 
|  | 988 | /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ | 
|  | 989 | for (idx = 0; idx <= 2; idx++) { | 
|  | 990 | rtlpriv->link_info.num_rx_in4period[idx] = | 
|  | 991 | rtlpriv->link_info.num_rx_in4period[idx + 1]; | 
|  | 992 | rtlpriv->link_info.num_tx_in4period[idx] = | 
|  | 993 | rtlpriv->link_info.num_tx_in4period[idx + 1]; | 
|  | 994 | } | 
|  | 995 | rtlpriv->link_info.num_rx_in4period[3] = | 
|  | 996 | rtlpriv->link_info.num_rx_inperiod; | 
|  | 997 | rtlpriv->link_info.num_tx_in4period[3] = | 
|  | 998 | rtlpriv->link_info.num_tx_inperiod; | 
|  | 999 | for (idx = 0; idx <= 3; idx++) { | 
|  | 1000 | rx_cnt_inp4eriod += | 
|  | 1001 | rtlpriv->link_info.num_rx_in4period[idx]; | 
|  | 1002 | tx_cnt_inp4eriod += | 
|  | 1003 | rtlpriv->link_info.num_tx_in4period[idx]; | 
|  | 1004 | } | 
|  | 1005 | aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; | 
|  | 1006 | aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; | 
|  | 1007 |  | 
|  | 1008 | /* (2) check traffic busy */ | 
|  | 1009 | if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1010 | busytraffic = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1011 |  | 
|  | 1012 | /* Higher Tx/Rx data. */ | 
|  | 1013 | if (aver_rx_cnt_inperiod > 4000 || | 
|  | 1014 | aver_tx_cnt_inperiod > 4000) { | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1015 | higher_busytraffic = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1016 |  | 
|  | 1017 | /* Extremely high Rx data. */ | 
|  | 1018 | if (aver_rx_cnt_inperiod > 5000) | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1019 | higher_busyrxtraffic = true; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1020 | } | 
|  | 1021 |  | 
|  | 1022 | /* check every tid's tx traffic */ | 
|  | 1023 | for (tid = 0; tid <= 7; tid++) { | 
|  | 1024 | for (idx = 0; idx <= 2; idx++) | 
|  | 1025 | rtlpriv->link_info.tidtx_in4period[tid][idx] = | 
|  | 1026 | rtlpriv->link_info.tidtx_in4period[tid] | 
|  | 1027 | [idx + 1]; | 
|  | 1028 | rtlpriv->link_info.tidtx_in4period[tid][3] = | 
|  | 1029 | rtlpriv->link_info.tidtx_inperiod[tid]; | 
|  | 1030 |  | 
|  | 1031 | for (idx = 0; idx <= 3; idx++) | 
|  | 1032 | tidtx_inp4eriod[tid] += | 
|  | 1033 | rtlpriv->link_info.tidtx_in4period[tid][idx]; | 
|  | 1034 | aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; | 
|  | 1035 | if (aver_tidtx_inperiod[tid] > 5000) | 
|  | 1036 | rtlpriv->link_info.higher_busytxtraffic[tid] = | 
|  | 1037 | true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1038 | else | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1039 | rtlpriv->link_info.higher_busytxtraffic[tid] = | 
|  | 1040 | false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1041 | } | 
|  | 1042 |  | 
|  | 1043 | if (((rtlpriv->link_info.num_rx_inperiod + | 
|  | 1044 | rtlpriv->link_info.num_tx_inperiod) > 8) || | 
|  | 1045 | (rtlpriv->link_info.num_rx_inperiod > 2)) | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1046 | enter_ps = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1047 | else | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1048 | enter_ps = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1049 |  | 
|  | 1050 | /* LeisurePS only work in infra mode. */ | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1051 | if (enter_ps) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1052 | rtl_lps_enter(hw); | 
|  | 1053 | else | 
|  | 1054 | rtl_lps_leave(hw); | 
|  | 1055 | } | 
|  | 1056 |  | 
|  | 1057 | rtlpriv->link_info.num_rx_inperiod = 0; | 
|  | 1058 | rtlpriv->link_info.num_tx_inperiod = 0; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1059 | for (tid = 0; tid <= 7; tid++) | 
|  | 1060 | rtlpriv->link_info.tidtx_inperiod[tid] = 0; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1061 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1062 | rtlpriv->link_info.busytraffic = busytraffic; | 
|  | 1063 | rtlpriv->link_info.higher_busytraffic = higher_busytraffic; | 
|  | 1064 | rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1065 |  | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1066 | /* <3> DM */ | 
|  | 1067 | rtlpriv->cfg->ops->dm_watchdog(hw); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1068 | } | 
|  | 1069 |  | 
|  | 1070 | void rtl_watch_dog_timer_callback(unsigned long data) | 
|  | 1071 | { | 
|  | 1072 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; | 
|  | 1073 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 1074 |  | 
|  | 1075 | queue_delayed_work(rtlpriv->works.rtl_wq, | 
|  | 1076 | &rtlpriv->works.watchdog_wq, 0); | 
|  | 1077 |  | 
|  | 1078 | mod_timer(&rtlpriv->works.watchdog_timer, | 
|  | 1079 | jiffies + MSECS(RTL_WATCH_DOG_TIME)); | 
|  | 1080 | } | 
|  | 1081 |  | 
|  | 1082 | /********************************************************* | 
|  | 1083 | * | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1084 | * frame process functions | 
|  | 1085 | * | 
|  | 1086 | *********************************************************/ | 
|  | 1087 | u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) | 
|  | 1088 | { | 
|  | 1089 | struct ieee80211_mgmt *mgmt = (void *)data; | 
|  | 1090 | u8 *pos, *end; | 
|  | 1091 |  | 
|  | 1092 | pos = (u8 *)mgmt->u.beacon.variable; | 
|  | 1093 | end = data + len; | 
|  | 1094 | while (pos < end) { | 
|  | 1095 | if (pos + 2 + pos[1] > end) | 
|  | 1096 | return NULL; | 
|  | 1097 |  | 
|  | 1098 | if (pos[0] == ie) | 
|  | 1099 | return pos; | 
|  | 1100 |  | 
|  | 1101 | pos += 2 + pos[1]; | 
|  | 1102 | } | 
|  | 1103 | return NULL; | 
|  | 1104 | } | 
|  | 1105 |  | 
|  | 1106 | /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ | 
|  | 1107 | /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ | 
| Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1108 | static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1109 | enum ieee80211_smps_mode smps, u8 *da, u8 *bssid) | 
|  | 1110 | { | 
|  | 1111 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | 
|  | 1112 | struct sk_buff *skb; | 
|  | 1113 | struct ieee80211_mgmt *action_frame; | 
|  | 1114 |  | 
|  | 1115 | /* 27 = header + category + action + smps mode */ | 
|  | 1116 | skb = dev_alloc_skb(27 + hw->extra_tx_headroom); | 
|  | 1117 | if (!skb) | 
|  | 1118 | return NULL; | 
|  | 1119 |  | 
|  | 1120 | skb_reserve(skb, hw->extra_tx_headroom); | 
|  | 1121 | action_frame = (void *)skb_put(skb, 27); | 
|  | 1122 | memset(action_frame, 0, 27); | 
|  | 1123 | memcpy(action_frame->da, da, ETH_ALEN); | 
|  | 1124 | memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); | 
|  | 1125 | memcpy(action_frame->bssid, bssid, ETH_ALEN); | 
|  | 1126 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | 
|  | 1127 | IEEE80211_STYPE_ACTION); | 
|  | 1128 | action_frame->u.action.category = WLAN_CATEGORY_HT; | 
|  | 1129 | action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS; | 
|  | 1130 | switch (smps) { | 
|  | 1131 | case IEEE80211_SMPS_AUTOMATIC:/* 0 */ | 
|  | 1132 | case IEEE80211_SMPS_NUM_MODES:/* 4 */ | 
|  | 1133 | WARN_ON(1); | 
|  | 1134 | case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ | 
|  | 1135 | action_frame->u.action.u.ht_smps.smps_control = | 
|  | 1136 | WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ | 
|  | 1137 | break; | 
|  | 1138 | case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ | 
|  | 1139 | action_frame->u.action.u.ht_smps.smps_control = | 
|  | 1140 | WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ | 
|  | 1141 | break; | 
|  | 1142 | case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ | 
|  | 1143 | action_frame->u.action.u.ht_smps.smps_control = | 
|  | 1144 | WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ | 
|  | 1145 | break; | 
|  | 1146 | } | 
|  | 1147 |  | 
|  | 1148 | return skb; | 
|  | 1149 | } | 
|  | 1150 |  | 
|  | 1151 | int rtl_send_smps_action(struct ieee80211_hw *hw, | 
|  | 1152 | struct ieee80211_sta *sta, u8 *da, u8 *bssid, | 
|  | 1153 | enum ieee80211_smps_mode smps) | 
|  | 1154 | { | 
|  | 1155 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 1156 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
|  | 1157 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 1158 | struct sk_buff *skb = rtl_make_smps_action(hw, smps, da, bssid); | 
|  | 1159 | struct rtl_tcb_desc tcb_desc; | 
|  | 1160 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); | 
|  | 1161 |  | 
|  | 1162 | if (rtlpriv->mac80211.act_scanning) | 
|  | 1163 | goto err_free; | 
|  | 1164 |  | 
|  | 1165 | if (!sta) | 
|  | 1166 | goto err_free; | 
|  | 1167 |  | 
|  | 1168 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) | 
|  | 1169 | goto err_free; | 
|  | 1170 |  | 
|  | 1171 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) | 
|  | 1172 | goto err_free; | 
|  | 1173 |  | 
|  | 1174 | /* this is a type = mgmt * stype = action frame */ | 
|  | 1175 | if (skb) { | 
|  | 1176 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 
|  | 1177 | struct rtl_sta_info *sta_entry = | 
|  | 1178 | (struct rtl_sta_info *) sta->drv_priv; | 
|  | 1179 | sta_entry->mimo_ps = smps; | 
|  | 1180 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); | 
|  | 1181 |  | 
|  | 1182 | info->control.rates[0].idx = 0; | 
|  | 1183 | info->control.sta = sta; | 
|  | 1184 | info->band = hw->conf.channel->band; | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1185 | rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1186 | } | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1187 | err_free: | 
|  | 1188 | return 0; | 
|  | 1189 | } | 
|  | 1190 |  | 
|  | 1191 | /********************************************************* | 
|  | 1192 | * | 
|  | 1193 | * IOT functions | 
|  | 1194 | * | 
|  | 1195 | *********************************************************/ | 
|  | 1196 | static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, | 
|  | 1197 | struct octet_string vendor_ie) | 
|  | 1198 | { | 
|  | 1199 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 1200 | bool matched = false; | 
|  | 1201 | static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; | 
|  | 1202 | static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; | 
|  | 1203 | static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; | 
|  | 1204 | static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; | 
|  | 1205 | static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; | 
|  | 1206 | static u8 racap[] = { 0x00, 0x0c, 0x43 }; | 
|  | 1207 | static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; | 
|  | 1208 | static u8 marvcap[] = { 0x00, 0x50, 0x43 }; | 
|  | 1209 |  | 
|  | 1210 | if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || | 
|  | 1211 | memcmp(vendor_ie.octet, athcap_2, 3) == 0) { | 
|  | 1212 | rtlpriv->mac80211.vendor = PEER_ATH; | 
|  | 1213 | matched = true; | 
|  | 1214 | } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || | 
|  | 1215 | memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || | 
|  | 1216 | memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { | 
|  | 1217 | rtlpriv->mac80211.vendor = PEER_BROAD; | 
|  | 1218 | matched = true; | 
|  | 1219 | } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { | 
|  | 1220 | rtlpriv->mac80211.vendor = PEER_RAL; | 
|  | 1221 | matched = true; | 
|  | 1222 | } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { | 
|  | 1223 | rtlpriv->mac80211.vendor = PEER_CISCO; | 
|  | 1224 | matched = true; | 
|  | 1225 | } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { | 
|  | 1226 | rtlpriv->mac80211.vendor = PEER_MARV; | 
|  | 1227 | matched = true; | 
|  | 1228 | } | 
|  | 1229 |  | 
|  | 1230 | return matched; | 
|  | 1231 | } | 
|  | 1232 |  | 
| Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1233 | static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1234 | unsigned int len) | 
|  | 1235 | { | 
|  | 1236 | struct ieee80211_mgmt *mgmt = (void *)data; | 
|  | 1237 | struct octet_string vendor_ie; | 
|  | 1238 | u8 *pos, *end; | 
|  | 1239 |  | 
|  | 1240 | pos = (u8 *)mgmt->u.beacon.variable; | 
|  | 1241 | end = data + len; | 
|  | 1242 | while (pos < end) { | 
|  | 1243 | if (pos[0] == 221) { | 
|  | 1244 | vendor_ie.length = pos[1]; | 
|  | 1245 | vendor_ie.octet = &pos[2]; | 
|  | 1246 | if (rtl_chk_vendor_ouisub(hw, vendor_ie)) | 
|  | 1247 | return true; | 
|  | 1248 | } | 
|  | 1249 |  | 
|  | 1250 | if (pos + 2 + pos[1] > end) | 
|  | 1251 | return false; | 
|  | 1252 |  | 
|  | 1253 | pos += 2 + pos[1]; | 
|  | 1254 | } | 
|  | 1255 | return false; | 
|  | 1256 | } | 
|  | 1257 |  | 
|  | 1258 | void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) | 
|  | 1259 | { | 
|  | 1260 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 1261 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 1262 | struct ieee80211_hdr *hdr = (void *)data; | 
|  | 1263 | u32 vendor = PEER_UNKNOWN; | 
|  | 1264 |  | 
|  | 1265 | static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; | 
|  | 1266 | static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; | 
|  | 1267 | static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; | 
|  | 1268 | static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; | 
|  | 1269 | static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; | 
|  | 1270 | static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; | 
|  | 1271 | static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; | 
|  | 1272 | static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; | 
|  | 1273 | static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; | 
|  | 1274 | static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; | 
|  | 1275 | static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; | 
|  | 1276 | static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; | 
|  | 1277 | static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; | 
|  | 1278 | static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; | 
|  | 1279 | static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; | 
|  | 1280 | static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; | 
|  | 1281 |  | 
|  | 1282 | if (mac->opmode != NL80211_IFTYPE_STATION) | 
|  | 1283 | return; | 
|  | 1284 |  | 
|  | 1285 | if (mac->link_state == MAC80211_NOLINK) { | 
|  | 1286 | mac->vendor = PEER_UNKNOWN; | 
|  | 1287 | return; | 
|  | 1288 | } | 
|  | 1289 |  | 
|  | 1290 | if (mac->cnt_after_linked > 2) | 
|  | 1291 | return; | 
|  | 1292 |  | 
|  | 1293 | /* check if this really is a beacon */ | 
|  | 1294 | if (!ieee80211_is_beacon(hdr->frame_control)) | 
|  | 1295 | return; | 
|  | 1296 |  | 
|  | 1297 | /* min. beacon length + FCS_LEN */ | 
|  | 1298 | if (len <= 40 + FCS_LEN) | 
|  | 1299 | return; | 
|  | 1300 |  | 
|  | 1301 | /* and only beacons from the associated BSSID, please */ | 
|  | 1302 | if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid)) | 
|  | 1303 | return; | 
|  | 1304 |  | 
|  | 1305 | if (rtl_find_221_ie(hw, data, len)) | 
|  | 1306 | vendor = mac->vendor; | 
|  | 1307 |  | 
|  | 1308 | if ((memcmp(mac->bssid, ap5_1, 3) == 0) || | 
|  | 1309 | (memcmp(mac->bssid, ap5_2, 3) == 0) || | 
|  | 1310 | (memcmp(mac->bssid, ap5_3, 3) == 0) || | 
|  | 1311 | (memcmp(mac->bssid, ap5_4, 3) == 0) || | 
|  | 1312 | (memcmp(mac->bssid, ap5_5, 3) == 0) || | 
|  | 1313 | (memcmp(mac->bssid, ap5_6, 3) == 0) || | 
|  | 1314 | vendor == PEER_ATH) { | 
|  | 1315 | vendor = PEER_ATH; | 
|  | 1316 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ath find\n")); | 
|  | 1317 | } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || | 
|  | 1318 | (memcmp(mac->bssid, ap4_5, 3) == 0) || | 
|  | 1319 | (memcmp(mac->bssid, ap4_1, 3) == 0) || | 
|  | 1320 | (memcmp(mac->bssid, ap4_2, 3) == 0) || | 
|  | 1321 | (memcmp(mac->bssid, ap4_3, 3) == 0) || | 
|  | 1322 | vendor == PEER_RAL) { | 
|  | 1323 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ral findn\n")); | 
|  | 1324 | vendor = PEER_RAL; | 
|  | 1325 | } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || | 
|  | 1326 | vendor == PEER_CISCO) { | 
|  | 1327 | vendor = PEER_CISCO; | 
|  | 1328 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>cisco find\n")); | 
|  | 1329 | } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || | 
|  | 1330 | (memcmp(mac->bssid, ap3_2, 3) == 0) || | 
|  | 1331 | (memcmp(mac->bssid, ap3_3, 3) == 0) || | 
|  | 1332 | vendor == PEER_BROAD) { | 
|  | 1333 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>broad find\n")); | 
|  | 1334 | vendor = PEER_BROAD; | 
|  | 1335 | } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || | 
|  | 1336 | vendor == PEER_MARV) { | 
|  | 1337 | vendor = PEER_MARV; | 
|  | 1338 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>marv find\n")); | 
|  | 1339 | } | 
|  | 1340 |  | 
|  | 1341 | mac->vendor = vendor; | 
|  | 1342 | } | 
|  | 1343 |  | 
|  | 1344 | /********************************************************* | 
|  | 1345 | * | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1346 | * sysfs functions | 
|  | 1347 | * | 
|  | 1348 | *********************************************************/ | 
|  | 1349 | static ssize_t rtl_show_debug_level(struct device *d, | 
|  | 1350 | struct device_attribute *attr, char *buf) | 
|  | 1351 | { | 
|  | 1352 | struct ieee80211_hw *hw = dev_get_drvdata(d); | 
|  | 1353 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 1354 |  | 
|  | 1355 | return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel); | 
|  | 1356 | } | 
|  | 1357 |  | 
|  | 1358 | static ssize_t rtl_store_debug_level(struct device *d, | 
|  | 1359 | struct device_attribute *attr, | 
|  | 1360 | const char *buf, size_t count) | 
|  | 1361 | { | 
|  | 1362 | struct ieee80211_hw *hw = dev_get_drvdata(d); | 
|  | 1363 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 1364 | unsigned long val; | 
|  | 1365 | int ret; | 
|  | 1366 |  | 
|  | 1367 | ret = strict_strtoul(buf, 0, &val); | 
|  | 1368 | if (ret) { | 
|  | 1369 | printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf); | 
|  | 1370 | } else { | 
|  | 1371 | rtlpriv->dbg.global_debuglevel = val; | 
|  | 1372 | printk(KERN_DEBUG "debuglevel:%x\n", | 
|  | 1373 | rtlpriv->dbg.global_debuglevel); | 
|  | 1374 | } | 
|  | 1375 |  | 
|  | 1376 | return strnlen(buf, count); | 
|  | 1377 | } | 
|  | 1378 |  | 
|  | 1379 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, | 
|  | 1380 | rtl_show_debug_level, rtl_store_debug_level); | 
|  | 1381 |  | 
|  | 1382 | static struct attribute *rtl_sysfs_entries[] = { | 
|  | 1383 |  | 
|  | 1384 | &dev_attr_debug_level.attr, | 
|  | 1385 |  | 
|  | 1386 | NULL | 
|  | 1387 | }; | 
|  | 1388 |  | 
|  | 1389 | /* | 
|  | 1390 | * "name" is folder name witch will be | 
|  | 1391 | * put in device directory like : | 
|  | 1392 | * sys/devices/pci0000:00/0000:00:1c.4/ | 
|  | 1393 | * 0000:06:00.0/rtl_sysfs | 
|  | 1394 | */ | 
|  | 1395 | struct attribute_group rtl_attribute_group = { | 
|  | 1396 | .name = "rtlsysfs", | 
|  | 1397 | .attrs = rtl_sysfs_entries, | 
|  | 1398 | }; | 
|  | 1399 |  | 
|  | 1400 | MODULE_AUTHOR("lizhaoming	<chaoming_li@realsil.com.cn>"); | 
|  | 1401 | MODULE_AUTHOR("Realtek WlanFAE	<wlanfae@realtek.com>"); | 
|  | 1402 | MODULE_AUTHOR("Larry Finger	<Larry.FInger@lwfinger.net>"); | 
|  | 1403 | MODULE_LICENSE("GPL"); | 
|  | 1404 | MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); | 
|  | 1405 |  | 
|  | 1406 | static int __init rtl_core_module_init(void) | 
|  | 1407 | { | 
| Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1408 | if (rtl_rate_control_register()) | 
|  | 1409 | printk(KERN_ERR "rtlwifi: Unable to register rtl_rc," | 
|  | 1410 | "use default RC !!\n"); | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1411 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1412 | return 0; | 
|  | 1413 | } | 
|  | 1414 |  | 
|  | 1415 | static void __exit rtl_core_module_exit(void) | 
|  | 1416 | { | 
| Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1417 | /*RC*/ | 
| Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1418 | rtl_rate_control_unregister(); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1419 | } | 
|  | 1420 |  | 
|  | 1421 | module_init(rtl_core_module_init); | 
|  | 1422 | module_exit(rtl_core_module_exit); |