diff --git a/src/hotspot.c b/src/hotspot.c index dec73ae0..1ef36b6d 100644 --- a/src/hotspot.c +++ b/src/hotspot.c @@ -192,9 +192,11 @@ static bool hotspot_match_hessid(const struct network_info *info, return !memcmp(config->hessid, hessid, 6); } -static bool hotspot_match_roaming_consortium(const struct network_info *info, +static const uint8_t *hotspot_match_roaming_consortium( + const struct network_info *info, const uint8_t *rc_ie, - size_t rc_len) + size_t rc_len, + size_t *rc_len_out) { const uint8_t *rc1, *rc2, *rc3; size_t rc1_len, rc2_len, rc3_len; @@ -202,26 +204,35 @@ static bool hotspot_match_roaming_consortium(const struct network_info *info, super); if (!config->rc || !rc_ie) - return false; + return NULL; if (ie_parse_roaming_consortium_from_data(rc_ie, rc_ie[1] + 2, NULL, &rc1, &rc1_len, &rc2, &rc2_len, &rc3, &rc3_len) < 0) - return false; + return NULL; /* rc1 is guarenteed to be set if the above returns success */ - if (rc1_len == config->rc_len && !memcmp(rc1, config->rc, rc1_len)) - return true; + if (rc1_len == config->rc_len && !memcmp(rc1, config->rc, rc1_len)) { + if (rc_len_out) + *rc_len_out = rc1_len; + return rc1; + } if (rc2 && rc2_len == config->rc_len && - !memcmp(rc2, config->rc, rc2_len)) - return true; + !memcmp(rc2, config->rc, rc2_len)) { + if (rc_len_out) + *rc_len_out = rc2_len; + return rc2; + } if (rc3 && rc1_len == config->rc_len && - !memcmp(rc3, config->rc, rc3_len)) - return true; + !memcmp(rc3, config->rc, rc3_len)) { + if (rc_len_out) + *rc_len_out = rc3_len; + return rc3; + } - return false; + return NULL; } static bool hotspot_match_nai_realms(const struct network_info *info, diff --git a/src/knownnetworks.c b/src/knownnetworks.c index 124eddc5..3cf4270b 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -221,14 +221,17 @@ bool network_info_match_hessid(const struct network_info *info, return info->ops->match_hessid(info, hessid); } -bool network_info_match_roaming_consortium(const struct network_info *info, +const uint8_t *network_info_match_roaming_consortium( + const struct network_info *info, const uint8_t *rc, - size_t rc_len) + size_t rc_len, + size_t *rc_len_out) { if (!info->ops->match_roaming_consortium) - return false; + return NULL; - return info->ops->match_roaming_consortium(info, rc, rc_len); + return info->ops->match_roaming_consortium(info, rc, rc_len, + rc_len_out); } bool network_info_match_nai_realm(const struct network_info *info, diff --git a/src/knownnetworks.h b/src/knownnetworks.h index ff4320be..c7aa2237 100644 --- a/src/knownnetworks.h +++ b/src/knownnetworks.h @@ -41,9 +41,11 @@ struct network_info_ops { bool (*match_hessid)(const struct network_info *info, const uint8_t *hessid); - bool (*match_roaming_consortium)(const struct network_info *info, + const uint8_t *(*match_roaming_consortium)( + const struct network_info *info, const uint8_t *rc_ie, - size_t rc_len); + size_t rc_len, + size_t *rc_len_out); bool (*match_nai_realms)(const struct network_info *info, const char **nai_realms); }; @@ -96,9 +98,11 @@ const char *network_info_get_type(const struct network_info *info); bool network_info_match_hessid(const struct network_info *info, const uint8_t *hessid); -bool network_info_match_roaming_consortium(const struct network_info *info, +const uint8_t *network_info_match_roaming_consortium( + const struct network_info *info, const uint8_t *rc, - size_t rc_len); + size_t rc_len, + size_t *rc_len_out); bool network_info_match_nai_realm(const struct network_info *info, const char **nai_realms); diff --git a/src/network.c b/src/network.c index ac914e71..b8d7bb35 100644 --- a/src/network.c +++ b/src/network.c @@ -575,7 +575,8 @@ static bool hotspot_info_matches(struct network *network, return true; if (network_info_match_roaming_consortium(info, bss->rc_ie, - bss->rc_ie[1] + 2)) + bss->rc_ie[1] + 2, + NULL)) return true; return false;