iwlwifi: default WEP HW encryption
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / iwlwifi / iwl-sta.c
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>
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"
38
39 int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
40 {
41         int i, not_empty = 0;
42         u8 buff[sizeof(struct iwl_wep_cmd) +
43                 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
44         struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
45         size_t cmd_size  = sizeof(struct iwl_wep_cmd);
46         struct iwl_host_cmd cmd = {
47                 .id = REPLY_WEPKEY,
48                 .data = wep_cmd,
49                 .meta.flags = CMD_ASYNC,
50         };
51
52         memset(wep_cmd, 0, cmd_size +
53                         (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
54
55         for (i = 0; i < WEP_KEYS_MAX ; i++) {
56                 wep_cmd->key[i].key_index = i;
57                 if (priv->wep_keys[i].key_size) {
58                         wep_cmd->key[i].key_offset = i;
59                         not_empty = 1;
60                 } else {
61                         wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
62                 }
63
64                 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
65                 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
66                                 priv->wep_keys[i].key_size);
67         }
68
69         wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
70         wep_cmd->num_keys = WEP_KEYS_MAX;
71
72         cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
73
74         cmd.len = cmd_size;
75
76         if (not_empty || send_if_empty)
77                 return iwl_send_cmd(priv, &cmd);
78         else
79                 return 0;
80 }
81
82 int iwl_remove_default_wep_key(struct iwl_priv *priv,
83                                struct ieee80211_key_conf *key)
84 {
85         int ret;
86         unsigned long flags;
87
88         spin_lock_irqsave(&priv->sta_lock, flags);
89         priv->default_wep_key--;
90         memset(&priv->wep_keys[key->keyidx], 0, sizeof(priv->wep_keys[0]));
91         ret = iwl_send_static_wepkey_cmd(priv, 1);
92         spin_unlock_irqrestore(&priv->sta_lock, flags);
93
94         return ret;
95 }
96
97 int iwl_set_default_wep_key(struct iwl_priv *priv,
98                             struct ieee80211_key_conf *keyconf)
99 {
100         int ret;
101         unsigned long flags;
102
103         keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
104         keyconf->hw_key_idx = keyconf->keyidx;
105         priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
106
107         spin_lock_irqsave(&priv->sta_lock, flags);
108         priv->default_wep_key++;
109
110         priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
111         memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
112                                                         keyconf->keylen);
113
114         ret = iwl_send_static_wepkey_cmd(priv, 0);
115         spin_unlock_irqrestore(&priv->sta_lock, flags);
116
117         return ret;
118 }
119