[PATCH v2 2/4] common: add security_to_akms()

James Prestwood
2026-03-24T19:20:59Z

This takes a security enum and returns a bitmask of all possible
AKMs for that security type. The AKM list was refactored to be
reused by AKM_IS_PSK/AKM_IS_8021X.
---
src/common.c | 41 +++++++++++++++++++++++++++++++----------
src/common.h | 1 +
2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/src/common.c b/src/common.c
index 91979423..1e5b3b7b 100644
--- a/src/common.c
+++ b/src/common.c
@@ -28,6 +28,8 @@
#include <stdbool.h>
#include <string.h>

+#include <ell/ell.h>
+
#include "src/iwd.h"
#include "src/common.h"
#include "src/ie.h"
@@ -64,18 +66,15 @@ bool security_from_str(const char *str, enum security *security)
return true;
}

-#define AKM_IS_PSK(akm) \
-( \
- akm & (IE_RSN_AKM_SUITE_PSK | \
+#define AKMS_PSK \
+ (IE_RSN_AKM_SUITE_PSK | \
IE_RSN_AKM_SUITE_PSK_SHA256 | \
IE_RSN_AKM_SUITE_FT_USING_PSK | \
IE_RSN_AKM_SUITE_SAE_SHA256 | \
- IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256) \
-)
+ IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256)

-#define AKM_IS_8021X(akm) \
-( \
- akm & (IE_RSN_AKM_SUITE_8021X | \
+#define AKMS_8021X \
+ (IE_RSN_AKM_SUITE_8021X | \
IE_RSN_AKM_SUITE_8021X_SHA256 | \
IE_RSN_AKM_SUITE_FT_OVER_8021X | \
IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384 | \
@@ -83,8 +82,11 @@ bool security_from_str(const char *str, enum security *security)
IE_RSN_AKM_SUITE_FILS_SHA384 | \
IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256 | \
IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384 | \
- IE_RSN_AKM_SUITE_OSEN) \
-)
+ IE_RSN_AKM_SUITE_OSEN)
+
+#define AKM_IS_PSK(akm) (akm & AKMS_PSK)
+
+#define AKM_IS_8021X(akm) (akm & AKMS_8021X)

enum security security_determine(uint16_t bss_capability,
const struct ie_rsn_info *info)
@@ -103,3 +105,22 @@ enum security security_determine(uint16_t bss_capability,

return SECURITY_NONE;
}
+
+/* Returns all possible AKMs (as bitmask) for a given security type */
+uint32_t security_to_akms(enum security security)
+{
+ switch (security) {
+ case SECURITY_WEP:
+ l_warn("WEP security type not supported");
+ /* Fall through */
+ case SECURITY_NONE:
+ return 0;
+ case SECURITY_PSK:
+ return AKMS_PSK;
+ case SECURITY_8021X:
+ return AKMS_8021X;
+ default:
+ l_warn("Unhandled security type: %u", security);
+ return 0;
+ }
+}
diff --git a/src/common.h b/src/common.h
index ca12d813..7e877299 100644
--- a/src/common.h
+++ b/src/common.h
@@ -36,3 +36,4 @@ const char *security_to_str(enum security security);
bool security_from_str(const char *str, enum security *security);
enum security security_determine(uint16_t bss_capability,
const struct ie_rsn_info *info);
+uint32_t security_to_akms(enum security security);
\ No newline at end of file
--
2.34.1