staging: greybus: add Viresh as maintainer of few greybus protocol drivers
[linux-2.6/btrfs-unstable.git] / drivers / staging / vt6655 / key.c
blobe161d5d9aebb1240b40090b9616d7e2bedb069bd
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * File: key.c
22 * Purpose: Implement functions for 802.11i Key management
24 * Author: Jerry Chen
26 * Date: May 29, 2003
30 #include "tmacro.h"
31 #include "key.h"
32 #include "mac.h"
34 static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
35 struct ieee80211_key_conf *key, u32 key_type, u32 mode,
36 bool onfly_latch)
38 struct vnt_private *priv = hw->priv;
39 u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
40 u16 key_mode = 0;
41 u32 entry = 0;
42 u8 *bssid;
43 u8 key_inx = key->keyidx;
44 u8 i;
46 if (mac_addr)
47 bssid = mac_addr;
48 else
49 bssid = &broadcast[0];
51 if (key_type != VNT_KEY_DEFAULTKEY) {
52 for (i = 0; i < (MAX_KEY_TABLE - 1); i++) {
53 if (!test_bit(i, &priv->key_entry_inuse)) {
54 set_bit(i, &priv->key_entry_inuse);
56 key->hw_key_idx = i;
57 entry = key->hw_key_idx;
58 break;
63 switch (key_type) {
64 /* fallthrough */
65 case VNT_KEY_DEFAULTKEY:
66 /* default key last entry */
67 entry = MAX_KEY_TABLE - 1;
68 key->hw_key_idx = entry;
69 case VNT_KEY_ALLGROUP:
70 key_mode |= VNT_KEY_ALLGROUP;
71 if (onfly_latch)
72 key_mode |= VNT_KEY_ONFLY_ALL;
73 case VNT_KEY_GROUP_ADDRESS:
74 key_mode |= mode;
75 case VNT_KEY_GROUP:
76 key_mode |= (mode << 4);
77 key_mode |= VNT_KEY_GROUP;
78 break;
79 case VNT_KEY_PAIRWISE:
80 key_mode |= mode;
81 key_inx = 4;
82 break;
83 default:
84 return -EINVAL;
87 if (onfly_latch)
88 key_mode |= VNT_KEY_ONFLY;
90 if (mode == KEY_CTL_WEP) {
91 if (key->keylen == WLAN_KEY_LEN_WEP40)
92 key->key[15] &= 0x7f;
93 if (key->keylen == WLAN_KEY_LEN_WEP104)
94 key->key[15] |= 0x80;
97 MACvSetKeyEntry(priv, key_mode, entry, key_inx,
98 bssid, (u32 *)key->key, priv->byLocalID);
100 return 0;
103 int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
104 struct ieee80211_vif *vif, struct ieee80211_key_conf *key)
106 struct ieee80211_bss_conf *conf = &vif->bss_conf;
107 struct vnt_private *priv = hw->priv;
108 u8 *mac_addr = NULL;
109 u8 key_dec_mode = 0;
110 int ret = 0;
111 u32 u;
113 if (sta)
114 mac_addr = &sta->addr[0];
116 switch (key->cipher) {
117 case 0:
118 for (u = 0 ; u < MAX_KEY_TABLE; u++)
119 MACvDisableKeyEntry(priv, u);
120 return ret;
122 case WLAN_CIPHER_SUITE_WEP40:
123 case WLAN_CIPHER_SUITE_WEP104:
124 for (u = 0; u < MAX_KEY_TABLE; u++)
125 MACvDisableKeyEntry(priv, u);
127 vnt_set_keymode(hw, mac_addr,
128 key, VNT_KEY_DEFAULTKEY, KEY_CTL_WEP, true);
130 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
132 return ret;
133 case WLAN_CIPHER_SUITE_TKIP:
134 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
135 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
137 key_dec_mode = KEY_CTL_TKIP;
139 break;
140 case WLAN_CIPHER_SUITE_CCMP:
141 key_dec_mode = KEY_CTL_CCMP;
143 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
146 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
147 vnt_set_keymode(hw, mac_addr,
148 key, VNT_KEY_PAIRWISE, key_dec_mode, true);
149 } else {
150 vnt_set_keymode(hw, mac_addr,
151 key, VNT_KEY_DEFAULTKEY, key_dec_mode, true);
153 vnt_set_keymode(hw, (u8 *)conf->bssid,
154 key, VNT_KEY_GROUP_ADDRESS, key_dec_mode, true);
157 return 0;