From 4ae3f3972077cb7873fe47d1fd08a5f77b1d3430 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 17 May 2020 00:17:55 +0300 Subject: [PATCH] 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 --- src/common/defs.h | 8 ++++++++ src/drivers/driver_nl80211.c | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/defs.h b/src/common/defs.h index 27c55de05..bbe3120de 100644 --- a/src/common/defs.h +++ b/src/common/defs.h @@ -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 * diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 017cc30d5..8be593a52 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -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) {