From 9ef5f68d4bccb880646f7ccf4b5380cd5da0068a Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Fri, 22 Sep 2017 05:06:23 +0200 Subject: [PATCH] util: Add address type utils --- src/util.c | 16 ++++++++++++++++ src/util.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/util.c b/src/util.c index d56a2592..9299ed7d 100644 --- a/src/util.c +++ b/src/util.c @@ -131,3 +131,19 @@ bool util_string_to_address(const char *str, uint8_t *addr) return true; } + +bool util_is_group_address(const uint8_t *addr) +{ + /* 802.11-2016 section 9.2.2 */ + return util_is_bit_set(addr[0], 0); +} + +bool util_is_broadcast_address(const uint8_t *addr) +{ + /* 802.11-2016 section 9.2.4.3 */ + static const uint8_t bcast_addr[6] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + }; + + return !memcmp(addr, bcast_addr, 6); +} diff --git a/src/util.h b/src/util.h index 8b45145a..2747538d 100644 --- a/src/util.h +++ b/src/util.h @@ -36,6 +36,8 @@ const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid); bool util_ssid_is_utf8(size_t len, const uint8_t *ssid); const char *util_address_to_string(const uint8_t *addr); bool util_string_to_address(const char *str, uint8_t *addr); +bool util_is_group_address(const uint8_t *addr); +bool util_is_broadcast_address(const uint8_t *addr); static inline uint8_t util_bit_field(const uint8_t oct, int start, int num) {