1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose: Implement functions for 802.11i Key management
24 int vnt_key_init_table(struct vnt_private
*priv
)
27 u8 data
[MAX_KEY_TABLE
];
29 for (i
= 0; i
< MAX_KEY_TABLE
; i
++)
32 return vnt_control_out(priv
, MESSAGE_TYPE_CLRKEYENTRY
,
33 0, 0, ARRAY_SIZE(data
), data
);
36 static int vnt_set_keymode(struct ieee80211_hw
*hw
, u8
*mac_addr
,
37 struct ieee80211_key_conf
*key
, u32 key_type
,
38 u32 mode
, bool onfly_latch
)
40 struct vnt_private
*priv
= hw
->priv
;
41 u8 broadcast
[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
45 u8 key_inx
= key
->keyidx
;
51 bssid
= &broadcast
[0];
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
);
59 entry
= key
->hw_key_idx
;
66 case VNT_KEY_DEFAULTKEY
:
67 /* default key last entry */
68 entry
= MAX_KEY_TABLE
- 1;
69 key
->hw_key_idx
= entry
;
71 case VNT_KEY_ALLGROUP
:
72 key_mode
|= VNT_KEY_ALLGROUP
;
74 key_mode
|= VNT_KEY_ONFLY_ALL
;
76 case VNT_KEY_GROUP_ADDRESS
:
80 key_mode
|= (mode
<< 4);
81 key_mode
|= VNT_KEY_GROUP
;
83 case VNT_KEY_PAIRWISE
:
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
);
95 key_mode
|= VNT_KEY_ONFLY
;
97 if (mode
== KEY_CTL_WEP
) {
98 if (key
->keylen
== WLAN_KEY_LEN_WEP40
)
100 if (key
->keylen
== WLAN_KEY_LEN_WEP104
)
101 key
->key
[15] |= 0x80;
104 vnt_mac_set_keyentry(priv
, key_mode
, entry
, key_inx
, bssid
, key
->key
);
109 int vnt_set_keys(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
,
110 struct ieee80211_vif
*vif
, struct ieee80211_key_conf
*key
)
112 struct ieee80211_bss_conf
*conf
= &vif
->bss_conf
;
113 struct vnt_private
*priv
= hw
->priv
;
119 mac_addr
= &sta
->addr
[0];
121 switch (key
->cipher
) {
123 for (u
= 0 ; u
< MAX_KEY_TABLE
; u
++)
124 vnt_mac_disable_keyentry(priv
, u
);
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
);
132 vnt_set_keymode(hw
, mac_addr
, key
, VNT_KEY_DEFAULTKEY
,
135 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
138 case WLAN_CIPHER_SUITE_TKIP
:
139 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
140 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
142 key_dec_mode
= KEY_CTL_TKIP
;
145 case WLAN_CIPHER_SUITE_CCMP
:
146 if (priv
->local_id
<= MAC_REVISION_A1
)
149 key_dec_mode
= KEY_CTL_CCMP
;
151 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
154 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) {
155 vnt_set_keymode(hw
, mac_addr
, key
, VNT_KEY_PAIRWISE
,
158 vnt_set_keymode(hw
, mac_addr
, key
, VNT_KEY_DEFAULTKEY
,
161 vnt_set_keymode(hw
, (u8
*)conf
->bssid
, key
,
162 VNT_KEY_GROUP_ADDRESS
, key_dec_mode
, true);