]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add a helper function for recognizing BIP enum wpa_alg values
authorJouni Malinen <j@w1.fi>
Sat, 16 May 2020 21:17:55 +0000 (00:17 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 16 May 2020 22:31:19 +0000 (01:31 +0300)
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>
src/common/defs.h
src/drivers/driver_nl80211.c

index 27c55de055481bb1d9a42f13a4fecb6155513013..bbe3120de82ffd1f3c25515d46a0f076f5be08f6 100644 (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
  *
index 017cc30d59c5afcb12d1060a8becef385c5602e1..8be593a525e08a361ea5428266a604ea889b5e55 100644 (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) {