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> |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 27 | * |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include "wifi.h" |
| 31 | #include "core.h" |
| 32 | #include "cam.h" |
| 33 | #include "base.h" |
| 34 | #include "ps.h" |
| 35 | |
| 36 | /*mutex for start & stop is must here. */ |
| 37 | static int rtl_op_start(struct ieee80211_hw *hw) |
| 38 | { |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 39 | int err; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 40 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 41 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 42 | |
| 43 | if (!is_hal_stop(rtlhal)) |
| 44 | return 0; |
| 45 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 46 | return 0; |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 47 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 48 | err = rtlpriv->intf_ops->adapter_start(hw); |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 49 | if (!err) |
| 50 | rtl_watch_dog_timer_callback((unsigned long)hw); |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 51 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 52 | return err; |
| 53 | } |
| 54 | |
| 55 | static void rtl_op_stop(struct ieee80211_hw *hw) |
| 56 | { |
| 57 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 58 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 59 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 60 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 61 | |
| 62 | if (is_hal_stop(rtlhal)) |
| 63 | return; |
| 64 | |
| 65 | if (unlikely(ppsc->rfpwr_state == ERFOFF)) { |
| 66 | rtl_ips_nic_on(hw); |
| 67 | mdelay(1); |
| 68 | } |
| 69 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 70 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 71 | |
| 72 | mac->link_state = MAC80211_NOLINK; |
| 73 | memset(mac->bssid, 0, 6); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 74 | mac->vendor = PEER_UNKNOWN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 75 | |
| 76 | /*reset sec info */ |
| 77 | rtl_cam_reset_sec_info(hw); |
| 78 | |
| 79 | rtl_deinit_deferred_work(hw); |
| 80 | rtlpriv->intf_ops->adapter_stop(hw); |
| 81 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 82 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 83 | } |
| 84 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 85 | static void rtl_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 86 | { |
| 87 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 88 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 89 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 90 | struct rtl_tcb_desc tcb_desc; |
| 91 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 92 | |
| 93 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) |
| 94 | goto err_free; |
| 95 | |
| 96 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 97 | goto err_free; |
| 98 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 99 | if (!rtlpriv->intf_ops->waitq_insert(hw, skb)) |
| 100 | rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 101 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 102 | return; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 103 | |
| 104 | err_free: |
| 105 | dev_kfree_skb_any(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static int rtl_op_add_interface(struct ieee80211_hw *hw, |
| 109 | struct ieee80211_vif *vif) |
| 110 | { |
| 111 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 112 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 113 | int err = 0; |
| 114 | |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame^] | 115 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER; |
| 116 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 117 | if (mac->vif) { |
| 118 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 119 | "vif has been set!! mac->vif = 0x%p\n", mac->vif); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 120 | return -EOPNOTSUPP; |
| 121 | } |
| 122 | |
| 123 | rtl_ips_nic_on(hw); |
| 124 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 125 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 126 | switch (vif->type) { |
| 127 | case NL80211_IFTYPE_STATION: |
| 128 | if (mac->beacon_enabled == 1) { |
| 129 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 130 | "NL80211_IFTYPE_STATION\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 131 | mac->beacon_enabled = 0; |
| 132 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, |
| 133 | rtlpriv->cfg->maps |
| 134 | [RTL_IBSS_INT_MASKS]); |
| 135 | } |
| 136 | break; |
| 137 | case NL80211_IFTYPE_ADHOC: |
| 138 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 139 | "NL80211_IFTYPE_ADHOC\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 140 | |
| 141 | mac->link_state = MAC80211_LINKED; |
| 142 | rtlpriv->cfg->ops->set_bcn_reg(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 143 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) |
| 144 | mac->basic_rates = 0xfff; |
| 145 | else |
| 146 | mac->basic_rates = 0xff0; |
| 147 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
| 148 | (u8 *) (&mac->basic_rates)); |
| 149 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 150 | break; |
| 151 | case NL80211_IFTYPE_AP: |
| 152 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 153 | "NL80211_IFTYPE_AP\n"); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 154 | |
| 155 | mac->link_state = MAC80211_LINKED; |
| 156 | rtlpriv->cfg->ops->set_bcn_reg(hw); |
| 157 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) |
| 158 | mac->basic_rates = 0xfff; |
| 159 | else |
| 160 | mac->basic_rates = 0xff0; |
| 161 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
| 162 | (u8 *) (&mac->basic_rates)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 163 | break; |
| 164 | default: |
| 165 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 166 | "operation mode %d is not supported!\n", vif->type); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 167 | err = -EOPNOTSUPP; |
| 168 | goto out; |
| 169 | } |
| 170 | |
| 171 | mac->vif = vif; |
| 172 | mac->opmode = vif->type; |
| 173 | rtlpriv->cfg->ops->set_network_type(hw, vif->type); |
| 174 | memcpy(mac->mac_addr, vif->addr, ETH_ALEN); |
| 175 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr); |
| 176 | |
| 177 | out: |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 178 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 179 | return err; |
| 180 | } |
| 181 | |
| 182 | static void rtl_op_remove_interface(struct ieee80211_hw *hw, |
| 183 | struct ieee80211_vif *vif) |
| 184 | { |
| 185 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 186 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 187 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 188 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 189 | |
| 190 | /* Free beacon resources */ |
| 191 | if ((mac->opmode == NL80211_IFTYPE_AP) || |
| 192 | (mac->opmode == NL80211_IFTYPE_ADHOC) || |
| 193 | (mac->opmode == NL80211_IFTYPE_MESH_POINT)) { |
| 194 | if (mac->beacon_enabled == 1) { |
| 195 | mac->beacon_enabled = 0; |
| 196 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, |
| 197 | rtlpriv->cfg->maps |
| 198 | [RTL_IBSS_INT_MASKS]); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | *Note: We assume NL80211_IFTYPE_UNSPECIFIED as |
| 204 | *NO LINK for our hardware. |
| 205 | */ |
| 206 | mac->vif = NULL; |
| 207 | mac->link_state = MAC80211_NOLINK; |
| 208 | memset(mac->bssid, 0, 6); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 209 | mac->vendor = PEER_UNKNOWN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 210 | mac->opmode = NL80211_IFTYPE_UNSPECIFIED; |
| 211 | rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 212 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 213 | } |
| 214 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 215 | static int rtl_op_config(struct ieee80211_hw *hw, u32 changed) |
| 216 | { |
| 217 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 218 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 219 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 220 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 221 | struct ieee80211_conf *conf = &hw->conf; |
| 222 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 223 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 224 | if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { /*BIT(2)*/ |
| 225 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 226 | "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /*For IPS */ |
| 230 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 231 | if (hw->conf.flags & IEEE80211_CONF_IDLE) |
| 232 | rtl_ips_nic_off(hw); |
| 233 | else |
| 234 | rtl_ips_nic_on(hw); |
| 235 | } else { |
| 236 | /* |
| 237 | *although rfoff may not cause by ips, but we will |
| 238 | *check the reason in set_rf_power_state function |
| 239 | */ |
| 240 | if (unlikely(ppsc->rfpwr_state == ERFOFF)) |
| 241 | rtl_ips_nic_on(hw); |
| 242 | } |
| 243 | |
| 244 | /*For LPS */ |
| 245 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 246 | cancel_delayed_work(&rtlpriv->works.ps_work); |
| 247 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); |
| 248 | if (conf->flags & IEEE80211_CONF_PS) { |
| 249 | rtlpriv->psc.sw_ps_enabled = true; |
| 250 | /* sleep here is must, or we may recv the beacon and |
| 251 | * cause mac80211 into wrong ps state, this will cause |
| 252 | * power save nullfunc send fail, and further cause |
| 253 | * pkt loss, So sleep must quickly but not immediatly |
| 254 | * because that will cause nullfunc send by mac80211 |
| 255 | * fail, and cause pkt loss, we have tested that 5mA |
| 256 | * is worked very well */ |
| 257 | if (!rtlpriv->psc.multi_buffered) |
| 258 | queue_delayed_work(rtlpriv->works.rtl_wq, |
| 259 | &rtlpriv->works.ps_work, |
| 260 | MSECS(5)); |
| 261 | } else { |
| 262 | rtl_swlps_rf_awake(hw); |
| 263 | rtlpriv->psc.sw_ps_enabled = false; |
| 264 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { |
| 268 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 269 | "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n", |
| 270 | hw->conf.long_frame_max_tx_count); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 271 | mac->retry_long = hw->conf.long_frame_max_tx_count; |
| 272 | mac->retry_short = hw->conf.long_frame_max_tx_count; |
| 273 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT, |
| 274 | (u8 *) (&hw->conf. |
| 275 | long_frame_max_tx_count)); |
| 276 | } |
| 277 | |
| 278 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 279 | struct ieee80211_channel *channel = hw->conf.channel; |
| 280 | u8 wide_chan = (u8) channel->hw_value; |
| 281 | |
| 282 | /* |
| 283 | *because we should back channel to |
| 284 | *current_network.chan in in scanning, |
| 285 | *So if set_chan == current_network.chan |
| 286 | *we should set it. |
| 287 | *because mac80211 tell us wrong bw40 |
| 288 | *info for cisco1253 bw20, so we modify |
| 289 | *it here based on UPPER & LOWER |
| 290 | */ |
| 291 | switch (hw->conf.channel_type) { |
| 292 | case NL80211_CHAN_HT20: |
| 293 | case NL80211_CHAN_NO_HT: |
| 294 | /* SC */ |
| 295 | mac->cur_40_prime_sc = |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 296 | PRIME_CHNL_OFFSET_DONT_CARE; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 297 | rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20; |
| 298 | mac->bw_40 = false; |
| 299 | break; |
| 300 | case NL80211_CHAN_HT40MINUS: |
| 301 | /* SC */ |
| 302 | mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER; |
| 303 | rtlphy->current_chan_bw = |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 304 | HT_CHANNEL_WIDTH_20_40; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 305 | mac->bw_40 = true; |
| 306 | |
| 307 | /*wide channel */ |
| 308 | wide_chan -= 2; |
| 309 | |
| 310 | break; |
| 311 | case NL80211_CHAN_HT40PLUS: |
| 312 | /* SC */ |
| 313 | mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER; |
| 314 | rtlphy->current_chan_bw = |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 315 | HT_CHANNEL_WIDTH_20_40; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 316 | mac->bw_40 = true; |
| 317 | |
| 318 | /*wide channel */ |
| 319 | wide_chan += 2; |
| 320 | |
| 321 | break; |
| 322 | default: |
| 323 | mac->bw_40 = false; |
| 324 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 325 | "switch case not processed\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | |
| 329 | if (wide_chan <= 0) |
| 330 | wide_chan = 1; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 331 | |
| 332 | /* In scanning, before we go offchannel we may send a ps=1 null |
| 333 | * to AP, and then we may send a ps = 0 null to AP quickly, but |
| 334 | * first null may have caused AP to put lots of packet to hw tx |
| 335 | * buffer. These packets must be tx'd before we go off channel |
| 336 | * so we must delay more time to let AP flush these packets |
| 337 | * before going offchannel, or dis-association or delete BA will |
| 338 | * happen by AP |
| 339 | */ |
Mike McCormack | 9c05044 | 2011-06-20 10:44:58 +0900 | [diff] [blame] | 340 | if (rtlpriv->mac80211.offchan_delay) { |
| 341 | rtlpriv->mac80211.offchan_delay = false; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 342 | mdelay(50); |
| 343 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 344 | rtlphy->current_channel = wide_chan; |
| 345 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 346 | rtlpriv->cfg->ops->switch_channel(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 347 | rtlpriv->cfg->ops->set_channel_access(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 348 | rtlpriv->cfg->ops->set_bw_mode(hw, |
| 349 | hw->conf.channel_type); |
| 350 | } |
| 351 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 352 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static void rtl_op_configure_filter(struct ieee80211_hw *hw, |
| 358 | unsigned int changed_flags, |
| 359 | unsigned int *new_flags, u64 multicast) |
| 360 | { |
| 361 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 362 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 363 | |
| 364 | *new_flags &= RTL_SUPPORTED_FILTERS; |
| 365 | if (!changed_flags) |
| 366 | return; |
| 367 | |
| 368 | /*TODO: we disable broadcase now, so enable here */ |
| 369 | if (changed_flags & FIF_ALLMULTI) { |
| 370 | if (*new_flags & FIF_ALLMULTI) { |
| 371 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] | |
| 372 | rtlpriv->cfg->maps[MAC_RCR_AB]; |
| 373 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 374 | "Enable receive multicast frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 375 | } else { |
| 376 | mac->rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] | |
| 377 | rtlpriv->cfg->maps[MAC_RCR_AB]); |
| 378 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 379 | "Disable receive multicast frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | if (changed_flags & FIF_FCSFAIL) { |
| 384 | if (*new_flags & FIF_FCSFAIL) { |
| 385 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32]; |
| 386 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 387 | "Enable receive FCS error frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 388 | } else { |
| 389 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32]; |
| 390 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 391 | "Disable receive FCS error frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 395 | /* if ssid not set to hw don't check bssid |
| 396 | * here just used for linked scanning, & linked |
| 397 | * and nolink check bssid is set in set network_type */ |
| 398 | if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) && |
| 399 | (mac->link_state >= MAC80211_LINKED)) { |
| 400 | if (mac->opmode != NL80211_IFTYPE_AP) { |
| 401 | if (*new_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 402 | rtlpriv->cfg->ops->set_chk_bssid(hw, false); |
| 403 | } else { |
| 404 | rtlpriv->cfg->ops->set_chk_bssid(hw, true); |
| 405 | } |
| 406 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | if (changed_flags & FIF_CONTROL) { |
| 410 | if (*new_flags & FIF_CONTROL) { |
| 411 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 412 | |
| 413 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 414 | "Enable receive control frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 415 | } else { |
| 416 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 417 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 418 | "Disable receive control frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | if (changed_flags & FIF_OTHER_BSS) { |
| 423 | if (*new_flags & FIF_OTHER_BSS) { |
| 424 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP]; |
| 425 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 426 | "Enable receive other BSS's frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 427 | } else { |
| 428 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP]; |
| 429 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 430 | "Disable receive other BSS's frame\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 431 | } |
| 432 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 433 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 434 | static int rtl_op_sta_add(struct ieee80211_hw *hw, |
| 435 | struct ieee80211_vif *vif, |
| 436 | struct ieee80211_sta *sta) |
| 437 | { |
| 438 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 439 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 440 | struct rtl_sta_info *sta_entry; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 441 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 442 | if (sta) { |
| 443 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 444 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
| 445 | sta_entry->wireless_mode = WIRELESS_MODE_G; |
| 446 | if (sta->supp_rates[0] <= 0xf) |
| 447 | sta_entry->wireless_mode = WIRELESS_MODE_B; |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 448 | if (sta->ht_cap.ht_supported) |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 449 | sta_entry->wireless_mode = WIRELESS_MODE_N_24G; |
| 450 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 451 | sta_entry->wireless_mode = WIRELESS_MODE_A; |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 452 | if (sta->ht_cap.ht_supported) |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 453 | sta_entry->wireless_mode = WIRELESS_MODE_N_24G; |
| 454 | } |
| 455 | |
| 456 | /* I found some times mac80211 give wrong supp_rates for adhoc*/ |
| 457 | if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC) |
| 458 | sta_entry->wireless_mode = WIRELESS_MODE_G; |
| 459 | |
| 460 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 461 | "Add sta addr is %pM\n", sta->addr); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 462 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); |
| 463 | } |
| 464 | return 0; |
| 465 | } |
| 466 | static int rtl_op_sta_remove(struct ieee80211_hw *hw, |
| 467 | struct ieee80211_vif *vif, |
| 468 | struct ieee80211_sta *sta) |
| 469 | { |
| 470 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 471 | struct rtl_sta_info *sta_entry; |
| 472 | if (sta) { |
| 473 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 474 | "Remove sta addr is %pM\n", sta->addr); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 475 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 476 | sta_entry->wireless_mode = 0; |
| 477 | sta_entry->ratr_index = 0; |
| 478 | } |
| 479 | return 0; |
| 480 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 481 | static int _rtl_get_hal_qnum(u16 queue) |
| 482 | { |
| 483 | int qnum; |
| 484 | |
| 485 | switch (queue) { |
| 486 | case 0: |
| 487 | qnum = AC3_VO; |
| 488 | break; |
| 489 | case 1: |
| 490 | qnum = AC2_VI; |
| 491 | break; |
| 492 | case 2: |
| 493 | qnum = AC0_BE; |
| 494 | break; |
| 495 | case 3: |
| 496 | qnum = AC1_BK; |
| 497 | break; |
| 498 | default: |
| 499 | qnum = AC0_BE; |
| 500 | break; |
| 501 | } |
| 502 | return qnum; |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | *for mac80211 VO=0, VI=1, BE=2, BK=3 |
| 507 | *for rtl819x BE=0, BK=1, VI=2, VO=3 |
| 508 | */ |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 509 | static int rtl_op_conf_tx(struct ieee80211_hw *hw, |
| 510 | struct ieee80211_vif *vif, u16 queue, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 511 | const struct ieee80211_tx_queue_params *param) |
| 512 | { |
| 513 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 514 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 515 | int aci; |
| 516 | |
| 517 | if (queue >= AC_MAX) { |
| 518 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 519 | "queue number %d is incorrect!\n", queue); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 520 | return -EINVAL; |
| 521 | } |
| 522 | |
| 523 | aci = _rtl_get_hal_qnum(queue); |
| 524 | mac->ac[aci].aifs = param->aifs; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 525 | mac->ac[aci].cw_min = cpu_to_le16(param->cw_min); |
| 526 | mac->ac[aci].cw_max = cpu_to_le16(param->cw_max); |
| 527 | mac->ac[aci].tx_op = cpu_to_le16(param->txop); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 528 | memcpy(&mac->edca_param[aci], param, sizeof(*param)); |
| 529 | rtlpriv->cfg->ops->set_qos(hw, aci); |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static void rtl_op_bss_info_changed(struct ieee80211_hw *hw, |
| 534 | struct ieee80211_vif *vif, |
| 535 | struct ieee80211_bss_conf *bss_conf, u32 changed) |
| 536 | { |
| 537 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 538 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 539 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 540 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 541 | struct ieee80211_sta *sta = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 542 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 543 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 544 | if ((vif->type == NL80211_IFTYPE_ADHOC) || |
| 545 | (vif->type == NL80211_IFTYPE_AP) || |
| 546 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 547 | if ((changed & BSS_CHANGED_BEACON) || |
| 548 | (changed & BSS_CHANGED_BEACON_ENABLED && |
| 549 | bss_conf->enable_beacon)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 550 | if (mac->beacon_enabled == 0) { |
| 551 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 552 | "BSS_CHANGED_BEACON_ENABLED\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 553 | |
| 554 | /*start hw beacon interrupt. */ |
| 555 | /*rtlpriv->cfg->ops->set_bcn_reg(hw); */ |
| 556 | mac->beacon_enabled = 1; |
| 557 | rtlpriv->cfg->ops->update_interrupt_mask(hw, |
| 558 | rtlpriv->cfg->maps |
| 559 | [RTL_IBSS_INT_MASKS], |
| 560 | 0); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 561 | |
| 562 | if (rtlpriv->cfg->ops->linked_set_reg) |
| 563 | rtlpriv->cfg->ops->linked_set_reg(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 564 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 565 | } |
| 566 | if ((changed & BSS_CHANGED_BEACON_ENABLED && |
| 567 | !bss_conf->enable_beacon)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 568 | if (mac->beacon_enabled == 1) { |
| 569 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 570 | "ADHOC DISABLE BEACON\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 571 | |
| 572 | mac->beacon_enabled = 0; |
| 573 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, |
| 574 | rtlpriv->cfg->maps |
| 575 | [RTL_IBSS_INT_MASKS]); |
| 576 | } |
| 577 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 578 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 579 | RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 580 | "BSS_CHANGED_BEACON_INT\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 581 | mac->beacon_interval = bss_conf->beacon_int; |
| 582 | rtlpriv->cfg->ops->set_bcn_intv(hw); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /*TODO: reference to enum ieee80211_bss_change */ |
| 587 | if (changed & BSS_CHANGED_ASSOC) { |
| 588 | if (bss_conf->assoc) { |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 589 | /* we should reset all sec info & cam |
| 590 | * before set cam after linked, we should not |
| 591 | * reset in disassoc, that will cause tkip->wep |
| 592 | * fail because some flag will be wrong */ |
| 593 | /* reset sec info */ |
| 594 | rtl_cam_reset_sec_info(hw); |
| 595 | /* reset cam to fix wep fail issue |
| 596 | * when change from wpa to wep */ |
| 597 | rtl_cam_reset_all_entry(hw); |
| 598 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 599 | mac->link_state = MAC80211_LINKED; |
| 600 | mac->cnt_after_linked = 0; |
| 601 | mac->assoc_id = bss_conf->aid; |
| 602 | memcpy(mac->bssid, bss_conf->bssid, 6); |
| 603 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 604 | if (rtlpriv->cfg->ops->linked_set_reg) |
| 605 | rtlpriv->cfg->ops->linked_set_reg(hw); |
| 606 | if (mac->opmode == NL80211_IFTYPE_STATION && sta) |
| 607 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 608 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 609 | "BSS_CHANGED_ASSOC\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 610 | } else { |
| 611 | if (mac->link_state == MAC80211_LINKED) |
| 612 | rtl_lps_leave(hw); |
| 613 | |
| 614 | mac->link_state = MAC80211_NOLINK; |
| 615 | memset(mac->bssid, 0, 6); |
George | bac2555 | 2011-09-03 10:58:48 -0500 | [diff] [blame] | 616 | |
| 617 | /* reset sec info */ |
| 618 | rtl_cam_reset_sec_info(hw); |
| 619 | |
| 620 | rtl_cam_reset_all_entry(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 621 | mac->vendor = PEER_UNKNOWN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 622 | |
| 623 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 624 | "BSS_CHANGED_UN_ASSOC\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 629 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 630 | "BSS_CHANGED_ERP_CTS_PROT\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 631 | mac->use_cts_protect = bss_conf->use_cts_prot; |
| 632 | } |
| 633 | |
| 634 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 635 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 636 | "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n", |
| 637 | bss_conf->use_short_preamble); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 638 | |
| 639 | mac->short_preamble = bss_conf->use_short_preamble; |
| 640 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE, |
| 641 | (u8 *) (&mac->short_preamble)); |
| 642 | } |
| 643 | |
| 644 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 645 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 646 | "BSS_CHANGED_ERP_SLOT\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 647 | |
| 648 | if (bss_conf->use_short_slot) |
| 649 | mac->slot_time = RTL_SLOT_TIME_9; |
| 650 | else |
| 651 | mac->slot_time = RTL_SLOT_TIME_20; |
| 652 | |
| 653 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, |
| 654 | (u8 *) (&mac->slot_time)); |
| 655 | } |
| 656 | |
| 657 | if (changed & BSS_CHANGED_HT) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 658 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, "BSS_CHANGED_HT\n"); |
Alessio Igor Bogani | 701c2be | 2011-02-28 18:46:44 +0100 | [diff] [blame] | 659 | rcu_read_lock(); |
Larry Finger | 7101f40 | 2011-06-10 11:05:23 -0500 | [diff] [blame] | 660 | sta = get_sta(hw, vif, bss_conf->bssid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 661 | if (sta) { |
| 662 | if (sta->ht_cap.ampdu_density > |
| 663 | mac->current_ampdu_density) |
| 664 | mac->current_ampdu_density = |
| 665 | sta->ht_cap.ampdu_density; |
| 666 | if (sta->ht_cap.ampdu_factor < |
| 667 | mac->current_ampdu_factor) |
| 668 | mac->current_ampdu_factor = |
| 669 | sta->ht_cap.ampdu_factor; |
| 670 | } |
Alessio Igor Bogani | 701c2be | 2011-02-28 18:46:44 +0100 | [diff] [blame] | 671 | rcu_read_unlock(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 672 | |
| 673 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY, |
| 674 | (u8 *) (&mac->max_mss_density)); |
| 675 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR, |
| 676 | &mac->current_ampdu_factor); |
| 677 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE, |
| 678 | &mac->current_ampdu_density); |
| 679 | } |
| 680 | |
| 681 | if (changed & BSS_CHANGED_BSSID) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 682 | u32 basic_rates; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 683 | |
| 684 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID, |
| 685 | (u8 *) bss_conf->bssid); |
| 686 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 687 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, "%pM\n", |
| 688 | bss_conf->bssid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 689 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 690 | mac->vendor = PEER_UNKNOWN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 691 | memcpy(mac->bssid, bss_conf->bssid, 6); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 692 | rtlpriv->cfg->ops->set_network_type(hw, vif->type); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 693 | |
Alessio Igor Bogani | 701c2be | 2011-02-28 18:46:44 +0100 | [diff] [blame] | 694 | rcu_read_lock(); |
Larry Finger | 7101f40 | 2011-06-10 11:05:23 -0500 | [diff] [blame] | 695 | sta = get_sta(hw, vif, bss_conf->bssid); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 696 | if (!sta) { |
| 697 | rcu_read_unlock(); |
| 698 | goto out; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 699 | } |
| 700 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 701 | if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 702 | mac->mode = WIRELESS_MODE_A; |
| 703 | } else { |
| 704 | if (sta->supp_rates[0] <= 0xf) |
| 705 | mac->mode = WIRELESS_MODE_B; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 706 | else |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 707 | mac->mode = WIRELESS_MODE_G; |
| 708 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 709 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 710 | if (sta->ht_cap.ht_supported) { |
| 711 | if (rtlhal->current_bandtype == BAND_ON_2_4G) |
| 712 | mac->mode = WIRELESS_MODE_N_24G; |
| 713 | else |
| 714 | mac->mode = WIRELESS_MODE_N_5G; |
| 715 | } |
| 716 | |
| 717 | /* just station need it, because ibss & ap mode will |
| 718 | * set in sta_add, and will be NULL here */ |
| 719 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 720 | struct rtl_sta_info *sta_entry; |
| 721 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 722 | sta_entry->wireless_mode = mac->mode; |
| 723 | } |
| 724 | |
| 725 | if (sta->ht_cap.ht_supported) { |
| 726 | mac->ht_enable = true; |
| 727 | |
| 728 | /* |
| 729 | * for cisco 1252 bw20 it's wrong |
| 730 | * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
| 731 | * mac->bw_40 = true; |
| 732 | * } |
| 733 | * */ |
| 734 | } |
| 735 | |
| 736 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 737 | /* for 5G must << RATE_6M_INDEX=4, |
| 738 | * because 5G have no cck rate*/ |
| 739 | if (rtlhal->current_bandtype == BAND_ON_5G) |
| 740 | basic_rates = sta->supp_rates[1] << 4; |
| 741 | else |
| 742 | basic_rates = sta->supp_rates[0]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 743 | |
| 744 | mac->basic_rates = basic_rates; |
| 745 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
| 746 | (u8 *) (&basic_rates)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 747 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 748 | rcu_read_unlock(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /* |
| 752 | * For FW LPS: |
| 753 | * To tell firmware we have connected |
| 754 | * to an AP. For 92SE/CE power save v2. |
| 755 | */ |
| 756 | if (changed & BSS_CHANGED_ASSOC) { |
| 757 | if (bss_conf->assoc) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 758 | if (ppsc->fwctrl_lps) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 759 | u8 mstatus = RT_MEDIA_CONNECT; |
| 760 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 761 | HW_VAR_H2C_FW_JOINBSSRPT, |
| 762 | (u8 *) (&mstatus)); |
| 763 | ppsc->report_linked = true; |
| 764 | } |
| 765 | } else { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 766 | if (ppsc->fwctrl_lps) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 767 | u8 mstatus = RT_MEDIA_DISCONNECT; |
| 768 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 769 | HW_VAR_H2C_FW_JOINBSSRPT, |
| 770 | (u8 *)(&mstatus)); |
| 771 | ppsc->report_linked = false; |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | out: |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 777 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 778 | } |
| 779 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 780 | static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 781 | { |
| 782 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 783 | u64 tsf; |
| 784 | |
| 785 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf)); |
| 786 | return tsf; |
| 787 | } |
| 788 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 789 | static void rtl_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 790 | u64 tsf) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 791 | { |
| 792 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 793 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 794 | u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 795 | |
| 796 | mac->tsf = tsf; |
| 797 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&bibss)); |
| 798 | } |
| 799 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 800 | static void rtl_op_reset_tsf(struct ieee80211_hw *hw, |
| 801 | struct ieee80211_vif *vif) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 802 | { |
| 803 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 804 | u8 tmp = 0; |
| 805 | |
| 806 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *) (&tmp)); |
| 807 | } |
| 808 | |
| 809 | static void rtl_op_sta_notify(struct ieee80211_hw *hw, |
| 810 | struct ieee80211_vif *vif, |
| 811 | enum sta_notify_cmd cmd, |
| 812 | struct ieee80211_sta *sta) |
| 813 | { |
| 814 | switch (cmd) { |
| 815 | case STA_NOTIFY_SLEEP: |
| 816 | break; |
| 817 | case STA_NOTIFY_AWAKE: |
| 818 | break; |
| 819 | default: |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | static int rtl_op_ampdu_action(struct ieee80211_hw *hw, |
| 825 | struct ieee80211_vif *vif, |
| 826 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 827 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 828 | u8 buf_size) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 829 | { |
| 830 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 831 | |
| 832 | switch (action) { |
| 833 | case IEEE80211_AMPDU_TX_START: |
| 834 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 835 | "IEEE80211_AMPDU_TX_START: TID:%d\n", tid); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 836 | return rtl_tx_agg_start(hw, sta, tid, ssn); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 837 | break; |
| 838 | case IEEE80211_AMPDU_TX_STOP: |
| 839 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 840 | "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 841 | return rtl_tx_agg_stop(hw, sta, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 842 | break; |
| 843 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 844 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 845 | "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 846 | rtl_tx_agg_oper(hw, sta, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 847 | break; |
| 848 | case IEEE80211_AMPDU_RX_START: |
| 849 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 850 | "IEEE80211_AMPDU_RX_START:TID:%d\n", tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 851 | break; |
| 852 | case IEEE80211_AMPDU_RX_STOP: |
| 853 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 854 | "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 855 | break; |
| 856 | default: |
| 857 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 858 | "IEEE80211_AMPDU_ERR!!!!:\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 859 | return -EOPNOTSUPP; |
| 860 | } |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static void rtl_op_sw_scan_start(struct ieee80211_hw *hw) |
| 865 | { |
| 866 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 867 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 868 | |
| 869 | mac->act_scanning = true; |
| 870 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 871 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 872 | |
| 873 | if (mac->link_state == MAC80211_LINKED) { |
| 874 | rtl_lps_leave(hw); |
| 875 | mac->link_state = MAC80211_LINKED_SCANNING; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 876 | } else { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 877 | rtl_ips_nic_on(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /* Dual mac */ |
| 881 | rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 882 | |
| 883 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY); |
| 884 | rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP); |
| 885 | } |
| 886 | |
| 887 | static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw) |
| 888 | { |
| 889 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 890 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 891 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 892 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 893 | mac->act_scanning = false; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 894 | /* Dual mac */ |
| 895 | rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false; |
| 896 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 897 | if (mac->link_state == MAC80211_LINKED_SCANNING) { |
| 898 | mac->link_state = MAC80211_LINKED; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 899 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 900 | /* fix fwlps issue */ |
| 901 | rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); |
| 902 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 903 | } |
| 904 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 905 | rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 909 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 910 | struct ieee80211_key_conf *key) |
| 911 | { |
| 912 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 913 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 914 | u8 key_type = NO_ENCRYPTION; |
| 915 | u8 key_idx; |
| 916 | bool group_key = false; |
| 917 | bool wep_only = false; |
| 918 | int err = 0; |
| 919 | u8 mac_addr[ETH_ALEN]; |
| 920 | u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 921 | u8 zero_addr[ETH_ALEN] = { 0 }; |
| 922 | |
| 923 | if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) { |
| 924 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 925 | "not open hw encryption\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 926 | return -ENOSPC; /*User disabled HW-crypto */ |
| 927 | } |
| 928 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 929 | "%s hardware based encryption for keyidx: %d, mac: %pM\n", |
| 930 | cmd == SET_KEY ? "Using" : "Disabling", key->keyidx, |
| 931 | sta ? sta->addr : bcast_addr); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 932 | rtlpriv->sec.being_setkey = true; |
| 933 | rtl_ips_nic_on(hw); |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 934 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 935 | /* <1> get encryption alg */ |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 936 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 937 | switch (key->cipher) { |
| 938 | case WLAN_CIPHER_SUITE_WEP40: |
| 939 | key_type = WEP40_ENCRYPTION; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 940 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 941 | break; |
| 942 | case WLAN_CIPHER_SUITE_WEP104: |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 943 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 944 | key_type = WEP104_ENCRYPTION; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 945 | break; |
| 946 | case WLAN_CIPHER_SUITE_TKIP: |
| 947 | key_type = TKIP_ENCRYPTION; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 948 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 949 | break; |
| 950 | case WLAN_CIPHER_SUITE_CCMP: |
| 951 | key_type = AESCCMP_ENCRYPTION; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 952 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 953 | break; |
| 954 | default: |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 955 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "alg_err:%x!!!!\n", |
| 956 | key->cipher); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 957 | goto out_unlock; |
| 958 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 959 | if (key_type == WEP40_ENCRYPTION || |
| 960 | key_type == WEP104_ENCRYPTION || |
| 961 | mac->opmode == NL80211_IFTYPE_ADHOC) |
| 962 | rtlpriv->sec.use_defaultkey = true; |
| 963 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 964 | /* <2> get key_idx */ |
| 965 | key_idx = (u8) (key->keyidx); |
| 966 | if (key_idx > 3) |
| 967 | goto out_unlock; |
| 968 | /* <3> if pairwise key enable_hw_sec */ |
| 969 | group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 970 | |
| 971 | /* wep always be group key, but there are two conditions: |
| 972 | * 1) wep only: is just for wep enc, in this condition |
| 973 | * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION |
| 974 | * will be true & enable_hw_sec will be set when wep |
| 975 | * ke setting. |
| 976 | * 2) wep(group) + AES(pairwise): some AP like cisco |
| 977 | * may use it, in this condition enable_hw_sec will not |
| 978 | * be set when wep key setting */ |
| 979 | /* we must reset sec_info after lingked before set key, |
| 980 | * or some flag will be wrong*/ |
| 981 | if (mac->opmode == NL80211_IFTYPE_AP) { |
| 982 | if (!group_key || key_type == WEP40_ENCRYPTION || |
| 983 | key_type == WEP104_ENCRYPTION) { |
| 984 | if (group_key) |
| 985 | wep_only = true; |
| 986 | rtlpriv->cfg->ops->enable_hw_sec(hw); |
| 987 | } |
| 988 | } else { |
| 989 | if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) || |
| 990 | rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) { |
| 991 | if (rtlpriv->sec.pairwise_enc_algorithm == |
| 992 | NO_ENCRYPTION && |
| 993 | (key_type == WEP40_ENCRYPTION || |
| 994 | key_type == WEP104_ENCRYPTION)) |
| 995 | wep_only = true; |
| 996 | rtlpriv->sec.pairwise_enc_algorithm = key_type; |
| 997 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 998 | "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n", |
| 999 | key_type); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1000 | rtlpriv->cfg->ops->enable_hw_sec(hw); |
| 1001 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1002 | } |
| 1003 | /* <4> set key based on cmd */ |
| 1004 | switch (cmd) { |
| 1005 | case SET_KEY: |
| 1006 | if (wep_only) { |
| 1007 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1008 | "set WEP(group/pairwise) key\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1009 | /* Pairwise key with an assigned MAC address. */ |
| 1010 | rtlpriv->sec.pairwise_enc_algorithm = key_type; |
| 1011 | rtlpriv->sec.group_enc_algorithm = key_type; |
| 1012 | /*set local buf about wep key. */ |
| 1013 | memcpy(rtlpriv->sec.key_buf[key_idx], |
| 1014 | key->key, key->keylen); |
| 1015 | rtlpriv->sec.key_len[key_idx] = key->keylen; |
| 1016 | memcpy(mac_addr, zero_addr, ETH_ALEN); |
| 1017 | } else if (group_key) { /* group key */ |
| 1018 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1019 | "set group key\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1020 | /* group key */ |
| 1021 | rtlpriv->sec.group_enc_algorithm = key_type; |
| 1022 | /*set local buf about group key. */ |
| 1023 | memcpy(rtlpriv->sec.key_buf[key_idx], |
| 1024 | key->key, key->keylen); |
| 1025 | rtlpriv->sec.key_len[key_idx] = key->keylen; |
| 1026 | memcpy(mac_addr, bcast_addr, ETH_ALEN); |
| 1027 | } else { /* pairwise key */ |
| 1028 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1029 | "set pairwise key\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1030 | if (!sta) { |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 1031 | RT_ASSERT(false, |
| 1032 | "pairwise key without mac_addr\n"); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1033 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1034 | err = -EOPNOTSUPP; |
| 1035 | goto out_unlock; |
| 1036 | } |
| 1037 | /* Pairwise key with an assigned MAC address. */ |
| 1038 | rtlpriv->sec.pairwise_enc_algorithm = key_type; |
| 1039 | /*set local buf about pairwise key. */ |
| 1040 | memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX], |
| 1041 | key->key, key->keylen); |
| 1042 | rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen; |
| 1043 | rtlpriv->sec.pairwise_key = |
| 1044 | rtlpriv->sec.key_buf[PAIRWISE_KEYIDX]; |
| 1045 | memcpy(mac_addr, sta->addr, ETH_ALEN); |
| 1046 | } |
| 1047 | rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr, |
| 1048 | group_key, key_type, wep_only, |
| 1049 | false); |
| 1050 | /* <5> tell mac80211 do something: */ |
| 1051 | /*must use sw generate IV, or can not work !!!!. */ |
| 1052 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1053 | key->hw_key_idx = key_idx; |
| 1054 | if (key_type == TKIP_ENCRYPTION) |
| 1055 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 1056 | break; |
| 1057 | case DISABLE_KEY: |
| 1058 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1059 | "disable key delete one entry\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1060 | /*set local buf about wep key. */ |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1061 | if (mac->opmode == NL80211_IFTYPE_AP) { |
| 1062 | if (sta) |
| 1063 | rtl_cam_del_entry(hw, sta->addr); |
| 1064 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1065 | memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen); |
| 1066 | rtlpriv->sec.key_len[key_idx] = 0; |
| 1067 | memcpy(mac_addr, zero_addr, ETH_ALEN); |
| 1068 | /* |
| 1069 | *mac80211 will delete entrys one by one, |
| 1070 | *so don't use rtl_cam_reset_all_entry |
| 1071 | *or clear all entry here. |
| 1072 | */ |
| 1073 | rtl_cam_delete_one_entry(hw, mac_addr, key_idx); |
George | bac2555 | 2011-09-03 10:58:48 -0500 | [diff] [blame] | 1074 | |
| 1075 | rtl_cam_reset_sec_info(hw); |
| 1076 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1077 | break; |
| 1078 | default: |
| 1079 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1080 | "cmd_err:%x!!!!\n", cmd); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1081 | } |
| 1082 | out_unlock: |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1083 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1084 | rtlpriv->sec.being_setkey = false; |
| 1085 | return err; |
| 1086 | } |
| 1087 | |
| 1088 | static void rtl_op_rfkill_poll(struct ieee80211_hw *hw) |
| 1089 | { |
| 1090 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1091 | |
| 1092 | bool radio_state; |
| 1093 | bool blocked; |
| 1094 | u8 valid = 0; |
| 1095 | |
| 1096 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 1097 | return; |
| 1098 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1099 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1100 | |
| 1101 | /*if Radio On return true here */ |
| 1102 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
| 1103 | |
| 1104 | if (valid) { |
| 1105 | if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) { |
| 1106 | rtlpriv->rfkill.rfkill_state = radio_state; |
| 1107 | |
| 1108 | RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1109 | "wireless radio switch turned %s\n", |
| 1110 | radio_state ? "on" : "off"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1111 | |
| 1112 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; |
| 1113 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
| 1114 | } |
| 1115 | } |
| 1116 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1117 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1118 | } |
| 1119 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1120 | /* this function is called by mac80211 to flush tx buffer |
| 1121 | * before switch channle or power save, or tx buffer packet |
| 1122 | * maybe send after offchannel or rf sleep, this may cause |
| 1123 | * dis-association by AP */ |
| 1124 | static void rtl_op_flush(struct ieee80211_hw *hw, bool drop) |
| 1125 | { |
| 1126 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1127 | |
| 1128 | if (rtlpriv->intf_ops->flush) |
| 1129 | rtlpriv->intf_ops->flush(hw, drop); |
| 1130 | } |
| 1131 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1132 | const struct ieee80211_ops rtl_ops = { |
| 1133 | .start = rtl_op_start, |
| 1134 | .stop = rtl_op_stop, |
| 1135 | .tx = rtl_op_tx, |
| 1136 | .add_interface = rtl_op_add_interface, |
| 1137 | .remove_interface = rtl_op_remove_interface, |
| 1138 | .config = rtl_op_config, |
| 1139 | .configure_filter = rtl_op_configure_filter, |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1140 | .sta_add = rtl_op_sta_add, |
| 1141 | .sta_remove = rtl_op_sta_remove, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1142 | .set_key = rtl_op_set_key, |
| 1143 | .conf_tx = rtl_op_conf_tx, |
| 1144 | .bss_info_changed = rtl_op_bss_info_changed, |
| 1145 | .get_tsf = rtl_op_get_tsf, |
| 1146 | .set_tsf = rtl_op_set_tsf, |
| 1147 | .reset_tsf = rtl_op_reset_tsf, |
| 1148 | .sta_notify = rtl_op_sta_notify, |
| 1149 | .ampdu_action = rtl_op_ampdu_action, |
| 1150 | .sw_scan_start = rtl_op_sw_scan_start, |
| 1151 | .sw_scan_complete = rtl_op_sw_scan_complete, |
| 1152 | .rfkill_poll = rtl_op_rfkill_poll, |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1153 | .flush = rtl_op_flush, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1154 | }; |