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