diff options
author | Thomas Haller <thaller@redhat.com> | 2020-01-04 16:34:44 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-02-10 19:11:50 +0100 |
commit | 02e5fade5571626f455e525a06b8c86564f9ffd1 (patch) | |
tree | e98f4e4fb35f4215029d47c08eab332b68ce3888 /src/supplicant | |
parent | 1cc65fff1d61fd56a21f1ca2dce53e6485a0b088 (diff) | |
download | NetworkManager-02e5fade5571626f455e525a06b8c86564f9ffd1.tar.gz |
supplicant: add enum for supplicant capabilities (features)
We should handle features/capabilities more generically.
Add an enum type for that. It will be used next.
Also, wpa_supplicant calls this "Capabilities", not features.
Use that name.
Diffstat (limited to 'src/supplicant')
-rw-r--r-- | src/supplicant/nm-supplicant-types.h | 84 | ||||
-rw-r--r-- | src/supplicant/tests/test-supplicant-config.c | 39 |
2 files changed, 123 insertions, 0 deletions
diff --git a/src/supplicant/nm-supplicant-types.h b/src/supplicant/nm-supplicant-types.h index 2b3563548b..dc005c8e3e 100644 --- a/src/supplicant/nm-supplicant-types.h +++ b/src/supplicant/nm-supplicant-types.h @@ -14,6 +14,90 @@ typedef struct _NMSupplicantManager NMSupplicantManager; typedef struct _NMSupplicantInterface NMSupplicantInterface; typedef struct _NMSupplicantConfig NMSupplicantConfig; +/*****************************************************************************/ + +typedef enum { + NM_SUPPL_CAP_TYPE_AP = 0, + NM_SUPPL_CAP_TYPE_FAST, + NM_SUPPL_CAP_TYPE_PMF, + NM_SUPPL_CAP_TYPE_FILS, + NM_SUPPL_CAP_TYPE_P2P, + NM_SUPPL_CAP_TYPE_MESH, + NM_SUPPL_CAP_TYPE_WFD, + NM_SUPPL_CAP_TYPE_FT, + NM_SUPPL_CAP_TYPE_SHA384, + _NM_SUPPL_CAP_TYPE_NUM, +} NMSupplCapType; + +#define NM_SUPPL_CAP_MASK_NO(type) ((NMSupplCapMask) (1llu << ((type) * 2u))) +#define NM_SUPPL_CAP_MASK_YES(type) ((NMSupplCapMask) (2llu << ((type) * 2u))) +#define NM_SUPPL_CAP_MASK_MASK(type) ((NMSupplCapMask) (3llu << ((type) * 2u))) + +typedef enum { + NM_SUPPL_CAP_MASK_NONE = 0, + NM_SUPPL_CAP_MASK_ALL = ((1llu << (_NM_SUPPL_CAP_TYPE_NUM * 2)) - 1), + +/* usually it's bad to use macros to define enum values (because you cannot find them with ctags/cscope + * anymore. In this case, still do it because the alternative is ugly too. */ +#define _NM_SUPPL_CAP_MASK_DEFINE(type) \ + NM_SUPPL_CAP_MASK_T_##type##_NO = (1llu << ((NM_SUPPL_CAP_TYPE_##type) * 2u)), \ + NM_SUPPL_CAP_MASK_T_##type##_YES = (2llu << ((NM_SUPPL_CAP_TYPE_##type) * 2u)), \ + NM_SUPPL_CAP_MASK_T_##type##_MASK = (3llu << ((NM_SUPPL_CAP_TYPE_##type) * 2u)) + _NM_SUPPL_CAP_MASK_DEFINE (AP), + _NM_SUPPL_CAP_MASK_DEFINE (FAST), + _NM_SUPPL_CAP_MASK_DEFINE (PMF), + _NM_SUPPL_CAP_MASK_DEFINE (FILS), + _NM_SUPPL_CAP_MASK_DEFINE (P2P), + _NM_SUPPL_CAP_MASK_DEFINE (MESH), + _NM_SUPPL_CAP_MASK_DEFINE (WFD), + _NM_SUPPL_CAP_MASK_DEFINE (FT), + _NM_SUPPL_CAP_MASK_DEFINE (SHA384), +#undef _NM_SUPPL_CAP_MASK_DEFINE +} NMSupplCapMask; + +static inline NMSupplCapMask +NM_SUPPL_CAP_MASK_SET (NMSupplCapMask features, NMSupplCapType type, NMTernary value) +{ + nm_assert (_NM_INT_NOT_NEGATIVE (type)); + nm_assert (type < _NM_SUPPL_CAP_TYPE_NUM); + nm_assert (NM_IN_SET (value, NM_TERNARY_DEFAULT, + NM_TERNARY_TRUE, + NM_TERNARY_FALSE)); + nm_assert (!(features & ~NM_SUPPL_CAP_MASK_ALL)); + + features &= ~NM_SUPPL_CAP_MASK_MASK (type); + switch (value) { + case NM_TERNARY_FALSE: + features |= NM_SUPPL_CAP_MASK_NO (type); + break; + case NM_TERNARY_TRUE: + features |= NM_SUPPL_CAP_MASK_YES (type); + break; + case NM_TERNARY_DEFAULT: + break; + } + + return features; +} + +static inline NMTernary +NM_SUPPL_CAP_MASK_GET (NMSupplCapMask features, NMSupplCapType type) +{ + int f; + + nm_assert (_NM_INT_NOT_NEGATIVE (type)); + nm_assert (type < _NM_SUPPL_CAP_TYPE_NUM); + nm_assert (!(features & ~NM_SUPPL_CAP_MASK_ALL)); + + f = ((int) (features >> (2 * (int) type))) & 0x3; + + nm_assert (NM_IN_SET (f, 0, 1, 2)); + + return (NMTernary) (f - 1); +} + +/*****************************************************************************/ + typedef enum { NM_SUPPLICANT_FEATURE_UNKNOWN = 0, /* Can't detect whether supported or not */ NM_SUPPLICANT_FEATURE_NO = 1, /* Feature definitely not supported */ diff --git a/src/supplicant/tests/test-supplicant-config.c b/src/supplicant/tests/test-supplicant-config.c index 008735b423..401b6b8561 100644 --- a/src/supplicant/tests/test-supplicant-config.c +++ b/src/supplicant/tests/test-supplicant-config.c @@ -621,6 +621,44 @@ test_wifi_eap_fils_disabled (void) validate_opt ("wifi-eap", config_dict, "bgscan", TYPE_BYTES, bgscan); } +/*****************************************************************************/ + +static void +test_suppl_cap_mask (void) +{ + NMSupplCapType type; + + g_assert_cmpint (NM_SUPPL_CAP_MASK_GET (NM_SUPPL_CAP_MASK_T_AP_NO, NM_SUPPL_CAP_TYPE_AP), ==, NM_TERNARY_FALSE); + g_assert_cmpint (NM_SUPPL_CAP_MASK_GET (NM_SUPPL_CAP_MASK_T_AP_YES, NM_SUPPL_CAP_TYPE_AP), ==, NM_TERNARY_TRUE); + g_assert_cmpint (NM_SUPPL_CAP_MASK_GET (NM_SUPPL_CAP_MASK_NONE, NM_SUPPL_CAP_TYPE_AP), ==, NM_TERNARY_DEFAULT); + + g_assert_cmpint (NM_SUPPL_CAP_MASK_GET (NM_SUPPL_CAP_MASK_T_FILS_NO, NM_SUPPL_CAP_TYPE_FILS), ==, NM_TERNARY_FALSE); + g_assert_cmpint (NM_SUPPL_CAP_MASK_GET (NM_SUPPL_CAP_MASK_T_FILS_YES, NM_SUPPL_CAP_TYPE_FILS), ==, NM_TERNARY_TRUE); + g_assert_cmpint (NM_SUPPL_CAP_MASK_GET (NM_SUPPL_CAP_MASK_NONE, NM_SUPPL_CAP_TYPE_FILS), ==, NM_TERNARY_DEFAULT); + + for (type = 0; type < _NM_SUPPL_CAP_TYPE_NUM; type++) { + NMTernary value; + NMSupplCapMask feature; + NMSupplCapMask feature2; + + feature = nmtst_get_rand_bool () + ? 0u + : nmtst_get_rand_uint64 (); + feature &= NM_SUPPL_CAP_MASK_ALL; + + value = nmtst_rand_select (NM_TERNARY_DEFAULT, + NM_TERNARY_FALSE, + NM_TERNARY_TRUE); + + feature2 = NM_SUPPL_CAP_MASK_SET (feature, type, value); + + g_assert_cmpint (NM_SUPPL_CAP_MASK_GET (feature2, type), ==, value); + g_assert_cmpint (feature & ~NM_SUPPL_CAP_MASK_MASK (type), ==, feature2 & ~NM_SUPPL_CAP_MASK_MASK (type)); + } +} + +/*****************************************************************************/ + NMTST_DEFINE (); int main (int argc, char **argv) @@ -634,6 +672,7 @@ int main (int argc, char **argv) g_test_add_func ("/supplicant-config/wifi-eap/unlocked-bssid", test_wifi_eap_unlocked_bssid); g_test_add_func ("/supplicant-config/wifi-eap/fils-disabled", test_wifi_eap_fils_disabled); g_test_add_func ("/supplicant-config/wifi-sae", test_wifi_sae); + g_test_add_func ("/supplicant-config/test_suppl_cap_mask", test_suppl_cap_mask); return g_test_run (); } |