Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
| 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: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 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> |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 32 | |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 33 | #include "iwl-dev.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 34 | #include "iwl-core.h" |
| 35 | #include "iwl-sta.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 36 | #include "iwl-helpers.h" |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 37 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 38 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 39 | #define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */ |
| 40 | #define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */ |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 41 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 42 | u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr) |
| 43 | { |
| 44 | int i; |
| 45 | int start = 0; |
| 46 | int ret = IWL_INVALID_STATION; |
| 47 | unsigned long flags; |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 48 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 49 | if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) || |
| 50 | (priv->iw_mode == NL80211_IFTYPE_AP)) |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 51 | start = IWL_STA_ID; |
| 52 | |
| 53 | if (is_broadcast_ether_addr(addr)) |
| 54 | return priv->hw_params.bcast_sta_id; |
| 55 | |
| 56 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 57 | for (i = start; i < priv->hw_params.max_stations; i++) |
| 58 | if (priv->stations[i].used && |
| 59 | (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 60 | addr))) { |
| 61 | ret = i; |
| 62 | goto out; |
| 63 | } |
| 64 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 65 | IWL_DEBUG_ASSOC_LIMIT("can not find STA %pM total %d\n", |
| 66 | addr, priv->num_stations); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 67 | |
| 68 | out: |
| 69 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 70 | return ret; |
| 71 | } |
| 72 | EXPORT_SYMBOL(iwl_find_station); |
| 73 | |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 74 | int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) |
| 75 | { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 76 | if (priv->iw_mode == NL80211_IFTYPE_STATION) { |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 77 | return IWL_AP_ID; |
| 78 | } else { |
| 79 | u8 *da = ieee80211_get_DA(hdr); |
| 80 | return iwl_find_station(priv, da); |
| 81 | } |
| 82 | } |
| 83 | EXPORT_SYMBOL(iwl_get_ra_sta_id); |
| 84 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 85 | static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) |
| 86 | { |
| 87 | unsigned long flags; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 88 | |
| 89 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 90 | |
| 91 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) |
| 92 | IWL_ERROR("ACTIVATE a non DRIVER active station %d\n", sta_id); |
| 93 | |
| 94 | priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 95 | IWL_DEBUG_ASSOC("Added STA to Ucode: %pM\n", |
| 96 | priv->stations[sta_id].sta.sta.addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 97 | |
| 98 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 99 | } |
| 100 | |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 101 | static int iwl_add_sta_callback(struct iwl_priv *priv, |
| 102 | struct iwl_cmd *cmd, struct sk_buff *skb) |
| 103 | { |
| 104 | struct iwl_rx_packet *res = NULL; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 105 | u8 sta_id = cmd->cmd.addsta.sta.sta_id; |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 106 | |
| 107 | if (!skb) { |
| 108 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | res = (struct iwl_rx_packet *)skb->data; |
| 113 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 114 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 115 | res->hdr.flags); |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | switch (res->u.add_sta.status) { |
| 120 | case ADD_STA_SUCCESS_MSK: |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 121 | iwl_sta_ucode_activate(priv, sta_id); |
| 122 | /* fall through */ |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 123 | default: |
| 124 | IWL_DEBUG_HC("Received REPLY_ADD_STA:(0x%08X)\n", |
| 125 | res->u.add_sta.status); |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | /* We didn't cache the SKB; let the caller free it */ |
| 130 | return 1; |
| 131 | } |
| 132 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 133 | int iwl_send_add_sta(struct iwl_priv *priv, |
| 134 | struct iwl_addsta_cmd *sta, u8 flags) |
| 135 | { |
| 136 | struct iwl_rx_packet *res = NULL; |
| 137 | int ret = 0; |
| 138 | u8 data[sizeof(*sta)]; |
| 139 | struct iwl_host_cmd cmd = { |
| 140 | .id = REPLY_ADD_STA, |
| 141 | .meta.flags = flags, |
| 142 | .data = data, |
| 143 | }; |
| 144 | |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 145 | if (flags & CMD_ASYNC) |
| 146 | cmd.meta.u.callback = iwl_add_sta_callback; |
| 147 | else |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 148 | cmd.meta.flags |= CMD_WANT_SKB; |
| 149 | |
| 150 | cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data); |
| 151 | ret = iwl_send_cmd(priv, &cmd); |
| 152 | |
| 153 | if (ret || (flags & CMD_ASYNC)) |
| 154 | return ret; |
| 155 | |
| 156 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
| 157 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 158 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 159 | res->hdr.flags); |
| 160 | ret = -EIO; |
| 161 | } |
| 162 | |
| 163 | if (ret == 0) { |
| 164 | switch (res->u.add_sta.status) { |
| 165 | case ADD_STA_SUCCESS_MSK: |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 166 | iwl_sta_ucode_activate(priv, sta->sta.sta_id); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 167 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 168 | break; |
| 169 | default: |
| 170 | ret = -EIO; |
| 171 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | priv->alloc_rxb_skb--; |
| 177 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 178 | |
| 179 | return ret; |
| 180 | } |
| 181 | EXPORT_SYMBOL(iwl_send_add_sta); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 182 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 183 | 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] | 184 | struct ieee80211_sta_ht_cap *sta_ht_inf) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 185 | { |
| 186 | __le32 sta_flags; |
| 187 | u8 mimo_ps_mode; |
| 188 | |
| 189 | if (!sta_ht_inf || !sta_ht_inf->ht_supported) |
| 190 | goto done; |
| 191 | |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 192 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 193 | |
| 194 | sta_flags = priv->stations[index].sta.station_flags; |
| 195 | |
| 196 | sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); |
| 197 | |
| 198 | switch (mimo_ps_mode) { |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 199 | case WLAN_HT_CAP_SM_PS_STATIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 200 | sta_flags |= STA_FLG_MIMO_DIS_MSK; |
| 201 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 202 | case WLAN_HT_CAP_SM_PS_DYNAMIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 203 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
| 204 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 205 | case WLAN_HT_CAP_SM_PS_DISABLED: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 206 | break; |
| 207 | default: |
Jiri Slaby | 6f14792 | 2008-08-11 23:49:41 +0200 | [diff] [blame] | 208 | IWL_WARNING("Invalid MIMO PS mode %d\n", mimo_ps_mode); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 209 | break; |
| 210 | } |
| 211 | |
| 212 | sta_flags |= cpu_to_le32( |
| 213 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); |
| 214 | |
| 215 | sta_flags |= cpu_to_le32( |
| 216 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
| 217 | |
| 218 | if (iwl_is_fat_tx_allowed(priv, sta_ht_inf)) |
| 219 | sta_flags |= STA_FLG_FAT_EN_MSK; |
| 220 | else |
| 221 | sta_flags &= ~STA_FLG_FAT_EN_MSK; |
| 222 | |
| 223 | priv->stations[index].sta.station_flags = sta_flags; |
| 224 | done: |
| 225 | return; |
| 226 | } |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * iwl_add_station_flags - Add station to tables in driver and device |
| 230 | */ |
| 231 | u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 232 | u8 flags, struct ieee80211_sta_ht_cap *ht_info) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 233 | { |
| 234 | int i; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 235 | int sta_id = IWL_INVALID_STATION; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 236 | struct iwl_station_entry *station; |
| 237 | unsigned long flags_spin; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 238 | |
| 239 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 240 | if (is_ap) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 241 | sta_id = IWL_AP_ID; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 242 | else if (is_broadcast_ether_addr(addr)) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 243 | sta_id = priv->hw_params.bcast_sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 244 | else |
| 245 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
| 246 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 247 | addr)) { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 248 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | |
| 252 | if (!priv->stations[i].used && |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 253 | sta_id == IWL_INVALID_STATION) |
| 254 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 255 | } |
| 256 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 257 | /* These two conditions have the same outcome, but keep them separate |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 258 | since they have different meanings */ |
| 259 | if (unlikely(sta_id == IWL_INVALID_STATION)) { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 260 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 261 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 262 | } |
| 263 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 264 | if (priv->stations[sta_id].used && |
| 265 | !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 266 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 267 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 271 | station = &priv->stations[sta_id]; |
| 272 | station->used = IWL_STA_DRIVER_ACTIVE; |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 273 | IWL_DEBUG_ASSOC("Add STA to driver ID %d: %pM\n", |
| 274 | sta_id, addr); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 275 | priv->num_stations++; |
| 276 | |
| 277 | /* Set up the REPLY_ADD_STA command to send to device */ |
| 278 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
| 279 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 280 | station->sta.mode = 0; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 281 | station->sta.sta.sta_id = sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 282 | station->sta.station_flags = 0; |
| 283 | |
| 284 | /* BCAST station and IBSS stations do not work in HT mode */ |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 285 | if (sta_id != priv->hw_params.bcast_sta_id && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 286 | priv->iw_mode != NL80211_IFTYPE_ADHOC) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 287 | iwl_set_ht_add_station(priv, sta_id, ht_info); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 288 | |
| 289 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 290 | |
| 291 | /* Add station to device's station table */ |
| 292 | iwl_send_add_sta(priv, &station->sta, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 293 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 294 | |
| 295 | } |
| 296 | EXPORT_SYMBOL(iwl_add_station_flags); |
| 297 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 298 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 299 | { |
| 300 | unsigned long flags; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 301 | u8 sta_id = iwl_find_station(priv, addr); |
| 302 | |
| 303 | BUG_ON(sta_id == IWL_INVALID_STATION); |
| 304 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 305 | IWL_DEBUG_ASSOC("Removed STA from Ucode: %pM\n", addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 306 | |
| 307 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 308 | |
| 309 | /* Ucode must be active and driver must be non active */ |
| 310 | if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE) |
| 311 | IWL_ERROR("removed non active STA %d\n", sta_id); |
| 312 | |
| 313 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; |
| 314 | |
| 315 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); |
| 316 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static int iwl_remove_sta_callback(struct iwl_priv *priv, |
| 320 | struct iwl_cmd *cmd, struct sk_buff *skb) |
| 321 | { |
| 322 | struct iwl_rx_packet *res = NULL; |
| 323 | const char *addr = cmd->cmd.rm_sta.addr; |
| 324 | |
| 325 | if (!skb) { |
| 326 | IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n"); |
| 327 | return 1; |
| 328 | } |
| 329 | |
| 330 | res = (struct iwl_rx_packet *)skb->data; |
| 331 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 332 | IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n", |
| 333 | res->hdr.flags); |
| 334 | return 1; |
| 335 | } |
| 336 | |
| 337 | switch (res->u.rem_sta.status) { |
| 338 | case REM_STA_SUCCESS_MSK: |
| 339 | iwl_sta_ucode_deactivate(priv, addr); |
| 340 | break; |
| 341 | default: |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 342 | IWL_ERROR("REPLY_REMOVE_STA failed\n"); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 343 | break; |
| 344 | } |
| 345 | |
| 346 | /* We didn't cache the SKB; let the caller free it */ |
| 347 | return 1; |
| 348 | } |
| 349 | |
| 350 | static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr, |
| 351 | u8 flags) |
| 352 | { |
| 353 | struct iwl_rx_packet *res = NULL; |
| 354 | int ret; |
| 355 | |
| 356 | struct iwl_rem_sta_cmd rm_sta_cmd; |
| 357 | |
| 358 | struct iwl_host_cmd cmd = { |
| 359 | .id = REPLY_REMOVE_STA, |
| 360 | .len = sizeof(struct iwl_rem_sta_cmd), |
| 361 | .meta.flags = flags, |
| 362 | .data = &rm_sta_cmd, |
| 363 | }; |
| 364 | |
| 365 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); |
| 366 | rm_sta_cmd.num_sta = 1; |
| 367 | memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN); |
| 368 | |
| 369 | if (flags & CMD_ASYNC) |
| 370 | cmd.meta.u.callback = iwl_remove_sta_callback; |
| 371 | else |
| 372 | cmd.meta.flags |= CMD_WANT_SKB; |
| 373 | ret = iwl_send_cmd(priv, &cmd); |
| 374 | |
| 375 | if (ret || (flags & CMD_ASYNC)) |
| 376 | return ret; |
| 377 | |
| 378 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
| 379 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 380 | IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n", |
| 381 | res->hdr.flags); |
| 382 | ret = -EIO; |
| 383 | } |
| 384 | |
| 385 | if (!ret) { |
| 386 | switch (res->u.rem_sta.status) { |
| 387 | case REM_STA_SUCCESS_MSK: |
| 388 | iwl_sta_ucode_deactivate(priv, addr); |
| 389 | IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n"); |
| 390 | break; |
| 391 | default: |
| 392 | ret = -EIO; |
| 393 | IWL_ERROR("REPLY_REMOVE_STA failed\n"); |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | priv->alloc_rxb_skb--; |
| 399 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 400 | |
| 401 | return ret; |
| 402 | } |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 403 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 404 | /** |
| 405 | * iwl_remove_station - Remove driver's knowledge of station. |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 406 | */ |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 407 | int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 408 | { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 409 | int sta_id = IWL_INVALID_STATION; |
| 410 | int i, ret = -EINVAL; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 411 | unsigned long flags; |
| 412 | |
| 413 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 414 | |
| 415 | if (is_ap) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 416 | sta_id = IWL_AP_ID; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 417 | else if (is_broadcast_ether_addr(addr)) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 418 | sta_id = priv->hw_params.bcast_sta_id; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 419 | else |
| 420 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
| 421 | if (priv->stations[i].used && |
| 422 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 423 | addr)) { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 424 | sta_id = i; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 425 | break; |
| 426 | } |
| 427 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 428 | if (unlikely(sta_id == IWL_INVALID_STATION)) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 429 | goto out; |
| 430 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 431 | IWL_DEBUG_ASSOC("Removing STA from driver:%d %pM\n", |
| 432 | sta_id, addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 433 | |
| 434 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 435 | IWL_ERROR("Removing %pM but non DRIVER active\n", |
| 436 | addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 437 | goto out; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 438 | } |
| 439 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 440 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 441 | IWL_ERROR("Removing %pM but non UCODE active\n", |
| 442 | addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 443 | goto out; |
| 444 | } |
| 445 | |
| 446 | |
| 447 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 448 | |
| 449 | priv->num_stations--; |
| 450 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 451 | BUG_ON(priv->num_stations < 0); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 452 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 453 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 454 | |
| 455 | ret = iwl_send_remove_station(priv, addr, CMD_ASYNC); |
| 456 | return ret; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 457 | out: |
| 458 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 459 | return ret; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 460 | } |
| 461 | EXPORT_SYMBOL(iwl_remove_station); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 462 | |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 463 | static int iwl_get_free_ucode_key_index(struct iwl_priv *priv) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 464 | { |
| 465 | int i; |
| 466 | |
| 467 | for (i = 0; i < STA_KEY_MAX_NUM; i++) |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 468 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 469 | return i; |
| 470 | |
| 471 | return -1; |
| 472 | } |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 473 | |
| 474 | int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) |
| 475 | { |
| 476 | int i, not_empty = 0; |
| 477 | u8 buff[sizeof(struct iwl_wep_cmd) + |
| 478 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; |
| 479 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; |
| 480 | size_t cmd_size = sizeof(struct iwl_wep_cmd); |
| 481 | struct iwl_host_cmd cmd = { |
| 482 | .id = REPLY_WEPKEY, |
| 483 | .data = wep_cmd, |
| 484 | .meta.flags = CMD_ASYNC, |
| 485 | }; |
| 486 | |
| 487 | memset(wep_cmd, 0, cmd_size + |
| 488 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); |
| 489 | |
| 490 | for (i = 0; i < WEP_KEYS_MAX ; i++) { |
| 491 | wep_cmd->key[i].key_index = i; |
| 492 | if (priv->wep_keys[i].key_size) { |
| 493 | wep_cmd->key[i].key_offset = i; |
| 494 | not_empty = 1; |
| 495 | } else { |
| 496 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 497 | } |
| 498 | |
| 499 | wep_cmd->key[i].key_size = priv->wep_keys[i].key_size; |
| 500 | memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key, |
| 501 | priv->wep_keys[i].key_size); |
| 502 | } |
| 503 | |
| 504 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 505 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 506 | |
| 507 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; |
| 508 | |
| 509 | cmd.len = cmd_size; |
| 510 | |
| 511 | if (not_empty || send_if_empty) |
| 512 | return iwl_send_cmd(priv, &cmd); |
| 513 | else |
| 514 | return 0; |
| 515 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 516 | EXPORT_SYMBOL(iwl_send_static_wepkey_cmd); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 517 | |
| 518 | int iwl_remove_default_wep_key(struct iwl_priv *priv, |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 519 | struct ieee80211_key_conf *keyconf) |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 520 | { |
| 521 | int ret; |
| 522 | unsigned long flags; |
| 523 | |
| 524 | spin_lock_irqsave(&priv->sta_lock, flags); |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 525 | |
| 526 | if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table)) |
| 527 | IWL_ERROR("index %d not used in uCode key table.\n", |
| 528 | keyconf->keyidx); |
| 529 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 530 | priv->default_wep_key--; |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 531 | memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 532 | ret = iwl_send_static_wepkey_cmd(priv, 1); |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 533 | IWL_DEBUG_WEP("Remove default WEP key: idx=%d ret=%d\n", |
| 534 | keyconf->keyidx, ret); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 535 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 536 | |
| 537 | return ret; |
| 538 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 539 | EXPORT_SYMBOL(iwl_remove_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 540 | |
| 541 | int iwl_set_default_wep_key(struct iwl_priv *priv, |
| 542 | struct ieee80211_key_conf *keyconf) |
| 543 | { |
| 544 | int ret; |
| 545 | unsigned long flags; |
| 546 | |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 547 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
| 548 | keyconf->keylen != WEP_KEY_LEN_64) { |
| 549 | IWL_DEBUG_WEP("Bad WEP key length %d\n", keyconf->keylen); |
| 550 | return -EINVAL; |
| 551 | } |
| 552 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 553 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 554 | keyconf->hw_key_idx = HW_KEY_DEFAULT; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 555 | priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; |
| 556 | |
| 557 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 558 | priv->default_wep_key++; |
| 559 | |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 560 | if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table)) |
| 561 | IWL_ERROR("index %d already used in uCode key table.\n", |
| 562 | keyconf->keyidx); |
| 563 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 564 | priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
| 565 | memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, |
| 566 | keyconf->keylen); |
| 567 | |
| 568 | ret = iwl_send_static_wepkey_cmd(priv, 0); |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 569 | IWL_DEBUG_WEP("Set default WEP key: len=%d idx=%d ret=%d\n", |
| 570 | keyconf->keylen, keyconf->keyidx, ret); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 571 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 572 | |
| 573 | return ret; |
| 574 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 575 | EXPORT_SYMBOL(iwl_set_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 576 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 577 | static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 578 | struct ieee80211_key_conf *keyconf, |
| 579 | u8 sta_id) |
| 580 | { |
| 581 | unsigned long flags; |
| 582 | __le16 key_flags = 0; |
| 583 | int ret; |
| 584 | |
| 585 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 586 | |
| 587 | key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); |
| 588 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 589 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 590 | |
| 591 | if (keyconf->keylen == WEP_KEY_LEN_128) |
| 592 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
| 593 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 594 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 595 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 596 | |
| 597 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 598 | |
| 599 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 600 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 601 | priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; |
| 602 | |
| 603 | memcpy(priv->stations[sta_id].keyinfo.key, |
| 604 | keyconf->key, keyconf->keylen); |
| 605 | |
| 606 | memcpy(&priv->stations[sta_id].sta.key.key[3], |
| 607 | keyconf->key, keyconf->keylen); |
| 608 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 609 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 610 | == STA_KEY_FLG_NO_ENC) |
| 611 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 612 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 613 | /* else, we are overriding an existing key => no need to allocated room |
| 614 | * in uCode. */ |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 615 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 616 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 617 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 618 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 619 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 620 | 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] | 621 | |
| 622 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 623 | |
| 624 | return ret; |
| 625 | } |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 626 | |
| 627 | static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, |
| 628 | struct ieee80211_key_conf *keyconf, |
| 629 | u8 sta_id) |
| 630 | { |
| 631 | unsigned long flags; |
| 632 | __le16 key_flags = 0; |
| 633 | |
| 634 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); |
| 635 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 636 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 637 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 638 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 639 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 640 | |
| 641 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 642 | |
| 643 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 644 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 645 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 646 | |
| 647 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 648 | keyconf->keylen); |
| 649 | |
| 650 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 651 | keyconf->keylen); |
| 652 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 653 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 654 | == STA_KEY_FLG_NO_ENC) |
| 655 | priv->stations[sta_id].sta.key.key_offset = |
| 656 | iwl_get_free_ucode_key_index(priv); |
| 657 | /* else, we are overriding an existing key => no need to allocated room |
| 658 | * in uCode. */ |
| 659 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 660 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 661 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 662 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 663 | |
| 664 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 665 | |
| 666 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 667 | return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, |
| 671 | struct ieee80211_key_conf *keyconf, |
| 672 | u8 sta_id) |
| 673 | { |
| 674 | unsigned long flags; |
| 675 | int ret = 0; |
| 676 | |
| 677 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 678 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 679 | |
| 680 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 681 | |
| 682 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 683 | priv->stations[sta_id].keyinfo.keylen = 16; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 684 | |
| 685 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 686 | == STA_KEY_FLG_NO_ENC) |
| 687 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 688 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 689 | /* else, we are overriding an existing key => no need to allocated room |
| 690 | * in uCode. */ |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 691 | |
| 692 | /* This copy is acutally not needed: we get the key with each TX */ |
| 693 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); |
| 694 | |
| 695 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16); |
| 696 | |
| 697 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 698 | |
| 699 | return ret; |
| 700 | } |
| 701 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 702 | int iwl_remove_dynamic_key(struct iwl_priv *priv, |
| 703 | struct ieee80211_key_conf *keyconf, |
| 704 | u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 705 | { |
| 706 | unsigned long flags; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 707 | int ret = 0; |
| 708 | u16 key_flags; |
| 709 | u8 keyidx; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 710 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 711 | priv->key_mapping_key--; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 712 | |
| 713 | spin_lock_irqsave(&priv->sta_lock, flags); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 714 | key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); |
| 715 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; |
| 716 | |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 717 | IWL_DEBUG_WEP("Remove dynamic key: idx=%d sta=%d\n", |
| 718 | keyconf->keyidx, sta_id); |
| 719 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 720 | if (keyconf->keyidx != keyidx) { |
| 721 | /* We need to remove a key with index different that the one |
| 722 | * in the uCode. This means that the key we need to remove has |
| 723 | * been replaced by another one with different index. |
| 724 | * Don't do anything and return ok |
| 725 | */ |
| 726 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 727 | return 0; |
| 728 | } |
| 729 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 730 | if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, |
| 731 | &priv->ucode_key_table)) |
| 732 | IWL_ERROR("index %d not used in uCode key table.\n", |
| 733 | priv->stations[sta_id].sta.key.key_offset); |
| 734 | memset(&priv->stations[sta_id].keyinfo, 0, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 735 | sizeof(struct iwl_hw_key)); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 736 | memset(&priv->stations[sta_id].sta.key, 0, |
| 737 | sizeof(struct iwl4965_keyinfo)); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 738 | priv->stations[sta_id].sta.key.key_flags = |
| 739 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; |
| 740 | priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 741 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 742 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 743 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 744 | 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] | 745 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 746 | return ret; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 747 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 748 | EXPORT_SYMBOL(iwl_remove_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 749 | |
| 750 | int iwl_set_dynamic_key(struct iwl_priv *priv, |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 751 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 752 | { |
| 753 | int ret; |
| 754 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 755 | priv->key_mapping_key++; |
| 756 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 757 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 758 | switch (keyconf->alg) { |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 759 | case ALG_CCMP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 760 | ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 761 | break; |
| 762 | case ALG_TKIP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 763 | ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 764 | break; |
| 765 | case ALG_WEP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 766 | ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 767 | break; |
| 768 | default: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 769 | IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 770 | ret = -EINVAL; |
| 771 | } |
| 772 | |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 773 | IWL_DEBUG_WEP("Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", |
| 774 | keyconf->alg, keyconf->keylen, keyconf->keyidx, |
| 775 | sta_id, ret); |
| 776 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 777 | return ret; |
| 778 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 779 | EXPORT_SYMBOL(iwl_set_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 780 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 781 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 782 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 783 | struct iwl_link_quality_cmd *lq) |
| 784 | { |
| 785 | int i; |
| 786 | IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id); |
| 787 | IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n", |
| 788 | lq->general_params.single_stream_ant_msk, |
| 789 | lq->general_params.dual_stream_ant_msk); |
| 790 | |
| 791 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
| 792 | IWL_DEBUG_RATE("lq index %d 0x%X\n", |
| 793 | i, lq->rs_table[i].rate_n_flags); |
| 794 | } |
| 795 | #else |
| 796 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 797 | struct iwl_link_quality_cmd *lq) |
| 798 | { |
| 799 | } |
| 800 | #endif |
| 801 | |
| 802 | int iwl_send_lq_cmd(struct iwl_priv *priv, |
| 803 | struct iwl_link_quality_cmd *lq, u8 flags) |
| 804 | { |
| 805 | struct iwl_host_cmd cmd = { |
| 806 | .id = REPLY_TX_LINK_QUALITY_CMD, |
| 807 | .len = sizeof(struct iwl_link_quality_cmd), |
| 808 | .meta.flags = flags, |
| 809 | .data = lq, |
| 810 | }; |
| 811 | |
| 812 | if ((lq->sta_id == 0xFF) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 813 | (priv->iw_mode == NL80211_IFTYPE_ADHOC)) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 814 | return -EINVAL; |
| 815 | |
| 816 | if (lq->sta_id == 0xFF) |
| 817 | lq->sta_id = IWL_AP_ID; |
| 818 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 819 | iwl_dump_lq_cmd(priv, lq); |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 820 | |
Ron Rindjunsky | 36e1f16 | 2008-06-30 17:23:13 +0800 | [diff] [blame] | 821 | if (iwl_is_associated(priv) && priv->assoc_station_added) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 822 | return iwl_send_cmd(priv, &cmd); |
| 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | EXPORT_SYMBOL(iwl_send_lq_cmd); |
| 827 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 828 | /** |
| 829 | * iwl_sta_init_lq - Initialize a station's hardware rate table |
| 830 | * |
| 831 | * The uCode's station table contains a table of fallback rates |
| 832 | * for automatic fallback during transmission. |
| 833 | * |
| 834 | * NOTE: This sets up a default set of values. These will be replaced later |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 835 | * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 836 | * rc80211_simple. |
| 837 | * |
| 838 | * NOTE: Run REPLY_ADD_STA command to set up station table entry, before |
| 839 | * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, |
| 840 | * which requires station table entry to exist). |
| 841 | */ |
| 842 | static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap) |
| 843 | { |
| 844 | int i, r; |
| 845 | struct iwl_link_quality_cmd link_cmd = { |
| 846 | .reserved1 = 0, |
| 847 | }; |
Tomas Winkler | 5d664a4 | 2008-10-08 09:37:29 +0800 | [diff] [blame] | 848 | u32 rate_flags; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 849 | |
| 850 | /* Set up the rate scaling to start at selected rate, fall back |
| 851 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
| 852 | if (is_ap) |
| 853 | r = IWL_RATE_54M_INDEX; |
| 854 | else if (priv->band == IEEE80211_BAND_5GHZ) |
| 855 | r = IWL_RATE_6M_INDEX; |
| 856 | else |
| 857 | r = IWL_RATE_1M_INDEX; |
| 858 | |
| 859 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 860 | rate_flags = 0; |
| 861 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) |
| 862 | rate_flags |= RATE_MCS_CCK_MSK; |
| 863 | |
Tomas Winkler | 5d664a4 | 2008-10-08 09:37:29 +0800 | [diff] [blame] | 864 | rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) << |
| 865 | RATE_MCS_ANT_POS; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 866 | |
| 867 | link_cmd.rs_table[i].rate_n_flags = |
Tomas Winkler | e7d326ac | 2008-06-12 09:47:11 +0800 | [diff] [blame] | 868 | iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 869 | r = iwl4965_get_prev_ieee_rate(r); |
| 870 | } |
| 871 | |
Tomas Winkler | 5d664a4 | 2008-10-08 09:37:29 +0800 | [diff] [blame] | 872 | link_cmd.general_params.single_stream_ant_msk = |
| 873 | first_antenna(priv->hw_params.valid_tx_ant); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 874 | link_cmd.general_params.dual_stream_ant_msk = 3; |
| 875 | link_cmd.agg_params.agg_dis_start_th = 3; |
| 876 | link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000); |
| 877 | |
| 878 | /* Update the rate scaling for control frame Tx to AP */ |
| 879 | link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id; |
| 880 | |
| 881 | iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD, |
| 882 | sizeof(link_cmd), &link_cmd, NULL); |
| 883 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 884 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 885 | /** |
| 886 | * iwl_rxon_add_station - add station into station table. |
| 887 | * |
| 888 | * there is only one AP station with id= IWL_AP_ID |
| 889 | * NOTE: mutex must be held before calling this fnction |
| 890 | */ |
| 891 | int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
| 892 | { |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame^] | 893 | struct ieee80211_sta *sta; |
| 894 | struct ieee80211_sta_ht_cap ht_config; |
| 895 | struct ieee80211_sta_ht_cap *cur_ht_config = NULL; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 896 | u8 sta_id; |
| 897 | |
| 898 | /* Add station to device's station table */ |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 899 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame^] | 900 | /* |
| 901 | * XXX: This check is definitely not correct, if we're an AP |
| 902 | * it'll always be false which is not what we want, but |
| 903 | * it doesn't look like iwlagn is prepared to be an HT |
| 904 | * AP anyway. |
| 905 | */ |
| 906 | if (priv->current_ht_config.is_ht) { |
| 907 | rcu_read_lock(); |
| 908 | sta = ieee80211_find_sta(priv->hw, addr); |
| 909 | if (sta) { |
| 910 | memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config)); |
| 911 | cur_ht_config = &ht_config; |
| 912 | } |
| 913 | rcu_read_unlock(); |
| 914 | } |
| 915 | |
| 916 | sta_id = iwl_add_station_flags(priv, addr, is_ap, |
| 917 | 0, cur_ht_config); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 918 | |
| 919 | /* Set up default rate scaling table in device's station table */ |
| 920 | iwl_sta_init_lq(priv, addr, is_ap); |
| 921 | |
| 922 | return sta_id; |
| 923 | } |
| 924 | EXPORT_SYMBOL(iwl_rxon_add_station); |
| 925 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 926 | /** |
| 927 | * iwl_get_sta_id - Find station's index within station table |
| 928 | * |
| 929 | * If new IBSS station, create new entry in station table |
| 930 | */ |
| 931 | int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) |
| 932 | { |
| 933 | int sta_id; |
| 934 | u16 fc = le16_to_cpu(hdr->frame_control); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 935 | |
| 936 | /* If this frame is broadcast or management, use broadcast station id */ |
| 937 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 938 | is_multicast_ether_addr(hdr->addr1)) |
| 939 | return priv->hw_params.bcast_sta_id; |
| 940 | |
| 941 | switch (priv->iw_mode) { |
| 942 | |
| 943 | /* If we are a client station in a BSS network, use the special |
| 944 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 945 | case NL80211_IFTYPE_STATION: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 946 | return IWL_AP_ID; |
| 947 | |
| 948 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 949 | case NL80211_IFTYPE_AP: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 950 | sta_id = iwl_find_station(priv, hdr->addr1); |
| 951 | if (sta_id != IWL_INVALID_STATION) |
| 952 | return sta_id; |
| 953 | return priv->hw_params.bcast_sta_id; |
| 954 | |
| 955 | /* If this frame is going out to an IBSS network, find the station, |
| 956 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 957 | case NL80211_IFTYPE_ADHOC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 958 | sta_id = iwl_find_station(priv, hdr->addr1); |
| 959 | if (sta_id != IWL_INVALID_STATION) |
| 960 | return sta_id; |
| 961 | |
| 962 | /* Create new station table entry */ |
| 963 | sta_id = iwl_add_station_flags(priv, hdr->addr1, |
| 964 | 0, CMD_ASYNC, NULL); |
| 965 | |
| 966 | if (sta_id != IWL_INVALID_STATION) |
| 967 | return sta_id; |
| 968 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 969 | IWL_DEBUG_DROP("Station %pM not in station map. " |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 970 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 971 | hdr->addr1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 972 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
| 973 | return priv->hw_params.bcast_sta_id; |
| 974 | |
Stefanik Gábor | d10c4ec | 2008-09-03 11:26:59 +0800 | [diff] [blame] | 975 | /* If we are in monitor mode, use BCAST. This is required for |
| 976 | * packet injection. */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 977 | case NL80211_IFTYPE_MONITOR: |
Stefanik Gábor | d10c4ec | 2008-09-03 11:26:59 +0800 | [diff] [blame] | 978 | return priv->hw_params.bcast_sta_id; |
| 979 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 980 | default: |
Jiri Slaby | 6f14792 | 2008-08-11 23:49:41 +0200 | [diff] [blame] | 981 | IWL_WARNING("Unknown mode of operation: %d\n", priv->iw_mode); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 982 | return priv->hw_params.bcast_sta_id; |
| 983 | } |
| 984 | } |
| 985 | EXPORT_SYMBOL(iwl_get_sta_id); |
| 986 | |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 987 | /** |
| 988 | * iwl_sta_modify_enable_tid_tx - Enable Tx for this TID in station table |
| 989 | */ |
| 990 | void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid) |
| 991 | { |
| 992 | unsigned long flags; |
| 993 | |
| 994 | /* Remove "disable" flag, to enable Tx for this TID */ |
| 995 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 996 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 997 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 998 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 999 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1000 | |
| 1001 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 1002 | } |
| 1003 | EXPORT_SYMBOL(iwl_sta_modify_enable_tid_tx); |
| 1004 | |