mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #11233 from haukepetersen/opt_bluetilad_find_and_cmp
net/bluetil/ad: add bluetil_ad_find_and_cmp()
This commit is contained in:
commit
1d2ccb243e
@ -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
|
||||
*
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user