From c93966d5a18d6222d26c276f4b4cfb7626b6ddc6 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 3 Sep 2021 16:26:46 -0500 Subject: [PATCH] ie: Add parse utility for network cost vendor IE --- src/ie.c | 20 ++++++++++++++++++++ src/ie.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/ie.c b/src/ie.c index 0aa86af6..1ce1d8a5 100644 --- a/src/ie.c +++ b/src/ie.c @@ -2472,3 +2472,23 @@ void ie_build_fils_ip_addr_response( done: *len = to - (len + 1); } + +/* + * Parse Network Cost IE according to: + * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nct/88f0cdf4-cdf2-4455-b849-4abf1e5c11ac + */ +int ie_parse_network_cost(const void *data, size_t len, + uint16_t *level, uint16_t *flags) +{ + const uint8_t *ie = data; + + if (len < 10 || ie[0] != IE_TYPE_VENDOR_SPECIFIC || ie[1] != 8) + return -ENOMSG; + + if (memcmp(ie + 2, microsoft_oui, 3) || ie[5] != 0x11) + return -ENOMSG; + + *level = l_get_le16(ie + 6); + *flags = l_get_le16(ie + 8); + return 0; +} diff --git a/src/ie.h b/src/ie.h index 8d4ab3c1..a2fdc2e3 100644 --- a/src/ie.h +++ b/src/ie.h @@ -626,3 +626,6 @@ int ie_parse_fils_ip_addr_response(struct ie_tlv_iter *iter, void ie_build_fils_ip_addr_response( const struct ie_fils_ip_addr_response_info *info, uint8_t *to); + +int ie_parse_network_cost(const void *data, size_t len, + uint16_t *flags, uint16_t *level);