blob: 41238f208ed50439b84d7bce9b6d0c4f6dfd4ced [file] [log] [blame]
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07001/******************************************************************************
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>
31
32#include "iwl-eeprom.h"
33#include "iwl-4965.h"
34#include "iwl-core.h"
35#include "iwl-sta.h"
36#include "iwl-io.h"
37#include "iwl-helpers.h"
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -070038#include "iwl-4965.h"
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -070039#include "iwl-sta.h"
40
41int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
42{
43 int i;
44
45 for (i = 0; i < STA_KEY_MAX_NUM; i++)
46 if (test_and_set_bit(i, &priv->ucode_key_table))
47 return i;
48
49 return -1;
50}
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070051
52int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
53{
54 int i, not_empty = 0;
55 u8 buff[sizeof(struct iwl_wep_cmd) +
56 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
57 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
58 size_t cmd_size = sizeof(struct iwl_wep_cmd);
59 struct iwl_host_cmd cmd = {
60 .id = REPLY_WEPKEY,
61 .data = wep_cmd,
62 .meta.flags = CMD_ASYNC,
63 };
64
65 memset(wep_cmd, 0, cmd_size +
66 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
67
68 for (i = 0; i < WEP_KEYS_MAX ; i++) {
69 wep_cmd->key[i].key_index = i;
70 if (priv->wep_keys[i].key_size) {
71 wep_cmd->key[i].key_offset = i;
72 not_empty = 1;
73 } else {
74 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
75 }
76
77 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
78 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
79 priv->wep_keys[i].key_size);
80 }
81
82 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
83 wep_cmd->num_keys = WEP_KEYS_MAX;
84
85 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
86
87 cmd.len = cmd_size;
88
89 if (not_empty || send_if_empty)
90 return iwl_send_cmd(priv, &cmd);
91 else
92 return 0;
93}
94
95int iwl_remove_default_wep_key(struct iwl_priv *priv,
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -070096 struct ieee80211_key_conf *keyconf)
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070097{
98 int ret;
99 unsigned long flags;
100
101 spin_lock_irqsave(&priv->sta_lock, flags);
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700102
103 if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
104 IWL_ERROR("index %d not used in uCode key table.\n",
105 keyconf->keyidx);
106
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700107 priv->default_wep_key--;
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700108 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700109 ret = iwl_send_static_wepkey_cmd(priv, 1);
110 spin_unlock_irqrestore(&priv->sta_lock, flags);
111
112 return ret;
113}
114
115int iwl_set_default_wep_key(struct iwl_priv *priv,
116 struct ieee80211_key_conf *keyconf)
117{
118 int ret;
119 unsigned long flags;
120
121 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
122 keyconf->hw_key_idx = keyconf->keyidx;
123 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
124
125 spin_lock_irqsave(&priv->sta_lock, flags);
126 priv->default_wep_key++;
127
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700128 if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table))
129 IWL_ERROR("index %d already used in uCode key table.\n",
130 keyconf->keyidx);
131
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700132 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
133 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
134 keyconf->keylen);
135
136 ret = iwl_send_static_wepkey_cmd(priv, 0);
137 spin_unlock_irqrestore(&priv->sta_lock, flags);
138
139 return ret;
140}
141
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700142int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
143 struct ieee80211_key_conf *keyconf,
144 u8 sta_id)
145{
146 unsigned long flags;
147 __le16 key_flags = 0;
148 int ret;
149
150 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
151 keyconf->hw_key_idx = keyconf->keyidx;
152
153 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
154 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
155 key_flags &= ~STA_KEY_FLG_INVALID;
156
157 if (keyconf->keylen == WEP_KEY_LEN_128)
158 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
159
160 if (sta_id == priv->hw_setting.bcast_sta_id)
161 key_flags |= STA_KEY_MULTICAST_MSK;
162
163 spin_lock_irqsave(&priv->sta_lock, flags);
164
165 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
166 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
167 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
168
169 memcpy(priv->stations[sta_id].keyinfo.key,
170 keyconf->key, keyconf->keylen);
171
172 memcpy(&priv->stations[sta_id].sta.key.key[3],
173 keyconf->key, keyconf->keylen);
174
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700175 priv->stations[sta_id].sta.key.key_offset =
176 iwl_get_free_ucode_key_index(priv);
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700177 priv->stations[sta_id].sta.key.key_flags = key_flags;
178
179 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
180 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
181
182 ret = iwl4965_send_add_station(priv,
183 &priv->stations[sta_id].sta, CMD_ASYNC);
184
185 spin_unlock_irqrestore(&priv->sta_lock, flags);
186
187 return ret;
188}