Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include <net/mac80211.h> |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 31 | #include <linux/etherdevice.h> |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 32 | #include <linux/sched.h> |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 33 | #include <linux/lockdep.h> |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 34 | |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 35 | #include "iwl-dev.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 36 | #include "iwl-core.h" |
| 37 | #include "iwl-sta.h" |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 38 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 39 | /* priv->sta_lock must be held */ |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 40 | static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) |
| 41 | { |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 42 | |
| 43 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) |
| 44 | IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u addr %pM\n", |
| 45 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 46 | |
| 47 | if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) { |
| 48 | IWL_DEBUG_ASSOC(priv, |
| 49 | "STA id %u addr %pM already present in uCode (according to driver)\n", |
| 50 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 51 | } else { |
| 52 | priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE; |
| 53 | IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n", |
| 54 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | static void iwl_process_add_sta_resp(struct iwl_priv *priv, |
| 59 | struct iwl_addsta_cmd *addsta, |
| 60 | struct iwl_rx_packet *pkt, |
| 61 | bool sync) |
| 62 | { |
| 63 | u8 sta_id = addsta->sta.sta_id; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 64 | unsigned long flags; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 65 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 66 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 67 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 68 | pkt->hdr.flags); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", |
| 73 | sta_id); |
| 74 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 75 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 76 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 77 | switch (pkt->u.add_sta.status) { |
| 78 | case ADD_STA_SUCCESS_MSK: |
| 79 | IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n"); |
| 80 | iwl_sta_ucode_activate(priv, sta_id); |
| 81 | break; |
| 82 | case ADD_STA_NO_ROOM_IN_TABLE: |
| 83 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 84 | sta_id); |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 85 | break; |
| 86 | case ADD_STA_NO_BLOCK_ACK_RESOURCE: |
| 87 | IWL_ERR(priv, "Adding station %d failed, no block ack resource.\n", |
| 88 | sta_id); |
| 89 | break; |
| 90 | case ADD_STA_MODIFY_NON_EXIST_STA: |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 91 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 92 | sta_id); |
| 93 | break; |
| 94 | default: |
| 95 | IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n", |
| 96 | pkt->u.add_sta.status); |
| 97 | break; |
| 98 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 99 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 100 | IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n", |
| 101 | priv->stations[sta_id].sta.mode == |
| 102 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 103 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 104 | |
| 105 | /* |
| 106 | * XXX: The MAC address in the command buffer is often changed from |
| 107 | * the original sent to the device. That is, the MAC address |
| 108 | * written to the command buffer often is not the same MAC adress |
| 109 | * read from the command buffer when the command returns. This |
| 110 | * issue has not yet been resolved and this debugging is left to |
| 111 | * observe the problem. |
| 112 | */ |
| 113 | IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n", |
| 114 | priv->stations[sta_id].sta.mode == |
| 115 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 116 | addsta->sta.addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 117 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 118 | } |
| 119 | |
Johannes Berg | 5696aea | 2009-07-24 11:13:06 -0700 | [diff] [blame] | 120 | static void iwl_add_sta_callback(struct iwl_priv *priv, |
| 121 | struct iwl_device_cmd *cmd, |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 122 | struct iwl_rx_packet *pkt) |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 123 | { |
Tomas Winkler | 3257e5d | 2008-10-14 12:32:43 -0700 | [diff] [blame] | 124 | struct iwl_addsta_cmd *addsta = |
| 125 | (struct iwl_addsta_cmd *)cmd->cmd.payload; |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 126 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 127 | iwl_process_add_sta_resp(priv, addsta, pkt, false); |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 128 | |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 129 | } |
| 130 | |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 131 | int iwl_send_add_sta(struct iwl_priv *priv, |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 132 | struct iwl_addsta_cmd *sta, u8 flags) |
| 133 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 134 | struct iwl_rx_packet *pkt = NULL; |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 135 | int ret = 0; |
| 136 | u8 data[sizeof(*sta)]; |
| 137 | struct iwl_host_cmd cmd = { |
| 138 | .id = REPLY_ADD_STA, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 139 | .flags = flags, |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 140 | .data = data, |
| 141 | }; |
Reinette Chatre | f875f51 | 2010-04-05 10:43:10 -0700 | [diff] [blame] | 142 | u8 sta_id __maybe_unused = sta->sta.sta_id; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 143 | |
| 144 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", |
| 145 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 146 | |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 147 | if (flags & CMD_ASYNC) |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 148 | cmd.callback = iwl_add_sta_callback; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 149 | else { |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 150 | cmd.flags |= CMD_WANT_SKB; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 151 | might_sleep(); |
| 152 | } |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 153 | |
| 154 | cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data); |
| 155 | ret = iwl_send_cmd(priv, &cmd); |
| 156 | |
| 157 | if (ret || (flags & CMD_ASYNC)) |
| 158 | return ret; |
| 159 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 160 | if (ret == 0) { |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 161 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
| 162 | iwl_process_add_sta_resp(priv, sta, pkt, true); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 163 | } |
Zhu Yi | 64a76b5 | 2009-12-10 14:37:21 -0800 | [diff] [blame] | 164 | iwl_free_pages(priv, cmd.reply_page); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 165 | |
| 166 | return ret; |
| 167 | } |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 168 | EXPORT_SYMBOL(iwl_send_add_sta); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 169 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 170 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 171 | struct ieee80211_sta_ht_cap *sta_ht_inf) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 172 | { |
| 173 | __le32 sta_flags; |
| 174 | u8 mimo_ps_mode; |
| 175 | |
| 176 | if (!sta_ht_inf || !sta_ht_inf->ht_supported) |
| 177 | goto done; |
| 178 | |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 179 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; |
Wey-Yi Guy | 3f3e037 | 2009-10-30 14:36:17 -0700 | [diff] [blame] | 180 | IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n", |
| 181 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ? |
| 182 | "static" : |
| 183 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ? |
| 184 | "dynamic" : "disabled"); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 185 | |
| 186 | sta_flags = priv->stations[index].sta.station_flags; |
| 187 | |
| 188 | sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); |
| 189 | |
| 190 | switch (mimo_ps_mode) { |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 191 | case WLAN_HT_CAP_SM_PS_STATIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 192 | sta_flags |= STA_FLG_MIMO_DIS_MSK; |
| 193 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 194 | case WLAN_HT_CAP_SM_PS_DYNAMIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 195 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
| 196 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 197 | case WLAN_HT_CAP_SM_PS_DISABLED: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 198 | break; |
| 199 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 200 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 201 | break; |
| 202 | } |
| 203 | |
| 204 | sta_flags |= cpu_to_le32( |
| 205 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); |
| 206 | |
| 207 | sta_flags |= cpu_to_le32( |
| 208 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
| 209 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 210 | if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf)) |
| 211 | sta_flags |= STA_FLG_HT40_EN_MSK; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 212 | else |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 213 | sta_flags &= ~STA_FLG_HT40_EN_MSK; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 214 | |
| 215 | priv->stations[index].sta.station_flags = sta_flags; |
| 216 | done: |
| 217 | return; |
| 218 | } |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 219 | |
| 220 | /** |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 221 | * iwl_prep_station - Prepare station information for addition |
| 222 | * |
| 223 | * should be called with sta_lock held |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 224 | */ |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 225 | static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr, |
| 226 | bool is_ap, |
| 227 | struct ieee80211_sta_ht_cap *ht_info) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 228 | { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 229 | struct iwl_station_entry *station; |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 230 | int i; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 231 | u8 sta_id = IWL_INVALID_STATION; |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 232 | u16 rate; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 233 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 234 | if (is_ap) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 235 | sta_id = IWL_AP_ID; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 236 | else if (is_broadcast_ether_addr(addr)) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 237 | sta_id = priv->hw_params.bcast_sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 238 | else |
| 239 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
| 240 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 241 | addr)) { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 242 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 243 | break; |
| 244 | } |
| 245 | |
| 246 | if (!priv->stations[i].used && |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 247 | sta_id == IWL_INVALID_STATION) |
| 248 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 249 | } |
| 250 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 251 | /* |
| 252 | * These two conditions have the same outcome, but keep them |
| 253 | * separate |
| 254 | */ |
| 255 | if (unlikely(sta_id == IWL_INVALID_STATION)) |
| 256 | return sta_id; |
| 257 | |
| 258 | /* |
| 259 | * uCode is not able to deal with multiple requests to add a |
| 260 | * station. Keep track if one is in progress so that we do not send |
| 261 | * another. |
| 262 | */ |
| 263 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 264 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", |
| 265 | sta_id); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 266 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 267 | } |
| 268 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 269 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 270 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 271 | !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 272 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", |
| 273 | sta_id, addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 274 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 275 | } |
| 276 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 277 | station = &priv->stations[sta_id]; |
| 278 | station->used = IWL_STA_DRIVER_ACTIVE; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 279 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 280 | sta_id, addr); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 281 | priv->num_stations++; |
| 282 | |
| 283 | /* Set up the REPLY_ADD_STA command to send to device */ |
| 284 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
| 285 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 286 | station->sta.mode = 0; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 287 | station->sta.sta.sta_id = sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 288 | station->sta.station_flags = 0; |
| 289 | |
Johannes Berg | 63d4176 | 2010-04-30 11:30:50 -0700 | [diff] [blame] | 290 | /* |
| 291 | * OK to call unconditionally, since local stations (IBSS BSSID |
| 292 | * STA and broadcast STA) pass in a NULL ht_info, and mac80211 |
| 293 | * doesn't allow HT IBSS. |
| 294 | */ |
| 295 | iwl_set_ht_add_station(priv, sta_id, ht_info); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 296 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 297 | /* 3945 only */ |
| 298 | rate = (priv->band == IEEE80211_BAND_5GHZ) ? |
| 299 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP; |
| 300 | /* Turn on both antennas for the station... */ |
| 301 | station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK); |
| 302 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 303 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 304 | |
| 305 | } |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 306 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 307 | #define STA_WAIT_TIMEOUT (HZ/2) |
| 308 | |
| 309 | /** |
| 310 | * iwl_add_station_common - |
| 311 | */ |
| 312 | int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, |
| 313 | bool is_ap, |
| 314 | struct ieee80211_sta_ht_cap *ht_info, |
| 315 | u8 *sta_id_r) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 316 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 317 | unsigned long flags_spin; |
| 318 | int ret = 0; |
| 319 | u8 sta_id; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 320 | struct iwl_addsta_cmd sta_cmd; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 321 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 322 | *sta_id_r = 0; |
| 323 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 324 | sta_id = iwl_prep_station(priv, addr, is_ap, ht_info); |
| 325 | if (sta_id == IWL_INVALID_STATION) { |
| 326 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", |
| 327 | addr); |
| 328 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 329 | return -EINVAL; |
| 330 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 331 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 332 | /* |
| 333 | * uCode is not able to deal with multiple requests to add a |
| 334 | * station. Keep track if one is in progress so that we do not send |
| 335 | * another. |
| 336 | */ |
| 337 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 338 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", |
| 339 | sta_id); |
| 340 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 341 | return -EEXIST; |
| 342 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 343 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 344 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 345 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
| 346 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", |
| 347 | sta_id, addr); |
| 348 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 349 | return -EEXIST; |
| 350 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 351 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 352 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 353 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 354 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 355 | |
| 356 | /* Add station to device's station table */ |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 357 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 358 | if (ret) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 359 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 360 | IWL_ERR(priv, "Adding station %pM failed.\n", |
| 361 | priv->stations[sta_id].sta.sta.addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 362 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 363 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 364 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 365 | } |
| 366 | *sta_id_r = sta_id; |
| 367 | return ret; |
| 368 | } |
| 369 | EXPORT_SYMBOL(iwl_add_station_common); |
| 370 | |
Johannes Berg | a6a0345 | 2010-04-29 10:41:07 -0700 | [diff] [blame] | 371 | static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv, |
| 372 | u8 sta_id) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 373 | { |
| 374 | int i, r; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 375 | struct iwl_link_quality_cmd *link_cmd; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 376 | u32 rate_flags; |
| 377 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 378 | link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL); |
| 379 | if (!link_cmd) { |
| 380 | IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n"); |
| 381 | return NULL; |
| 382 | } |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 383 | /* Set up the rate scaling to start at selected rate, fall back |
| 384 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
Johannes Berg | 156b70d | 2010-04-28 14:44:45 -0700 | [diff] [blame] | 385 | if (priv->band == IEEE80211_BAND_5GHZ) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 386 | r = IWL_RATE_6M_INDEX; |
| 387 | else |
| 388 | r = IWL_RATE_1M_INDEX; |
| 389 | |
| 390 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 391 | rate_flags = 0; |
| 392 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) |
| 393 | rate_flags |= RATE_MCS_CCK_MSK; |
| 394 | |
| 395 | rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) << |
| 396 | RATE_MCS_ANT_POS; |
| 397 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 398 | link_cmd->rs_table[i].rate_n_flags = |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 399 | iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); |
| 400 | r = iwl_get_prev_ieee_rate(r); |
| 401 | } |
| 402 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 403 | link_cmd->general_params.single_stream_ant_msk = |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 404 | first_antenna(priv->hw_params.valid_tx_ant); |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 405 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 406 | link_cmd->general_params.dual_stream_ant_msk = |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 407 | priv->hw_params.valid_tx_ant & |
| 408 | ~first_antenna(priv->hw_params.valid_tx_ant); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 409 | if (!link_cmd->general_params.dual_stream_ant_msk) { |
| 410 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 411 | } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) { |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 412 | link_cmd->general_params.dual_stream_ant_msk = |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 413 | priv->hw_params.valid_tx_ant; |
| 414 | } |
| 415 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 416 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
| 417 | link_cmd->agg_params.agg_time_limit = |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 418 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
| 419 | |
Johannes Berg | 156b70d | 2010-04-28 14:44:45 -0700 | [diff] [blame] | 420 | link_cmd->sta_id = sta_id; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 421 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 422 | return link_cmd; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /* |
Johannes Berg | 57f8db8 | 2010-04-30 11:30:49 -0700 | [diff] [blame] | 426 | * iwl_add_bssid_station - Add the special IBSS BSSID station |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 427 | * |
| 428 | * Function sleeps. |
| 429 | */ |
Johannes Berg | 57f8db8 | 2010-04-30 11:30:49 -0700 | [diff] [blame] | 430 | int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs, |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 431 | u8 *sta_id_r) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 432 | { |
| 433 | int ret; |
| 434 | u8 sta_id; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 435 | struct iwl_link_quality_cmd *link_cmd; |
| 436 | unsigned long flags; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 437 | |
Dan Carpenter | 96900c7 | 2010-05-14 16:53:46 +0200 | [diff] [blame] | 438 | if (sta_id_r) |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 439 | *sta_id_r = IWL_INVALID_STATION; |
| 440 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 441 | ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id); |
| 442 | if (ret) { |
| 443 | IWL_ERR(priv, "Unable to add station %pM\n", addr); |
| 444 | return ret; |
| 445 | } |
| 446 | |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 447 | if (sta_id_r) |
| 448 | *sta_id_r = sta_id; |
| 449 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 450 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 451 | priv->stations[sta_id].used |= IWL_STA_LOCAL; |
| 452 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 453 | |
| 454 | if (init_rs) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 455 | /* Set up default rate scaling table in device's station table */ |
Johannes Berg | a6a0345 | 2010-04-29 10:41:07 -0700 | [diff] [blame] | 456 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 457 | if (!link_cmd) { |
| 458 | IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n", |
| 459 | addr); |
| 460 | return -ENOMEM; |
| 461 | } |
Johannes Berg | a6a0345 | 2010-04-29 10:41:07 -0700 | [diff] [blame] | 462 | |
| 463 | ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true); |
| 464 | if (ret) |
| 465 | IWL_ERR(priv, "Link quality command failed (%d)\n", ret); |
| 466 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 467 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 468 | priv->stations[sta_id].lq = link_cmd; |
| 469 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 470 | } |
| 471 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 472 | return 0; |
| 473 | } |
Johannes Berg | 57f8db8 | 2010-04-30 11:30:49 -0700 | [diff] [blame] | 474 | EXPORT_SYMBOL(iwl_add_bssid_station); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 475 | |
| 476 | /** |
| 477 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station |
| 478 | * |
| 479 | * priv->sta_lock must be held |
| 480 | */ |
| 481 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) |
| 482 | { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 483 | /* Ucode must be active and driver must be non active */ |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 484 | if ((priv->stations[sta_id].used & |
| 485 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 486 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 487 | |
| 488 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; |
| 489 | |
| 490 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 491 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 492 | } |
| 493 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 494 | static int iwl_send_remove_station(struct iwl_priv *priv, |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 495 | const u8 *addr, int sta_id) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 496 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 497 | struct iwl_rx_packet *pkt; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 498 | int ret; |
| 499 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 500 | unsigned long flags_spin; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 501 | struct iwl_rem_sta_cmd rm_sta_cmd; |
| 502 | |
| 503 | struct iwl_host_cmd cmd = { |
| 504 | .id = REPLY_REMOVE_STA, |
| 505 | .len = sizeof(struct iwl_rem_sta_cmd), |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 506 | .flags = CMD_SYNC, |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 507 | .data = &rm_sta_cmd, |
| 508 | }; |
| 509 | |
| 510 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); |
| 511 | rm_sta_cmd.num_sta = 1; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 512 | memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 513 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 514 | cmd.flags |= CMD_WANT_SKB; |
| 515 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 516 | ret = iwl_send_cmd(priv, &cmd); |
| 517 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 518 | if (ret) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 519 | return ret; |
| 520 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 521 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
| 522 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 523 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 524 | pkt->hdr.flags); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 525 | ret = -EIO; |
| 526 | } |
| 527 | |
| 528 | if (!ret) { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 529 | switch (pkt->u.rem_sta.status) { |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 530 | case REM_STA_SUCCESS_MSK: |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 531 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 532 | iwl_sta_ucode_deactivate(priv, sta_id); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 533 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 534 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 535 | break; |
| 536 | default: |
| 537 | ret = -EIO; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 538 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 539 | break; |
| 540 | } |
| 541 | } |
Zhu Yi | 64a76b5 | 2009-12-10 14:37:21 -0800 | [diff] [blame] | 542 | iwl_free_pages(priv, cmd.reply_page); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 543 | |
| 544 | return ret; |
| 545 | } |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 546 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 547 | /** |
| 548 | * iwl_remove_station - Remove driver's knowledge of station. |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 549 | */ |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 550 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, |
| 551 | const u8 *addr) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 552 | { |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 553 | unsigned long flags; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 554 | |
| 555 | if (!iwl_is_ready(priv)) { |
| 556 | IWL_DEBUG_INFO(priv, |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 557 | "Unable to remove station %pM, device not ready.\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 558 | addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 559 | /* |
| 560 | * It is typical for stations to be removed when we are |
| 561 | * going down. Return success since device will be down |
| 562 | * soon anyway |
| 563 | */ |
| 564 | return 0; |
| 565 | } |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 566 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 567 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 568 | sta_id, addr); |
| 569 | |
| 570 | if (WARN_ON(sta_id == IWL_INVALID_STATION)) |
| 571 | return -EINVAL; |
| 572 | |
| 573 | spin_lock_irqsave(&priv->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 574 | |
| 575 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 576 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 577 | addr); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 578 | goto out_err; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 579 | } |
| 580 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 581 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 582 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 583 | addr); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 584 | goto out_err; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 585 | } |
| 586 | |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 587 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { |
| 588 | kfree(priv->stations[sta_id].lq); |
| 589 | priv->stations[sta_id].lq = NULL; |
| 590 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 591 | |
| 592 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 593 | |
| 594 | priv->num_stations--; |
| 595 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 596 | BUG_ON(priv->num_stations < 0); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 597 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 598 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 599 | |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 600 | return iwl_send_remove_station(priv, addr, sta_id); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 601 | out_err: |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 602 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 603 | return -EINVAL; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 604 | } |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 605 | EXPORT_SYMBOL_GPL(iwl_remove_station); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 606 | |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 607 | /** |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 608 | * iwl_clear_ucode_stations - clear ucode station table bits |
| 609 | * |
| 610 | * This function clears all the bits in the driver indicating |
| 611 | * which stations are active in the ucode. Call when something |
| 612 | * other than explicit station management would cause this in |
| 613 | * the ucode, e.g. unassociated RXON. |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 614 | */ |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 615 | void iwl_clear_ucode_stations(struct iwl_priv *priv) |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 616 | { |
Mohamed Abbas | 48676eb | 2009-03-11 11:17:59 -0700 | [diff] [blame] | 617 | int i; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 618 | unsigned long flags_spin; |
| 619 | bool cleared = false; |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 620 | |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 621 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n"); |
Mohamed Abbas | 48676eb | 2009-03-11 11:17:59 -0700 | [diff] [blame] | 622 | |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 623 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 624 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 625 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { |
| 626 | IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); |
| 627 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
| 628 | cleared = true; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 632 | |
| 633 | if (!cleared) |
| 634 | IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n"); |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 635 | } |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 636 | EXPORT_SYMBOL(iwl_clear_ucode_stations); |
| 637 | |
| 638 | /** |
| 639 | * iwl_restore_stations() - Restore driver known stations to device |
| 640 | * |
| 641 | * All stations considered active by driver, but not present in ucode, is |
| 642 | * restored. |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 643 | * |
| 644 | * Function sleeps. |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 645 | */ |
| 646 | void iwl_restore_stations(struct iwl_priv *priv) |
| 647 | { |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 648 | struct iwl_addsta_cmd sta_cmd; |
| 649 | struct iwl_link_quality_cmd lq; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 650 | unsigned long flags_spin; |
| 651 | int i; |
| 652 | bool found = false; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 653 | int ret; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 654 | bool send_lq; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 655 | |
| 656 | if (!iwl_is_ready(priv)) { |
| 657 | IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n"); |
| 658 | return; |
| 659 | } |
| 660 | |
| 661 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); |
| 662 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 663 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 664 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && |
| 665 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { |
| 666 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", |
| 667 | priv->stations[i].sta.sta.addr); |
| 668 | priv->stations[i].sta.mode = 0; |
| 669 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; |
| 670 | found = true; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 675 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 676 | memcpy(&sta_cmd, &priv->stations[i].sta, |
| 677 | sizeof(struct iwl_addsta_cmd)); |
| 678 | send_lq = false; |
| 679 | if (priv->stations[i].lq) { |
| 680 | memcpy(&lq, priv->stations[i].lq, |
| 681 | sizeof(struct iwl_link_quality_cmd)); |
| 682 | send_lq = true; |
| 683 | } |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 684 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 685 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 686 | if (ret) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 687 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 688 | IWL_ERR(priv, "Adding station %pM failed.\n", |
| 689 | priv->stations[i].sta.sta.addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 690 | priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 691 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 692 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 693 | } |
| 694 | /* |
| 695 | * Rate scaling has already been initialized, send |
| 696 | * current LQ command |
| 697 | */ |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 698 | if (send_lq) |
| 699 | iwl_send_lq_cmd(priv, &lq, CMD_SYNC, true); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 700 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 701 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 706 | if (!found) |
| 707 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n"); |
| 708 | else |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 709 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n"); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 710 | } |
| 711 | EXPORT_SYMBOL(iwl_restore_stations); |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 712 | |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 713 | int iwl_get_free_ucode_key_index(struct iwl_priv *priv) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 714 | { |
| 715 | int i; |
| 716 | |
| 717 | for (i = 0; i < STA_KEY_MAX_NUM; i++) |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 718 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 719 | return i; |
| 720 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 721 | return WEP_INVALID_OFFSET; |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 722 | } |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 723 | EXPORT_SYMBOL(iwl_get_free_ucode_key_index); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 724 | |
Johannes Berg | 335348b | 2010-03-30 10:11:46 -0700 | [diff] [blame] | 725 | static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 726 | { |
| 727 | int i, not_empty = 0; |
| 728 | u8 buff[sizeof(struct iwl_wep_cmd) + |
| 729 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; |
| 730 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; |
| 731 | size_t cmd_size = sizeof(struct iwl_wep_cmd); |
| 732 | struct iwl_host_cmd cmd = { |
| 733 | .id = REPLY_WEPKEY, |
| 734 | .data = wep_cmd, |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 735 | .flags = CMD_SYNC, |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 736 | }; |
| 737 | |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 738 | might_sleep(); |
| 739 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 740 | memset(wep_cmd, 0, cmd_size + |
| 741 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); |
| 742 | |
| 743 | for (i = 0; i < WEP_KEYS_MAX ; i++) { |
| 744 | wep_cmd->key[i].key_index = i; |
| 745 | if (priv->wep_keys[i].key_size) { |
| 746 | wep_cmd->key[i].key_offset = i; |
| 747 | not_empty = 1; |
| 748 | } else { |
| 749 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 750 | } |
| 751 | |
| 752 | wep_cmd->key[i].key_size = priv->wep_keys[i].key_size; |
| 753 | memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key, |
| 754 | priv->wep_keys[i].key_size); |
| 755 | } |
| 756 | |
| 757 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 758 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 759 | |
| 760 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; |
| 761 | |
| 762 | cmd.len = cmd_size; |
| 763 | |
| 764 | if (not_empty || send_if_empty) |
| 765 | return iwl_send_cmd(priv, &cmd); |
| 766 | else |
| 767 | return 0; |
| 768 | } |
Johannes Berg | 335348b | 2010-03-30 10:11:46 -0700 | [diff] [blame] | 769 | |
| 770 | int iwl_restore_default_wep_keys(struct iwl_priv *priv) |
| 771 | { |
| 772 | WARN_ON(!mutex_is_locked(&priv->mutex)); |
| 773 | |
| 774 | return iwl_send_static_wepkey_cmd(priv, 0); |
| 775 | } |
| 776 | EXPORT_SYMBOL(iwl_restore_default_wep_keys); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 777 | |
| 778 | int iwl_remove_default_wep_key(struct iwl_priv *priv, |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 779 | struct ieee80211_key_conf *keyconf) |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 780 | { |
| 781 | int ret; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 782 | |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 783 | WARN_ON(!mutex_is_locked(&priv->mutex)); |
| 784 | |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 785 | IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", |
| 786 | keyconf->keyidx); |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 787 | |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 788 | memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 789 | if (iwl_is_rfkill(priv)) { |
| 790 | IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 791 | /* but keys in device are clear anyway so return success */ |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 792 | return 0; |
| 793 | } |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 794 | ret = iwl_send_static_wepkey_cmd(priv, 1); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 795 | IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 796 | keyconf->keyidx, ret); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 797 | |
| 798 | return ret; |
| 799 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 800 | EXPORT_SYMBOL(iwl_remove_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 801 | |
| 802 | int iwl_set_default_wep_key(struct iwl_priv *priv, |
| 803 | struct ieee80211_key_conf *keyconf) |
| 804 | { |
| 805 | int ret; |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 806 | |
| 807 | WARN_ON(!mutex_is_locked(&priv->mutex)); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 808 | |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 809 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
| 810 | keyconf->keylen != WEP_KEY_LEN_64) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 811 | IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen); |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 812 | return -EINVAL; |
| 813 | } |
| 814 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 815 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 816 | keyconf->hw_key_idx = HW_KEY_DEFAULT; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 817 | priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; |
| 818 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 819 | priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
| 820 | memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, |
| 821 | keyconf->keylen); |
| 822 | |
| 823 | ret = iwl_send_static_wepkey_cmd(priv, 0); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 824 | IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 825 | keyconf->keylen, keyconf->keyidx, ret); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 826 | |
| 827 | return ret; |
| 828 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 829 | EXPORT_SYMBOL(iwl_set_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 830 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 831 | static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 832 | struct ieee80211_key_conf *keyconf, |
| 833 | u8 sta_id) |
| 834 | { |
| 835 | unsigned long flags; |
| 836 | __le16 key_flags = 0; |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 837 | struct iwl_addsta_cmd sta_cmd; |
| 838 | |
| 839 | lockdep_assert_held(&priv->mutex); |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 840 | |
| 841 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 842 | |
| 843 | key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); |
| 844 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 845 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 846 | |
| 847 | if (keyconf->keylen == WEP_KEY_LEN_128) |
| 848 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
| 849 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 850 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 851 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 852 | |
| 853 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 854 | |
| 855 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 856 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 857 | priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; |
| 858 | |
| 859 | memcpy(priv->stations[sta_id].keyinfo.key, |
| 860 | keyconf->key, keyconf->keylen); |
| 861 | |
| 862 | memcpy(&priv->stations[sta_id].sta.key.key[3], |
| 863 | keyconf->key, keyconf->keylen); |
| 864 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 865 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 866 | == STA_KEY_FLG_NO_ENC) |
| 867 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 868 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 869 | /* else, we are overriding an existing key => no need to allocated room |
| 870 | * in uCode. */ |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 871 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 872 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Jiri Slaby | e724b8f | 2009-01-05 17:06:06 +0100 | [diff] [blame] | 873 | "no space for a new key"); |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 874 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 875 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 876 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 877 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 878 | |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 879 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 880 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 881 | |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 882 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 883 | } |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 884 | |
| 885 | static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, |
| 886 | struct ieee80211_key_conf *keyconf, |
| 887 | u8 sta_id) |
| 888 | { |
| 889 | unsigned long flags; |
| 890 | __le16 key_flags = 0; |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 891 | struct iwl_addsta_cmd sta_cmd; |
| 892 | |
| 893 | lockdep_assert_held(&priv->mutex); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 894 | |
| 895 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); |
| 896 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 897 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 898 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 899 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 900 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 901 | |
| 902 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 903 | |
| 904 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 905 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 906 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 907 | |
| 908 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 909 | keyconf->keylen); |
| 910 | |
| 911 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 912 | keyconf->keylen); |
| 913 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 914 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 915 | == STA_KEY_FLG_NO_ENC) |
| 916 | priv->stations[sta_id].sta.key.key_offset = |
| 917 | iwl_get_free_ucode_key_index(priv); |
| 918 | /* else, we are overriding an existing key => no need to allocated room |
| 919 | * in uCode. */ |
| 920 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 921 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Jiri Slaby | e724b8f | 2009-01-05 17:06:06 +0100 | [diff] [blame] | 922 | "no space for a new key"); |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 923 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 924 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 925 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 926 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 927 | |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 928 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 929 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 930 | |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 931 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, |
| 935 | struct ieee80211_key_conf *keyconf, |
| 936 | u8 sta_id) |
| 937 | { |
| 938 | unsigned long flags; |
| 939 | int ret = 0; |
Reinette Chatre | 299f546 | 2009-04-30 13:56:31 -0700 | [diff] [blame] | 940 | __le16 key_flags = 0; |
| 941 | |
| 942 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 943 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 944 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 945 | |
| 946 | if (sta_id == priv->hw_params.bcast_sta_id) |
| 947 | key_flags |= STA_KEY_MULTICAST_MSK; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 948 | |
| 949 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 950 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 951 | |
| 952 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 953 | |
| 954 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 955 | priv->stations[sta_id].keyinfo.keylen = 16; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 956 | |
| 957 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 958 | == STA_KEY_FLG_NO_ENC) |
| 959 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 960 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 961 | /* else, we are overriding an existing key => no need to allocated room |
| 962 | * in uCode. */ |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 963 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 964 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Jiri Slaby | e724b8f | 2009-01-05 17:06:06 +0100 | [diff] [blame] | 965 | "no space for a new key"); |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 966 | |
Reinette Chatre | 299f546 | 2009-04-30 13:56:31 -0700 | [diff] [blame] | 967 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 968 | |
| 969 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 970 | /* This copy is acutally not needed: we get the key with each TX */ |
| 971 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); |
| 972 | |
| 973 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16); |
| 974 | |
| 975 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 976 | |
| 977 | return ret; |
| 978 | } |
| 979 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 980 | void iwl_update_tkip_key(struct iwl_priv *priv, |
| 981 | struct ieee80211_key_conf *keyconf, |
Johannes Berg | bdbb612 | 2010-04-30 13:53:37 -0700 | [diff] [blame] | 982 | struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 983 | { |
Johannes Berg | bdbb612 | 2010-04-30 13:53:37 -0700 | [diff] [blame] | 984 | u8 sta_id; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 985 | unsigned long flags; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 986 | int i; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 987 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 988 | if (iwl_scan_cancel(priv)) { |
| 989 | /* cancel scan failed, just live w/ bad key and rely |
| 990 | briefly on SW decryption */ |
| 991 | return; |
| 992 | } |
| 993 | |
Johannes Berg | 0af8bca | 2010-04-30 14:08:00 -0700 | [diff] [blame] | 994 | sta_id = iwl_sta_id_or_broadcast(priv, sta); |
| 995 | if (sta_id == IWL_INVALID_STATION) |
| 996 | return; |
| 997 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 998 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 999 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1000 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 1001 | |
| 1002 | for (i = 0; i < 5; i++) |
| 1003 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 1004 | cpu_to_le16(phase1key[i]); |
| 1005 | |
| 1006 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1007 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1008 | |
| 1009 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 1010 | |
| 1011 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1012 | |
| 1013 | } |
| 1014 | EXPORT_SYMBOL(iwl_update_tkip_key); |
| 1015 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1016 | int iwl_remove_dynamic_key(struct iwl_priv *priv, |
| 1017 | struct ieee80211_key_conf *keyconf, |
| 1018 | u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1019 | { |
| 1020 | unsigned long flags; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1021 | u16 key_flags; |
| 1022 | u8 keyidx; |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 1023 | struct iwl_addsta_cmd sta_cmd; |
| 1024 | |
| 1025 | lockdep_assert_held(&priv->mutex); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1026 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1027 | priv->key_mapping_key--; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1028 | |
| 1029 | spin_lock_irqsave(&priv->sta_lock, flags); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1030 | key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); |
| 1031 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; |
| 1032 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1033 | IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 1034 | keyconf->keyidx, sta_id); |
| 1035 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1036 | if (keyconf->keyidx != keyidx) { |
| 1037 | /* We need to remove a key with index different that the one |
| 1038 | * in the uCode. This means that the key we need to remove has |
| 1039 | * been replaced by another one with different index. |
| 1040 | * Don't do anything and return ok |
| 1041 | */ |
| 1042 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1046 | if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1047 | IWL_WARN(priv, "Removing wrong key %d 0x%x\n", |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1048 | keyconf->keyidx, key_flags); |
| 1049 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1053 | if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, |
| 1054 | &priv->ucode_key_table)) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1055 | IWL_ERR(priv, "index %d not used in uCode key table.\n", |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1056 | priv->stations[sta_id].sta.key.key_offset); |
| 1057 | memset(&priv->stations[sta_id].keyinfo, 0, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1058 | sizeof(struct iwl_hw_key)); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1059 | memset(&priv->stations[sta_id].sta.key, 0, |
| 1060 | sizeof(struct iwl4965_keyinfo)); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1061 | priv->stations[sta_id].sta.key.key_flags = |
| 1062 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; |
| 1063 | priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1064 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1065 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1066 | |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 1067 | if (iwl_is_rfkill(priv)) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 1068 | IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n"); |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 1069 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1070 | return 0; |
| 1071 | } |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 1072 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1073 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 1074 | |
| 1075 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1076 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 1077 | EXPORT_SYMBOL(iwl_remove_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1078 | |
| 1079 | int iwl_set_dynamic_key(struct iwl_priv *priv, |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1080 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1081 | { |
| 1082 | int ret; |
| 1083 | |
Johannes Berg | e666674 | 2010-06-14 08:32:24 -0700 | [diff] [blame^] | 1084 | lockdep_assert_held(&priv->mutex); |
| 1085 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1086 | priv->key_mapping_key++; |
| 1087 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1088 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1089 | switch (keyconf->alg) { |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1090 | case ALG_CCMP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1091 | ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1092 | break; |
| 1093 | case ALG_TKIP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1094 | ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1095 | break; |
| 1096 | case ALG_WEP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1097 | ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1098 | break; |
| 1099 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1100 | IWL_ERR(priv, |
| 1101 | "Unknown alg: %s alg = %d\n", __func__, keyconf->alg); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1102 | ret = -EINVAL; |
| 1103 | } |
| 1104 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1105 | IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 1106 | keyconf->alg, keyconf->keylen, keyconf->keyidx, |
| 1107 | sta_id, ret); |
| 1108 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1109 | return ret; |
| 1110 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 1111 | EXPORT_SYMBOL(iwl_set_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1112 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1113 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1114 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 1115 | struct iwl_link_quality_cmd *lq) |
| 1116 | { |
| 1117 | int i; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1118 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); |
| 1119 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1120 | lq->general_params.single_stream_ant_msk, |
| 1121 | lq->general_params.dual_stream_ant_msk); |
| 1122 | |
| 1123 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1124 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1125 | i, lq->rs_table[i].rate_n_flags); |
| 1126 | } |
| 1127 | #else |
| 1128 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 1129 | struct iwl_link_quality_cmd *lq) |
| 1130 | { |
| 1131 | } |
| 1132 | #endif |
| 1133 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1134 | /** |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 1135 | * is_lq_table_valid() - Test one aspect of LQ cmd for validity |
| 1136 | * |
| 1137 | * It sometimes happens when a HT rate has been in use and we |
| 1138 | * loose connectivity with AP then mac80211 will first tell us that the |
| 1139 | * current channel is not HT anymore before removing the station. In such a |
| 1140 | * scenario the RXON flags will be updated to indicate we are not |
| 1141 | * communicating HT anymore, but the LQ command may still contain HT rates. |
| 1142 | * Test for this to prevent driver from sending LQ command between the time |
| 1143 | * RXON flags are updated and when LQ command is updated. |
| 1144 | */ |
| 1145 | static bool is_lq_table_valid(struct iwl_priv *priv, |
| 1146 | struct iwl_link_quality_cmd *lq) |
| 1147 | { |
| 1148 | int i; |
| 1149 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; |
| 1150 | |
| 1151 | if (ht_conf->is_ht) |
| 1152 | return true; |
| 1153 | |
| 1154 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", |
| 1155 | priv->active_rxon.channel); |
| 1156 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 1157 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { |
| 1158 | IWL_DEBUG_INFO(priv, |
| 1159 | "index %d of LQ expects HT channel\n", |
| 1160 | i); |
| 1161 | return false; |
| 1162 | } |
| 1163 | } |
| 1164 | return true; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1168 | * iwl_send_lq_cmd() - Send link quality command |
| 1169 | * @init: This command is sent as part of station initialization right |
| 1170 | * after station has been added. |
| 1171 | * |
| 1172 | * The link quality command is sent as the last step of station creation. |
| 1173 | * This is the special case in which init is set and we call a callback in |
| 1174 | * this case to clear the state indicating that station creation is in |
| 1175 | * progress. |
| 1176 | */ |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1177 | int iwl_send_lq_cmd(struct iwl_priv *priv, |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1178 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1179 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1180 | int ret = 0; |
| 1181 | unsigned long flags_spin; |
| 1182 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1183 | struct iwl_host_cmd cmd = { |
| 1184 | .id = REPLY_TX_LINK_QUALITY_CMD, |
| 1185 | .len = sizeof(struct iwl_link_quality_cmd), |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 1186 | .flags = flags, |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1187 | .data = lq, |
| 1188 | }; |
| 1189 | |
Johannes Berg | 76c3c69 | 2010-03-30 02:46:29 -0700 | [diff] [blame] | 1190 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1191 | return -EINVAL; |
| 1192 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 1193 | iwl_dump_lq_cmd(priv, lq); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1194 | BUG_ON(init && (cmd.flags & CMD_ASYNC)); |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1195 | |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 1196 | if (is_lq_table_valid(priv, lq)) |
| 1197 | ret = iwl_send_cmd(priv, &cmd); |
| 1198 | else |
| 1199 | ret = -EINVAL; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1200 | |
| 1201 | if (cmd.flags & CMD_ASYNC) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1202 | return ret; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1203 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1204 | if (init) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 1205 | IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n", |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1206 | lq->sta_id); |
| 1207 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 1208 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 1209 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 1210 | } |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1211 | return ret; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1212 | } |
| 1213 | EXPORT_SYMBOL(iwl_send_lq_cmd); |
| 1214 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1215 | /** |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1216 | * iwl_alloc_bcast_station - add broadcast station into driver's station table. |
| 1217 | * |
| 1218 | * This adds the broadcast station into the driver's station table |
| 1219 | * and marks it driver active, so that it will be restored to the |
| 1220 | * device at the next best time. |
Reinette Chatre | 9a9ca65 | 2009-10-30 14:36:12 -0700 | [diff] [blame] | 1221 | */ |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1222 | int iwl_alloc_bcast_station(struct iwl_priv *priv, bool init_lq) |
Reinette Chatre | 9a9ca65 | 2009-10-30 14:36:12 -0700 | [diff] [blame] | 1223 | { |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1224 | struct iwl_link_quality_cmd *link_cmd; |
| 1225 | unsigned long flags; |
| 1226 | u8 sta_id; |
Reinette Chatre | 9a9ca65 | 2009-10-30 14:36:12 -0700 | [diff] [blame] | 1227 | |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1228 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1229 | sta_id = iwl_prep_station(priv, iwl_bcast_addr, false, NULL); |
| 1230 | if (sta_id == IWL_INVALID_STATION) { |
| 1231 | IWL_ERR(priv, "Unable to prepare broadcast station\n"); |
| 1232 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1233 | |
| 1234 | return -EINVAL; |
| 1235 | } |
| 1236 | |
| 1237 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; |
| 1238 | priv->stations[sta_id].used |= IWL_STA_BCAST; |
| 1239 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1240 | |
| 1241 | if (init_lq) { |
| 1242 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); |
| 1243 | if (!link_cmd) { |
| 1244 | IWL_ERR(priv, |
| 1245 | "Unable to initialize rate scaling for bcast station.\n"); |
| 1246 | return -ENOMEM; |
| 1247 | } |
| 1248 | |
| 1249 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1250 | priv->stations[sta_id].lq = link_cmd; |
| 1251 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1252 | } |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station); |
| 1257 | |
| 1258 | void iwl_dealloc_bcast_station(struct iwl_priv *priv) |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1259 | { |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1260 | unsigned long flags; |
| 1261 | int i; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1262 | |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1263 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1264 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 1265 | if (!(priv->stations[i].used & IWL_STA_BCAST)) |
| 1266 | continue; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1267 | |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1268 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
| 1269 | priv->num_stations--; |
| 1270 | BUG_ON(priv->num_stations < 0); |
| 1271 | kfree(priv->stations[i].lq); |
| 1272 | priv->stations[i].lq = NULL; |
| 1273 | } |
| 1274 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1275 | } |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 1276 | EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_station); |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1277 | |
| 1278 | /** |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1279 | * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 1280 | */ |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1281 | int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid) |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 1282 | { |
| 1283 | unsigned long flags; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1284 | struct iwl_addsta_cmd sta_cmd; |
| 1285 | |
| 1286 | lockdep_assert_held(&priv->mutex); |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 1287 | |
| 1288 | /* Remove "disable" flag, to enable Tx for this TID */ |
| 1289 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1290 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 1291 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 1292 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1293 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 1294 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1295 | |
| 1296 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 1297 | } |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1298 | EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid); |
| 1299 | |
Johannes Berg | 619753f | 2010-04-30 11:30:46 -0700 | [diff] [blame] | 1300 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, |
| 1301 | int tid, u16 ssn) |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1302 | { |
| 1303 | unsigned long flags; |
| 1304 | int sta_id; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1305 | struct iwl_addsta_cmd sta_cmd; |
| 1306 | |
| 1307 | lockdep_assert_held(&priv->mutex); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1308 | |
Johannes Berg | 619753f | 2010-04-30 11:30:46 -0700 | [diff] [blame] | 1309 | sta_id = iwl_sta_id(sta); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1310 | if (sta_id == IWL_INVALID_STATION) |
| 1311 | return -ENXIO; |
| 1312 | |
| 1313 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1314 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 1315 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; |
| 1316 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; |
| 1317 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 1318 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1319 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1320 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1321 | |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1322 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1323 | } |
| 1324 | EXPORT_SYMBOL(iwl_sta_rx_agg_start); |
| 1325 | |
Johannes Berg | 619753f | 2010-04-30 11:30:46 -0700 | [diff] [blame] | 1326 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, |
| 1327 | int tid) |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1328 | { |
| 1329 | unsigned long flags; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1330 | int sta_id; |
| 1331 | struct iwl_addsta_cmd sta_cmd; |
| 1332 | |
| 1333 | lockdep_assert_held(&priv->mutex); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1334 | |
Johannes Berg | 619753f | 2010-04-30 11:30:46 -0700 | [diff] [blame] | 1335 | sta_id = iwl_sta_id(sta); |
Wey-Yi Guy | a2f1cbe | 2009-03-17 21:51:52 -0700 | [diff] [blame] | 1336 | if (sta_id == IWL_INVALID_STATION) { |
| 1337 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1338 | return -ENXIO; |
Wey-Yi Guy | a2f1cbe | 2009-03-17 21:51:52 -0700 | [diff] [blame] | 1339 | } |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1340 | |
| 1341 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1342 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 1343 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; |
| 1344 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; |
| 1345 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1346 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1347 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1348 | |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 1349 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1350 | } |
| 1351 | EXPORT_SYMBOL(iwl_sta_rx_agg_stop); |
| 1352 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1353 | void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1354 | { |
| 1355 | unsigned long flags; |
| 1356 | |
| 1357 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1358 | priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK; |
| 1359 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 1360 | priv->stations[sta_id].sta.sta.modify_mask = 0; |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1361 | priv->stations[sta_id].sta.sleep_tx_count = 0; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1362 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 1363 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1364 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1365 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1366 | } |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1367 | EXPORT_SYMBOL(iwl_sta_modify_ps_wake); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1368 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1369 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt) |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1370 | { |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1371 | unsigned long flags; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1372 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1373 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1374 | priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK; |
| 1375 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 1376 | priv->stations[sta_id].sta.sta.modify_mask = |
| 1377 | STA_MODIFY_SLEEP_TX_COUNT_MSK; |
| 1378 | priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt); |
| 1379 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 1380 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1381 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1382 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1383 | } |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 1384 | EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1385 | |
| 1386 | int iwl_mac_sta_remove(struct ieee80211_hw *hw, |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 1387 | struct ieee80211_vif *vif, |
| 1388 | struct ieee80211_sta *sta) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1389 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1390 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 1391 | struct iwl_station_priv_common *sta_common = (void *)sta->drv_priv; |
| 1392 | int ret; |
| 1393 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1394 | IWL_DEBUG_INFO(priv, "received request to remove station %pM\n", |
| 1395 | sta->addr); |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 1396 | mutex_lock(&priv->mutex); |
| 1397 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", |
| 1398 | sta->addr); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 1399 | ret = iwl_remove_station(priv, sta_common->sta_id, sta->addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1400 | if (ret) |
| 1401 | IWL_ERR(priv, "Error removing station %pM\n", |
| 1402 | sta->addr); |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 1403 | mutex_unlock(&priv->mutex); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1404 | return ret; |
| 1405 | } |
| 1406 | EXPORT_SYMBOL(iwl_mac_sta_remove); |