Commit | Line | Data |
---|---|---|
6b4c6ce8 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
92b96797 FB |
2 | /* |
3 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. | |
4 | * All rights reserved. | |
5 | * | |
92b96797 FB |
6 | * File: key.c |
7 | * | |
8 | * Purpose: Implement functions for 802.11i Key management | |
9 | * | |
10 | * Author: Jerry Chen | |
11 | * | |
12 | * Date: May 29, 2003 | |
13 | * | |
14 | * Functions: | |
92b96797 FB |
15 | * |
16 | * Revision History: | |
17 | * | |
18 | */ | |
19 | ||
11d404cb | 20 | #include "mac.h" |
92b96797 | 21 | #include "key.h" |
62c8526d | 22 | #include "usbpipe.h" |
92b96797 | 23 | |
d1eb5003 MP |
24 | int vnt_key_init_table(struct vnt_private *priv) |
25 | { | |
d1eb5003 MP |
26 | u8 i; |
27 | u8 data[MAX_KEY_TABLE]; | |
28 | ||
29 | for (i = 0; i < MAX_KEY_TABLE; i++) | |
30 | data[i] = i; | |
31 | ||
88c9cc00 | 32 | return vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, |
d1eb5003 | 33 | 0, 0, ARRAY_SIZE(data), data); |
d1eb5003 MP |
34 | } |
35 | ||
36 | static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr, | |
5e38e15e SM |
37 | struct ieee80211_key_conf *key, u32 key_type, |
38 | u32 mode, bool onfly_latch) | |
d1eb5003 MP |
39 | { |
40 | struct vnt_private *priv = hw->priv; | |
41 | u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
42 | u16 key_mode = 0; | |
43 | u32 entry = 0; | |
44 | u8 *bssid; | |
45 | u8 key_inx = key->keyidx; | |
46 | u8 i; | |
47 | ||
48 | if (mac_addr) | |
49 | bssid = mac_addr; | |
50 | else | |
51 | bssid = &broadcast[0]; | |
52 | ||
53 | if (key_type != VNT_KEY_DEFAULTKEY) { | |
54 | for (i = 0; i < (MAX_KEY_TABLE - 1); i++) { | |
55 | if (!test_bit(i, &priv->key_entry_inuse)) { | |
56 | set_bit(i, &priv->key_entry_inuse); | |
57 | ||
58 | key->hw_key_idx = i; | |
59 | entry = key->hw_key_idx; | |
60 | break; | |
61 | } | |
62 | } | |
63 | } | |
64 | ||
65 | switch (key_type) { | |
d1eb5003 MP |
66 | case VNT_KEY_DEFAULTKEY: |
67 | /* default key last entry */ | |
68 | entry = MAX_KEY_TABLE - 1; | |
69 | key->hw_key_idx = entry; | |
3623d4de | 70 | /* fall through */ |
d1eb5003 MP |
71 | case VNT_KEY_ALLGROUP: |
72 | key_mode |= VNT_KEY_ALLGROUP; | |
73 | if (onfly_latch) | |
74 | key_mode |= VNT_KEY_ONFLY_ALL; | |
3623d4de | 75 | /* fall through */ |
d1eb5003 MP |
76 | case VNT_KEY_GROUP_ADDRESS: |
77 | key_mode |= mode; | |
3623d4de | 78 | /* fall through */ |
d1eb5003 MP |
79 | case VNT_KEY_GROUP: |
80 | key_mode |= (mode << 4); | |
81 | key_mode |= VNT_KEY_GROUP; | |
82 | break; | |
83 | case VNT_KEY_PAIRWISE: | |
84 | key_mode |= mode; | |
85 | key_inx = 4; | |
f9ef05ce MP |
86 | /* Don't save entry for pairwise key for station mode */ |
87 | if (priv->op_mode == NL80211_IFTYPE_STATION) | |
88 | clear_bit(entry, &priv->key_entry_inuse); | |
d1eb5003 MP |
89 | break; |
90 | default: | |
91 | return -EINVAL; | |
92 | } | |
93 | ||
94 | if (onfly_latch) | |
95 | key_mode |= VNT_KEY_ONFLY; | |
96 | ||
97 | if (mode == KEY_CTL_WEP) { | |
98 | if (key->keylen == WLAN_KEY_LEN_WEP40) | |
99 | key->key[15] &= 0x7f; | |
100 | if (key->keylen == WLAN_KEY_LEN_WEP104) | |
101 | key->key[15] |= 0x80; | |
102 | } | |
103 | ||
104 | vnt_mac_set_keyentry(priv, key_mode, entry, key_inx, bssid, key->key); | |
105 | ||
106 | return 0; | |
107 | } | |
108 | ||
109 | int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta, | |
5e38e15e | 110 | struct ieee80211_vif *vif, struct ieee80211_key_conf *key) |
d1eb5003 MP |
111 | { |
112 | struct ieee80211_bss_conf *conf = &vif->bss_conf; | |
113 | struct vnt_private *priv = hw->priv; | |
114 | u8 *mac_addr = NULL; | |
115 | u8 key_dec_mode = 0; | |
116 | int ret = 0, u; | |
117 | ||
118 | if (sta) | |
119 | mac_addr = &sta->addr[0]; | |
120 | ||
121 | switch (key->cipher) { | |
122 | case 0: | |
123 | for (u = 0 ; u < MAX_KEY_TABLE; u++) | |
124 | vnt_mac_disable_keyentry(priv, u); | |
125 | return ret; | |
126 | ||
127 | case WLAN_CIPHER_SUITE_WEP40: | |
128 | case WLAN_CIPHER_SUITE_WEP104: | |
129 | for (u = 0; u < MAX_KEY_TABLE; u++) | |
130 | vnt_mac_disable_keyentry(priv, u); | |
131 | ||
132 | vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY, | |
5e38e15e | 133 | KEY_CTL_WEP, true); |
d1eb5003 MP |
134 | |
135 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
136 | ||
137 | return ret; | |
138 | case WLAN_CIPHER_SUITE_TKIP: | |
139 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
140 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
141 | ||
142 | key_dec_mode = KEY_CTL_TKIP; | |
143 | ||
144 | break; | |
145 | case WLAN_CIPHER_SUITE_CCMP: | |
f1945a15 | 146 | if (priv->local_id <= MAC_REVISION_A1) |
88900631 | 147 | return -EOPNOTSUPP; |
d1eb5003 MP |
148 | |
149 | key_dec_mode = KEY_CTL_CCMP; | |
150 | ||
151 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
88900631 MP |
152 | break; |
153 | default: | |
154 | return -EOPNOTSUPP; | |
d1eb5003 MP |
155 | } |
156 | ||
d1eb5003 MP |
157 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
158 | vnt_set_keymode(hw, mac_addr, key, VNT_KEY_PAIRWISE, | |
5e38e15e | 159 | key_dec_mode, true); |
d1eb5003 MP |
160 | } else { |
161 | vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY, | |
5e38e15e | 162 | key_dec_mode, true); |
d1eb5003 MP |
163 | |
164 | vnt_set_keymode(hw, (u8 *)conf->bssid, key, | |
5e38e15e | 165 | VNT_KEY_GROUP_ADDRESS, key_dec_mode, true); |
d1eb5003 MP |
166 | } |
167 | ||
168 | return 0; | |
169 | } |