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 | |
| 33 | #include "iwl-eeprom.h" |
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" |
| 37 | #include "iwl-io.h" |
| 38 | #include "iwl-helpers.h" |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 39 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 40 | u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr) |
| 41 | { |
| 42 | int i; |
| 43 | int start = 0; |
| 44 | int ret = IWL_INVALID_STATION; |
| 45 | unsigned long flags; |
| 46 | DECLARE_MAC_BUF(mac); |
| 47 | |
| 48 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) || |
| 49 | (priv->iw_mode == IEEE80211_IF_TYPE_AP)) |
| 50 | start = IWL_STA_ID; |
| 51 | |
| 52 | if (is_broadcast_ether_addr(addr)) |
| 53 | return priv->hw_params.bcast_sta_id; |
| 54 | |
| 55 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 56 | for (i = start; i < priv->hw_params.max_stations; i++) |
| 57 | if (priv->stations[i].used && |
| 58 | (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 59 | addr))) { |
| 60 | ret = i; |
| 61 | goto out; |
| 62 | } |
| 63 | |
| 64 | IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n", |
| 65 | print_mac(mac, addr), priv->num_stations); |
| 66 | |
| 67 | out: |
| 68 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 69 | return ret; |
| 70 | } |
| 71 | EXPORT_SYMBOL(iwl_find_station); |
| 72 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 73 | int iwl_send_add_sta(struct iwl_priv *priv, |
| 74 | struct iwl_addsta_cmd *sta, u8 flags) |
| 75 | { |
| 76 | struct iwl_rx_packet *res = NULL; |
| 77 | int ret = 0; |
| 78 | u8 data[sizeof(*sta)]; |
| 79 | struct iwl_host_cmd cmd = { |
| 80 | .id = REPLY_ADD_STA, |
| 81 | .meta.flags = flags, |
| 82 | .data = data, |
| 83 | }; |
| 84 | |
| 85 | if (!(flags & CMD_ASYNC)) |
| 86 | cmd.meta.flags |= CMD_WANT_SKB; |
| 87 | |
| 88 | cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data); |
| 89 | ret = iwl_send_cmd(priv, &cmd); |
| 90 | |
| 91 | if (ret || (flags & CMD_ASYNC)) |
| 92 | return ret; |
| 93 | |
| 94 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
| 95 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 96 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 97 | res->hdr.flags); |
| 98 | ret = -EIO; |
| 99 | } |
| 100 | |
| 101 | if (ret == 0) { |
| 102 | switch (res->u.add_sta.status) { |
| 103 | case ADD_STA_SUCCESS_MSK: |
| 104 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 105 | break; |
| 106 | default: |
| 107 | ret = -EIO; |
| 108 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | priv->alloc_rxb_skb--; |
| 114 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 115 | |
| 116 | return ret; |
| 117 | } |
| 118 | EXPORT_SYMBOL(iwl_send_add_sta); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 119 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 120 | #ifdef CONFIG_IWL4965_HT |
| 121 | |
| 122 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
| 123 | struct ieee80211_ht_info *sta_ht_inf) |
| 124 | { |
| 125 | __le32 sta_flags; |
| 126 | u8 mimo_ps_mode; |
| 127 | |
| 128 | if (!sta_ht_inf || !sta_ht_inf->ht_supported) |
| 129 | goto done; |
| 130 | |
| 131 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2; |
| 132 | |
| 133 | sta_flags = priv->stations[index].sta.station_flags; |
| 134 | |
| 135 | sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); |
| 136 | |
| 137 | switch (mimo_ps_mode) { |
| 138 | case WLAN_HT_CAP_MIMO_PS_STATIC: |
| 139 | sta_flags |= STA_FLG_MIMO_DIS_MSK; |
| 140 | break; |
| 141 | case WLAN_HT_CAP_MIMO_PS_DYNAMIC: |
| 142 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
| 143 | break; |
| 144 | case WLAN_HT_CAP_MIMO_PS_DISABLED: |
| 145 | break; |
| 146 | default: |
| 147 | IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode); |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | sta_flags |= cpu_to_le32( |
| 152 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); |
| 153 | |
| 154 | sta_flags |= cpu_to_le32( |
| 155 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
| 156 | |
| 157 | if (iwl_is_fat_tx_allowed(priv, sta_ht_inf)) |
| 158 | sta_flags |= STA_FLG_FAT_EN_MSK; |
| 159 | else |
| 160 | sta_flags &= ~STA_FLG_FAT_EN_MSK; |
| 161 | |
| 162 | priv->stations[index].sta.station_flags = sta_flags; |
| 163 | done: |
| 164 | return; |
| 165 | } |
| 166 | #else |
| 167 | static inline void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
| 168 | struct ieee80211_ht_info *sta_ht_info) |
| 169 | { |
| 170 | } |
| 171 | #endif |
| 172 | |
| 173 | /** |
| 174 | * iwl_add_station_flags - Add station to tables in driver and device |
| 175 | */ |
| 176 | u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap, |
| 177 | u8 flags, struct ieee80211_ht_info *ht_info) |
| 178 | { |
| 179 | int i; |
| 180 | int index = IWL_INVALID_STATION; |
| 181 | struct iwl_station_entry *station; |
| 182 | unsigned long flags_spin; |
| 183 | DECLARE_MAC_BUF(mac); |
| 184 | |
| 185 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 186 | if (is_ap) |
| 187 | index = IWL_AP_ID; |
| 188 | else if (is_broadcast_ether_addr(addr)) |
| 189 | index = priv->hw_params.bcast_sta_id; |
| 190 | else |
| 191 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
| 192 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 193 | addr)) { |
| 194 | index = i; |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | if (!priv->stations[i].used && |
| 199 | index == IWL_INVALID_STATION) |
| 200 | index = i; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /* These two conditions have the same outcome, but keep them separate |
| 205 | since they have different meanings */ |
| 206 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 207 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 208 | return index; |
| 209 | } |
| 210 | |
| 211 | if (priv->stations[index].used && |
| 212 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 213 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 214 | return index; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr)); |
| 219 | station = &priv->stations[index]; |
| 220 | station->used = 1; |
| 221 | priv->num_stations++; |
| 222 | |
| 223 | /* Set up the REPLY_ADD_STA command to send to device */ |
| 224 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
| 225 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 226 | station->sta.mode = 0; |
| 227 | station->sta.sta.sta_id = index; |
| 228 | station->sta.station_flags = 0; |
| 229 | |
| 230 | /* BCAST station and IBSS stations do not work in HT mode */ |
| 231 | if (index != priv->hw_params.bcast_sta_id && |
| 232 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
| 233 | iwl_set_ht_add_station(priv, index, ht_info); |
| 234 | |
| 235 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 236 | |
| 237 | /* Add station to device's station table */ |
| 238 | iwl_send_add_sta(priv, &station->sta, flags); |
| 239 | return index; |
| 240 | |
| 241 | } |
| 242 | EXPORT_SYMBOL(iwl_add_station_flags); |
| 243 | |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 244 | int iwl_get_free_ucode_key_index(struct iwl_priv *priv) |
| 245 | { |
| 246 | int i; |
| 247 | |
| 248 | for (i = 0; i < STA_KEY_MAX_NUM; i++) |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 249 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 250 | return i; |
| 251 | |
| 252 | return -1; |
| 253 | } |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 254 | |
| 255 | int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) |
| 256 | { |
| 257 | int i, not_empty = 0; |
| 258 | u8 buff[sizeof(struct iwl_wep_cmd) + |
| 259 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; |
| 260 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; |
| 261 | size_t cmd_size = sizeof(struct iwl_wep_cmd); |
| 262 | struct iwl_host_cmd cmd = { |
| 263 | .id = REPLY_WEPKEY, |
| 264 | .data = wep_cmd, |
| 265 | .meta.flags = CMD_ASYNC, |
| 266 | }; |
| 267 | |
| 268 | memset(wep_cmd, 0, cmd_size + |
| 269 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); |
| 270 | |
| 271 | for (i = 0; i < WEP_KEYS_MAX ; i++) { |
| 272 | wep_cmd->key[i].key_index = i; |
| 273 | if (priv->wep_keys[i].key_size) { |
| 274 | wep_cmd->key[i].key_offset = i; |
| 275 | not_empty = 1; |
| 276 | } else { |
| 277 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 278 | } |
| 279 | |
| 280 | wep_cmd->key[i].key_size = priv->wep_keys[i].key_size; |
| 281 | memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key, |
| 282 | priv->wep_keys[i].key_size); |
| 283 | } |
| 284 | |
| 285 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 286 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 287 | |
| 288 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; |
| 289 | |
| 290 | cmd.len = cmd_size; |
| 291 | |
| 292 | if (not_empty || send_if_empty) |
| 293 | return iwl_send_cmd(priv, &cmd); |
| 294 | else |
| 295 | return 0; |
| 296 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 297 | EXPORT_SYMBOL(iwl_send_static_wepkey_cmd); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 298 | |
| 299 | int iwl_remove_default_wep_key(struct iwl_priv *priv, |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 300 | struct ieee80211_key_conf *keyconf) |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 301 | { |
| 302 | int ret; |
| 303 | unsigned long flags; |
| 304 | |
| 305 | spin_lock_irqsave(&priv->sta_lock, flags); |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 306 | |
| 307 | if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table)) |
| 308 | IWL_ERROR("index %d not used in uCode key table.\n", |
| 309 | keyconf->keyidx); |
| 310 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 311 | priv->default_wep_key--; |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 312 | memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 313 | ret = iwl_send_static_wepkey_cmd(priv, 1); |
| 314 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 315 | |
| 316 | return ret; |
| 317 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 318 | EXPORT_SYMBOL(iwl_remove_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 319 | |
| 320 | int iwl_set_default_wep_key(struct iwl_priv *priv, |
| 321 | struct ieee80211_key_conf *keyconf) |
| 322 | { |
| 323 | int ret; |
| 324 | unsigned long flags; |
| 325 | |
| 326 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 327 | keyconf->hw_key_idx = HW_KEY_DEFAULT; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 328 | priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; |
| 329 | |
| 330 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 331 | priv->default_wep_key++; |
| 332 | |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 333 | if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table)) |
| 334 | IWL_ERROR("index %d already used in uCode key table.\n", |
| 335 | keyconf->keyidx); |
| 336 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 337 | priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
| 338 | memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, |
| 339 | keyconf->keylen); |
| 340 | |
| 341 | ret = iwl_send_static_wepkey_cmd(priv, 0); |
| 342 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 343 | |
| 344 | return ret; |
| 345 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 346 | EXPORT_SYMBOL(iwl_set_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 347 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 348 | static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 349 | struct ieee80211_key_conf *keyconf, |
| 350 | u8 sta_id) |
| 351 | { |
| 352 | unsigned long flags; |
| 353 | __le16 key_flags = 0; |
| 354 | int ret; |
| 355 | |
| 356 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 357 | |
| 358 | key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); |
| 359 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 360 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 361 | |
| 362 | if (keyconf->keylen == WEP_KEY_LEN_128) |
| 363 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
| 364 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 365 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 366 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 367 | |
| 368 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 369 | |
| 370 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 371 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 372 | priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; |
| 373 | |
| 374 | memcpy(priv->stations[sta_id].keyinfo.key, |
| 375 | keyconf->key, keyconf->keylen); |
| 376 | |
| 377 | memcpy(&priv->stations[sta_id].sta.key.key[3], |
| 378 | keyconf->key, keyconf->keylen); |
| 379 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 380 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 381 | == STA_KEY_FLG_NO_ENC) |
| 382 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 383 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 384 | /* else, we are overriding an existing key => no need to allocated room |
| 385 | * in uCode. */ |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 386 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 387 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 388 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 389 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 390 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 391 | 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] | 392 | |
| 393 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 394 | |
| 395 | return ret; |
| 396 | } |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 397 | |
| 398 | static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, |
| 399 | struct ieee80211_key_conf *keyconf, |
| 400 | u8 sta_id) |
| 401 | { |
| 402 | unsigned long flags; |
| 403 | __le16 key_flags = 0; |
| 404 | |
| 405 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); |
| 406 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 407 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 408 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 409 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 410 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 411 | |
| 412 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 413 | |
| 414 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 415 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 416 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 417 | |
| 418 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 419 | keyconf->keylen); |
| 420 | |
| 421 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 422 | keyconf->keylen); |
| 423 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 424 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 425 | == STA_KEY_FLG_NO_ENC) |
| 426 | priv->stations[sta_id].sta.key.key_offset = |
| 427 | iwl_get_free_ucode_key_index(priv); |
| 428 | /* else, we are overriding an existing key => no need to allocated room |
| 429 | * in uCode. */ |
| 430 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 431 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 432 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 433 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 434 | |
| 435 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 436 | |
| 437 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 438 | 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] | 439 | } |
| 440 | |
| 441 | static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, |
| 442 | struct ieee80211_key_conf *keyconf, |
| 443 | u8 sta_id) |
| 444 | { |
| 445 | unsigned long flags; |
| 446 | int ret = 0; |
| 447 | |
| 448 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 449 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 450 | |
| 451 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 452 | |
| 453 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 454 | priv->stations[sta_id].keyinfo.keylen = 16; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 455 | |
| 456 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 457 | == STA_KEY_FLG_NO_ENC) |
| 458 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 459 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 460 | /* else, we are overriding an existing key => no need to allocated room |
| 461 | * in uCode. */ |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 462 | |
| 463 | /* This copy is acutally not needed: we get the key with each TX */ |
| 464 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); |
| 465 | |
| 466 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16); |
| 467 | |
| 468 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 469 | |
| 470 | return ret; |
| 471 | } |
| 472 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 473 | int iwl_remove_dynamic_key(struct iwl_priv *priv, |
| 474 | struct ieee80211_key_conf *keyconf, |
| 475 | u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 476 | { |
| 477 | unsigned long flags; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 478 | int ret = 0; |
| 479 | u16 key_flags; |
| 480 | u8 keyidx; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 481 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 482 | priv->key_mapping_key--; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 483 | |
| 484 | spin_lock_irqsave(&priv->sta_lock, flags); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 485 | key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); |
| 486 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; |
| 487 | |
| 488 | if (keyconf->keyidx != keyidx) { |
| 489 | /* We need to remove a key with index different that the one |
| 490 | * in the uCode. This means that the key we need to remove has |
| 491 | * been replaced by another one with different index. |
| 492 | * Don't do anything and return ok |
| 493 | */ |
| 494 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 495 | return 0; |
| 496 | } |
| 497 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 498 | if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, |
| 499 | &priv->ucode_key_table)) |
| 500 | IWL_ERROR("index %d not used in uCode key table.\n", |
| 501 | priv->stations[sta_id].sta.key.key_offset); |
| 502 | memset(&priv->stations[sta_id].keyinfo, 0, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 503 | sizeof(struct iwl_hw_key)); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 504 | memset(&priv->stations[sta_id].sta.key, 0, |
| 505 | sizeof(struct iwl4965_keyinfo)); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 506 | priv->stations[sta_id].sta.key.key_flags = |
| 507 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; |
| 508 | priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 509 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 510 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 511 | |
| 512 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 513 | 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] | 514 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 515 | return ret; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 516 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 517 | EXPORT_SYMBOL(iwl_remove_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 518 | |
| 519 | int iwl_set_dynamic_key(struct iwl_priv *priv, |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 520 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 521 | { |
| 522 | int ret; |
| 523 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 524 | priv->key_mapping_key++; |
| 525 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 526 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 527 | switch (keyconf->alg) { |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 528 | case ALG_CCMP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 529 | ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 530 | break; |
| 531 | case ALG_TKIP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 532 | ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 533 | break; |
| 534 | case ALG_WEP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 535 | ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 536 | break; |
| 537 | default: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 538 | IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 539 | ret = -EINVAL; |
| 540 | } |
| 541 | |
| 542 | return ret; |
| 543 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 544 | EXPORT_SYMBOL(iwl_set_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 545 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 546 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 547 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 548 | struct iwl_link_quality_cmd *lq) |
| 549 | { |
| 550 | int i; |
| 551 | IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id); |
| 552 | IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n", |
| 553 | lq->general_params.single_stream_ant_msk, |
| 554 | lq->general_params.dual_stream_ant_msk); |
| 555 | |
| 556 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
| 557 | IWL_DEBUG_RATE("lq index %d 0x%X\n", |
| 558 | i, lq->rs_table[i].rate_n_flags); |
| 559 | } |
| 560 | #else |
| 561 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 562 | struct iwl_link_quality_cmd *lq) |
| 563 | { |
| 564 | } |
| 565 | #endif |
| 566 | |
| 567 | int iwl_send_lq_cmd(struct iwl_priv *priv, |
| 568 | struct iwl_link_quality_cmd *lq, u8 flags) |
| 569 | { |
| 570 | struct iwl_host_cmd cmd = { |
| 571 | .id = REPLY_TX_LINK_QUALITY_CMD, |
| 572 | .len = sizeof(struct iwl_link_quality_cmd), |
| 573 | .meta.flags = flags, |
| 574 | .data = lq, |
| 575 | }; |
| 576 | |
| 577 | if ((lq->sta_id == 0xFF) && |
| 578 | (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)) |
| 579 | return -EINVAL; |
| 580 | |
| 581 | if (lq->sta_id == 0xFF) |
| 582 | lq->sta_id = IWL_AP_ID; |
| 583 | |
| 584 | iwl_dump_lq_cmd(priv,lq); |
| 585 | |
| 586 | if (iwl_is_associated(priv) && priv->assoc_station_added && |
| 587 | priv->lq_mngr.lq_ready) |
| 588 | return iwl_send_cmd(priv, &cmd); |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | EXPORT_SYMBOL(iwl_send_lq_cmd); |
| 593 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 594 | /** |
| 595 | * iwl_sta_init_lq - Initialize a station's hardware rate table |
| 596 | * |
| 597 | * The uCode's station table contains a table of fallback rates |
| 598 | * for automatic fallback during transmission. |
| 599 | * |
| 600 | * NOTE: This sets up a default set of values. These will be replaced later |
| 601 | * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of |
| 602 | * rc80211_simple. |
| 603 | * |
| 604 | * NOTE: Run REPLY_ADD_STA command to set up station table entry, before |
| 605 | * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, |
| 606 | * which requires station table entry to exist). |
| 607 | */ |
| 608 | static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap) |
| 609 | { |
| 610 | int i, r; |
| 611 | struct iwl_link_quality_cmd link_cmd = { |
| 612 | .reserved1 = 0, |
| 613 | }; |
| 614 | u16 rate_flags; |
| 615 | |
| 616 | /* Set up the rate scaling to start at selected rate, fall back |
| 617 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
| 618 | if (is_ap) |
| 619 | r = IWL_RATE_54M_INDEX; |
| 620 | else if (priv->band == IEEE80211_BAND_5GHZ) |
| 621 | r = IWL_RATE_6M_INDEX; |
| 622 | else |
| 623 | r = IWL_RATE_1M_INDEX; |
| 624 | |
| 625 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 626 | rate_flags = 0; |
| 627 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) |
| 628 | rate_flags |= RATE_MCS_CCK_MSK; |
| 629 | |
| 630 | /* Use Tx antenna B only */ |
| 631 | rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/ |
| 632 | |
| 633 | link_cmd.rs_table[i].rate_n_flags = |
| 634 | iwl4965_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); |
| 635 | r = iwl4965_get_prev_ieee_rate(r); |
| 636 | } |
| 637 | |
| 638 | link_cmd.general_params.single_stream_ant_msk = 2; |
| 639 | link_cmd.general_params.dual_stream_ant_msk = 3; |
| 640 | link_cmd.agg_params.agg_dis_start_th = 3; |
| 641 | link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000); |
| 642 | |
| 643 | /* Update the rate scaling for control frame Tx to AP */ |
| 644 | link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id; |
| 645 | |
| 646 | iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD, |
| 647 | sizeof(link_cmd), &link_cmd, NULL); |
| 648 | } |
| 649 | /** |
| 650 | * iwl_rxon_add_station - add station into station table. |
| 651 | * |
| 652 | * there is only one AP station with id= IWL_AP_ID |
| 653 | * NOTE: mutex must be held before calling this fnction |
| 654 | */ |
| 655 | int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
| 656 | { |
| 657 | u8 sta_id; |
| 658 | |
| 659 | /* Add station to device's station table */ |
| 660 | #ifdef CONFIG_IWL4965_HT |
| 661 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 662 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 663 | |
| 664 | if ((is_ap) && |
| 665 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 666 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 667 | sta_id = iwl_add_station_flags(priv, addr, is_ap, |
| 668 | 0, cur_ht_config); |
| 669 | else |
| 670 | #endif /* CONFIG_IWL4965_HT */ |
| 671 | sta_id = iwl_add_station_flags(priv, addr, is_ap, |
| 672 | 0, NULL); |
| 673 | |
| 674 | /* Set up default rate scaling table in device's station table */ |
| 675 | iwl_sta_init_lq(priv, addr, is_ap); |
| 676 | |
| 677 | return sta_id; |
| 678 | } |
| 679 | EXPORT_SYMBOL(iwl_rxon_add_station); |
| 680 | |
| 681 | |
| 682 | /** |
| 683 | * iwl_get_sta_id - Find station's index within station table |
| 684 | * |
| 685 | * If new IBSS station, create new entry in station table |
| 686 | */ |
| 687 | int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) |
| 688 | { |
| 689 | int sta_id; |
| 690 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 691 | DECLARE_MAC_BUF(mac); |
| 692 | |
| 693 | /* If this frame is broadcast or management, use broadcast station id */ |
| 694 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 695 | is_multicast_ether_addr(hdr->addr1)) |
| 696 | return priv->hw_params.bcast_sta_id; |
| 697 | |
| 698 | switch (priv->iw_mode) { |
| 699 | |
| 700 | /* If we are a client station in a BSS network, use the special |
| 701 | * AP station entry (that's the only station we communicate with) */ |
| 702 | case IEEE80211_IF_TYPE_STA: |
| 703 | return IWL_AP_ID; |
| 704 | |
| 705 | /* If we are an AP, then find the station, or use BCAST */ |
| 706 | case IEEE80211_IF_TYPE_AP: |
| 707 | sta_id = iwl_find_station(priv, hdr->addr1); |
| 708 | if (sta_id != IWL_INVALID_STATION) |
| 709 | return sta_id; |
| 710 | return priv->hw_params.bcast_sta_id; |
| 711 | |
| 712 | /* If this frame is going out to an IBSS network, find the station, |
| 713 | * or create a new station table entry */ |
| 714 | case IEEE80211_IF_TYPE_IBSS: |
| 715 | sta_id = iwl_find_station(priv, hdr->addr1); |
| 716 | if (sta_id != IWL_INVALID_STATION) |
| 717 | return sta_id; |
| 718 | |
| 719 | /* Create new station table entry */ |
| 720 | sta_id = iwl_add_station_flags(priv, hdr->addr1, |
| 721 | 0, CMD_ASYNC, NULL); |
| 722 | |
| 723 | if (sta_id != IWL_INVALID_STATION) |
| 724 | return sta_id; |
| 725 | |
| 726 | IWL_DEBUG_DROP("Station %s not in station map. " |
| 727 | "Defaulting to broadcast...\n", |
| 728 | print_mac(mac, hdr->addr1)); |
| 729 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
| 730 | return priv->hw_params.bcast_sta_id; |
| 731 | |
| 732 | default: |
| 733 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
| 734 | return priv->hw_params.bcast_sta_id; |
| 735 | } |
| 736 | } |
| 737 | EXPORT_SYMBOL(iwl_get_sta_id); |
| 738 | |