1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

net/bluetil/ad: add bluetil_ad_find_and_cmp()

This commit is contained in:
Hauke Petersen 2019-03-21 21:45:25 +01:00
parent b19fa40104
commit d293d3ece0
2 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Freie Universität Berlin
* Copyright (C) 2018,2019 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
@ -97,6 +97,20 @@ void bluetil_ad_init(bluetil_ad_t *ad, void *buf, size_t pos, size_t size);
int bluetil_ad_find(const bluetil_ad_t *ad,
uint8_t type, bluetil_ad_data_t *data);
/**
* @brief Find a specific field and compare its value against the given data
*
* @param[in] ad advertising data descriptor
* @param[in] type field to search for
* @param[in] val data to compare against
* @param[in] val_len size of @p val in byte
*
* @return true if the field was found and its data is equal to the given data
* @return false if the field was not found or the data is not equal
*/
int bluetil_ad_find_and_cmp(const bluetil_ad_t *ad, uint8_t type,
const void *val, size_t val_len);
/**
* @brief Find the given field and copy its payload into a string
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Freie Universität Berlin
* Copyright (C) 2018,2019 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
@ -59,6 +59,17 @@ int bluetil_ad_find(const bluetil_ad_t *ad, uint8_t type,
return BLUETIL_AD_NOTFOUND;
}
int bluetil_ad_find_and_cmp(const bluetil_ad_t *ad, uint8_t type,
const void *val, size_t val_len)
{
bluetil_ad_data_t field;
if (bluetil_ad_find(ad, type, &field) == BLUETIL_AD_OK) {
return ((field.len == val_len) && memcmp(val, field.data, val_len) == 0);
}
return 0;
}
int bluetil_ad_find_str(const bluetil_ad_t *ad, uint8_t type,
char *str, size_t str_len)
{