Add a helper function for recognizing BIP enum wpa_alg values

Use a shared wpa_alg_bip() function for this and fix the case in
nl_add_key() to cover all BIP algorithms. That fix does not change any
behavior since the function is not currently used with any BIP
algorithm, but it is better to avoid surprises should it ever be needed
with IGTK.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2020-05-17 00:17:55 +03:00
parent d3cab56c04
commit 4ae3f39720
2 changed files with 10 additions and 5 deletions

View file

@ -201,6 +201,14 @@ enum wpa_alg {
WPA_ALG_BIP_CMAC_256
};
static inline int wpa_alg_bip(enum wpa_alg alg)
{
return alg == WPA_ALG_BIP_CMAC_128 ||
alg == WPA_ALG_BIP_GMAC_128 ||
alg == WPA_ALG_BIP_GMAC_256 ||
alg == WPA_ALG_BIP_CMAC_256;
}
/**
* enum wpa_states - wpa_supplicant state
*

View file

@ -3284,10 +3284,7 @@ static int wpa_driver_nl80211_set_key(struct i802_bss *bss,
goto fail2;
if (!key_msg ||
nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) ||
nla_put_flag(key_msg, (alg == WPA_ALG_BIP_CMAC_128 ||
alg == WPA_ALG_BIP_GMAC_128 ||
alg == WPA_ALG_BIP_GMAC_256 ||
alg == WPA_ALG_BIP_CMAC_256) ?
nla_put_flag(key_msg, wpa_alg_bip(alg) ?
(key_idx == 6 || key_idx == 7 ?
NL80211_KEY_DEFAULT_BEACON :
NL80211_KEY_DEFAULT_MGMT) :
@ -3356,7 +3353,7 @@ static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
if (!suite)
return -1;
if (defkey && alg == WPA_ALG_BIP_CMAC_128) {
if (defkey && wpa_alg_bip(alg)) {
if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
return -1;
} else if (defkey) {