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