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
20 static int vnt_set_keymode(struct ieee80211_hw
*hw
, u8
*mac_addr
,
21 struct ieee80211_key_conf
*key
, u32 key_type
,
22 u32 mode
, bool onfly_latch
)
24 struct vnt_private
*priv
= hw
->priv
;
25 u8 broadcast
[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
29 u8 key_inx
= key
->keyidx
;
35 bssid
= &broadcast
[0];
37 if (key_type
!= VNT_KEY_DEFAULTKEY
) {
38 for (i
= 0; i
< (MAX_KEY_TABLE
- 1); i
++) {
39 if (!test_bit(i
, &priv
->key_entry_inuse
)) {
40 set_bit(i
, &priv
->key_entry_inuse
);
43 entry
= key
->hw_key_idx
;
50 case VNT_KEY_DEFAULTKEY
:
51 /* default key last entry */
52 entry
= MAX_KEY_TABLE
- 1;
53 key
->hw_key_idx
= entry
;
55 case VNT_KEY_ALLGROUP
:
56 key_mode
|= VNT_KEY_ALLGROUP
;
58 key_mode
|= VNT_KEY_ONFLY_ALL
;
60 case VNT_KEY_GROUP_ADDRESS
:
64 key_mode
|= (mode
<< 4);
65 key_mode
|= VNT_KEY_GROUP
;
67 case VNT_KEY_PAIRWISE
:
76 key_mode
|= VNT_KEY_ONFLY
;
78 if (mode
== KEY_CTL_WEP
) {
79 if (key
->keylen
== WLAN_KEY_LEN_WEP40
)
81 if (key
->keylen
== WLAN_KEY_LEN_WEP104
)
85 MACvSetKeyEntry(priv
, key_mode
, entry
, key_inx
,
86 bssid
, (u32
*)key
->key
, priv
->byLocalID
);
91 int vnt_set_keys(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
,
92 struct ieee80211_vif
*vif
, struct ieee80211_key_conf
*key
)
94 struct ieee80211_bss_conf
*conf
= &vif
->bss_conf
;
95 struct vnt_private
*priv
= hw
->priv
;
102 mac_addr
= &sta
->addr
[0];
104 switch (key
->cipher
) {
106 for (u
= 0 ; u
< MAX_KEY_TABLE
; u
++)
107 MACvDisableKeyEntry(priv
, u
);
110 case WLAN_CIPHER_SUITE_WEP40
:
111 case WLAN_CIPHER_SUITE_WEP104
:
112 for (u
= 0; u
< MAX_KEY_TABLE
; u
++)
113 MACvDisableKeyEntry(priv
, u
);
115 vnt_set_keymode(hw
, mac_addr
,
116 key
, VNT_KEY_DEFAULTKEY
, KEY_CTL_WEP
, true);
118 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
121 case WLAN_CIPHER_SUITE_TKIP
:
122 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
123 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
125 key_dec_mode
= KEY_CTL_TKIP
;
128 case WLAN_CIPHER_SUITE_CCMP
:
129 key_dec_mode
= KEY_CTL_CCMP
;
131 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
134 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) {
135 vnt_set_keymode(hw
, mac_addr
,
136 key
, VNT_KEY_PAIRWISE
, key_dec_mode
, true);
138 vnt_set_keymode(hw
, mac_addr
,
139 key
, VNT_KEY_DEFAULTKEY
, key_dec_mode
, true);
141 vnt_set_keymode(hw
, (u8
*)conf
->bssid
,
142 key
, VNT_KEY_GROUP_ADDRESS
, key_dec_mode
, true);