From d4cdd74ae003519ddbb8c76c364f696107709592 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 21 May 2015 20:58:42 -0500 Subject: [PATCH] ie: Add ie_rsn_cipher_suite_to_cipher --- src/ie.c | 25 +++++++++++++++++++++++++ src/ie.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/ie.c b/src/ie.c index 492c8193..e088a9af 100644 --- a/src/ie.c +++ b/src/ie.c @@ -27,6 +27,7 @@ #include #include #include "util.h" +#include "crypto.h" #include "ie.h" @@ -178,6 +179,30 @@ void ie_tlv_builder_finalize(struct ie_tlv_builder *builder, *out_len = len; } +/* + * Converts RSN cipher suite into an unsigned integer suitable to be used + * by nl80211. The enumeration is the same as found in crypto.h + * + * If the suite value is invalid, this function returns 0. + */ +uint32_t ie_rsn_cipher_suite_to_cipher(enum ie_rsn_cipher_suite suite) +{ + switch (suite) { + case IE_RSN_CIPHER_SUITE_CCMP: + return CRYPTO_CIPHER_CCMP; + case IE_RSN_CIPHER_SUITE_TKIP: + return CRYPTO_CIPHER_TKIP; + case IE_RSN_CIPHER_SUITE_WEP40: + return CRYPTO_CIPHER_WEP40; + case IE_RSN_CIPHER_SUITE_WEP104: + return CRYPTO_CIPHER_WEP104; + case IE_RSN_CIPHER_SUITE_BIP: + return CRYPTO_CIPHER_BIP; + default: + return 0; + } +} + /* 802.11, Section 8.4.2.27.2 */ static bool ie_parse_cipher_suite(const uint8_t *data, enum ie_rsn_cipher_suite *out) diff --git a/src/ie.h b/src/ie.h index d6d5ecc5..56bdd368 100644 --- a/src/ie.h +++ b/src/ie.h @@ -249,6 +249,7 @@ static inline const unsigned char *ie_tlv_iter_get_data( return iter->data; } +uint32_t ie_rsn_cipher_suite_to_cipher(enum ie_rsn_cipher_suite suite); bool ie_tlv_iter_next(struct ie_tlv_iter *iter); bool ie_tlv_builder_init(struct ie_tlv_builder *builder); bool ie_tlv_builder_set_length(struct ie_tlv_builder *builder,