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