Lines Matching +full:- +full:key

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Key management related functions.
5 * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
6 * Copyright (c) 2010, ST-Ericsson
11 #include "key.h"
19 idx = ffs(~wdev->key_map) - 1; in wfx_alloc_key()
21 return -1; in wfx_alloc_key()
23 wdev->key_map |= BIT(idx); in wfx_alloc_key()
29 WARN(!(wdev->key_map & BIT(idx)), "inconsistent key allocation"); in wfx_free_key()
30 wdev->key_map &= ~BIT(idx); in wfx_free_key()
34 struct ieee80211_key_conf *key, u8 *peer_addr) in fill_wep_pair() argument
36 WARN(key->keylen > sizeof(msg->key_data), "inconsistent data"); in fill_wep_pair()
37 msg->key_length = key->keylen; in fill_wep_pair()
38 memcpy(msg->key_data, key->key, key->keylen); in fill_wep_pair()
39 ether_addr_copy(msg->peer_address, peer_addr); in fill_wep_pair()
44 struct ieee80211_key_conf *key) in fill_wep_group() argument
46 WARN(key->keylen > sizeof(msg->key_data), "inconsistent data"); in fill_wep_group()
47 msg->key_id = key->keyidx; in fill_wep_group()
48 msg->key_length = key->keylen; in fill_wep_group()
49 memcpy(msg->key_data, key->key, key->keylen); in fill_wep_group()
54 struct ieee80211_key_conf *key, u8 *peer_addr) in fill_tkip_pair() argument
56 u8 *keybuf = key->key; in fill_tkip_pair()
58 WARN(key->keylen != sizeof(msg->tkip_key_data) + sizeof(msg->tx_mic_key) + in fill_tkip_pair()
59 sizeof(msg->rx_mic_key), "inconsistent data"); in fill_tkip_pair()
60 memcpy(msg->tkip_key_data, keybuf, sizeof(msg->tkip_key_data)); in fill_tkip_pair()
61 keybuf += sizeof(msg->tkip_key_data); in fill_tkip_pair()
62 memcpy(msg->tx_mic_key, keybuf, sizeof(msg->tx_mic_key)); in fill_tkip_pair()
63 keybuf += sizeof(msg->tx_mic_key); in fill_tkip_pair()
64 memcpy(msg->rx_mic_key, keybuf, sizeof(msg->rx_mic_key)); in fill_tkip_pair()
65 ether_addr_copy(msg->peer_address, peer_addr); in fill_tkip_pair()
69 static u8 fill_tkip_group(struct wfx_hif_tkip_group_key *msg, struct ieee80211_key_conf *key, in fill_tkip_group() argument
72 u8 *keybuf = key->key; in fill_tkip_group()
74 WARN(key->keylen != sizeof(msg->tkip_key_data) + 2 * sizeof(msg->rx_mic_key), in fill_tkip_group()
76 msg->key_id = key->keyidx; in fill_tkip_group()
77 memcpy(msg->rx_sequence_counter, &seq->tkip.iv16, sizeof(seq->tkip.iv16)); in fill_tkip_group()
78 memcpy(msg->rx_sequence_counter + sizeof(u16), &seq->tkip.iv32, sizeof(seq->tkip.iv32)); in fill_tkip_group()
79 memcpy(msg->tkip_key_data, keybuf, sizeof(msg->tkip_key_data)); in fill_tkip_group()
80 keybuf += sizeof(msg->tkip_key_data); in fill_tkip_group()
82 /* Use Tx MIC Key */ in fill_tkip_group()
83 memcpy(msg->rx_mic_key, keybuf + 0, sizeof(msg->rx_mic_key)); in fill_tkip_group()
85 /* Use Rx MIC Key */ in fill_tkip_group()
86 memcpy(msg->rx_mic_key, keybuf + 8, sizeof(msg->rx_mic_key)); in fill_tkip_group()
91 struct ieee80211_key_conf *key, u8 *peer_addr) in fill_ccmp_pair() argument
93 WARN(key->keylen != sizeof(msg->aes_key_data), "inconsistent data"); in fill_ccmp_pair()
94 ether_addr_copy(msg->peer_address, peer_addr); in fill_ccmp_pair()
95 memcpy(msg->aes_key_data, key->key, key->keylen); in fill_ccmp_pair()
100 struct ieee80211_key_conf *key, struct ieee80211_key_seq *seq) in fill_ccmp_group() argument
102 WARN(key->keylen != sizeof(msg->aes_key_data), "inconsistent data"); in fill_ccmp_group()
103 memcpy(msg->aes_key_data, key->key, key->keylen); in fill_ccmp_group()
104 memcpy(msg->rx_sequence_counter, seq->ccmp.pn, sizeof(seq->ccmp.pn)); in fill_ccmp_group()
105 memreverse(msg->rx_sequence_counter, sizeof(seq->ccmp.pn)); in fill_ccmp_group()
106 msg->key_id = key->keyidx; in fill_ccmp_group()
111 struct ieee80211_key_conf *key, u8 *peer_addr) in fill_sms4_pair() argument
113 u8 *keybuf = key->key; in fill_sms4_pair()
115 WARN(key->keylen != sizeof(msg->wapi_key_data) + sizeof(msg->mic_key_data), in fill_sms4_pair()
117 ether_addr_copy(msg->peer_address, peer_addr); in fill_sms4_pair()
118 memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data)); in fill_sms4_pair()
119 keybuf += sizeof(msg->wapi_key_data); in fill_sms4_pair()
120 memcpy(msg->mic_key_data, keybuf, sizeof(msg->mic_key_data)); in fill_sms4_pair()
121 msg->key_id = key->keyidx; in fill_sms4_pair()
126 struct ieee80211_key_conf *key) in fill_sms4_group() argument
128 u8 *keybuf = key->key; in fill_sms4_group()
130 WARN(key->keylen != sizeof(msg->wapi_key_data) + sizeof(msg->mic_key_data), in fill_sms4_group()
132 memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data)); in fill_sms4_group()
133 keybuf += sizeof(msg->wapi_key_data); in fill_sms4_group()
134 memcpy(msg->mic_key_data, keybuf, sizeof(msg->mic_key_data)); in fill_sms4_group()
135 msg->key_id = key->keyidx; in fill_sms4_group()
140 struct ieee80211_key_conf *key, struct ieee80211_key_seq *seq) in fill_aes_cmac_group() argument
142 WARN(key->keylen != sizeof(msg->igtk_key_data), "inconsistent data"); in fill_aes_cmac_group()
143 memcpy(msg->igtk_key_data, key->key, key->keylen); in fill_aes_cmac_group()
144 memcpy(msg->ipn, seq->aes_cmac.pn, sizeof(seq->aes_cmac.pn)); in fill_aes_cmac_group()
145 memreverse(msg->ipn, sizeof(seq->aes_cmac.pn)); in fill_aes_cmac_group()
146 msg->key_id = key->keyidx; in fill_aes_cmac_group()
151 struct ieee80211_key_conf *key) in wfx_add_key() argument
156 struct wfx_dev *wdev = wvif->wdev; in wfx_add_key()
157 int idx = wfx_alloc_key(wvif->wdev); in wfx_add_key()
158 bool pairwise = key->flags & IEEE80211_KEY_FLAG_PAIRWISE; in wfx_add_key()
161 WARN(key->flags & IEEE80211_KEY_FLAG_PAIRWISE && !sta, "inconsistent data"); in wfx_add_key()
162 ieee80211_get_key_rx_seq(key, 0, &seq); in wfx_add_key()
164 return -EINVAL; in wfx_add_key()
165 k.int_id = wvif->id; in wfx_add_key()
167 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || in wfx_add_key()
168 key->cipher == WLAN_CIPHER_SUITE_WEP104) { in wfx_add_key()
170 k.type = fill_wep_pair(&k.key.wep_pairwise_key, key, sta->addr); in wfx_add_key()
172 k.type = fill_wep_group(&k.key.wep_group_key, key); in wfx_add_key()
173 } else if (key->cipher == WLAN_CIPHER_SUITE_TKIP) { in wfx_add_key()
175 k.type = fill_tkip_pair(&k.key.tkip_pairwise_key, key, sta->addr); in wfx_add_key()
177 k.type = fill_tkip_group(&k.key.tkip_group_key, key, &seq, in wfx_add_key()
178 vif->type); in wfx_add_key()
179 } else if (key->cipher == WLAN_CIPHER_SUITE_CCMP) { in wfx_add_key()
181 k.type = fill_ccmp_pair(&k.key.aes_pairwise_key, key, sta->addr); in wfx_add_key()
183 k.type = fill_ccmp_group(&k.key.aes_group_key, key, &seq); in wfx_add_key()
184 } else if (key->cipher == WLAN_CIPHER_SUITE_SMS4) { in wfx_add_key()
186 k.type = fill_sms4_pair(&k.key.wapi_pairwise_key, key, sta->addr); in wfx_add_key()
188 k.type = fill_sms4_group(&k.key.wapi_group_key, key); in wfx_add_key()
189 } else if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { in wfx_add_key()
190 k.type = fill_aes_cmac_group(&k.key.igtk_group_key, key, &seq); in wfx_add_key()
191 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE; in wfx_add_key()
193 dev_warn(wdev->dev, "unsupported key type %d\n", key->cipher); in wfx_add_key()
195 return -EOPNOTSUPP; in wfx_add_key()
200 return -EOPNOTSUPP; in wfx_add_key()
202 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE | IEEE80211_KEY_FLAG_RESERVE_TAILROOM; in wfx_add_key()
203 key->hw_key_idx = idx; in wfx_add_key()
207 static int wfx_remove_key(struct wfx_vif *wvif, struct ieee80211_key_conf *key) in wfx_remove_key() argument
209 WARN(key->hw_key_idx >= MAX_KEY_ENTRIES, "corrupted hw_key_idx"); in wfx_remove_key()
210 wfx_free_key(wvif->wdev, key->hw_key_idx); in wfx_remove_key()
211 return wfx_hif_remove_key(wvif->wdev, key->hw_key_idx); in wfx_remove_key()
215 struct ieee80211_sta *sta, struct ieee80211_key_conf *key) in wfx_set_key() argument
217 int ret = -EOPNOTSUPP; in wfx_set_key()
218 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; in wfx_set_key()
220 mutex_lock(&wvif->wdev->conf_mutex); in wfx_set_key()
222 ret = wfx_add_key(wvif, sta, key); in wfx_set_key()
224 ret = wfx_remove_key(wvif, key); in wfx_set_key()
225 mutex_unlock(&wvif->wdev->conf_mutex); in wfx_set_key()