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