mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-28 18:32:41 +00:00
ad_parser: use bool return types
This commit is contained in:
parent
0fe46bc15b
commit
2baf01d2b2
@ -63,18 +63,18 @@ void ad_iterator_init(ad_context_t *context, uint8_t ad_len, const uint8_t * ad_
|
||||
context->offset = 0;
|
||||
}
|
||||
|
||||
int ad_iterator_has_more(const ad_context_t * context){
|
||||
bool ad_iterator_has_more(const ad_context_t * context){
|
||||
// assert chunk_len and chunk_type are withing buffer
|
||||
if ((context->offset+1) >= context->length) return 0;
|
||||
if ((context->offset+1) >= context->length) return false;
|
||||
|
||||
// assert chunk_len > 0
|
||||
int chunk_len = context->data[context->offset];
|
||||
if (chunk_len == 0) return 0;
|
||||
if (chunk_len == 0) return false;
|
||||
|
||||
// assert complete chunk fits into buffer
|
||||
if ((context->offset + 1 + chunk_len) > context->length) return 0;
|
||||
if ((context->offset + 1 + chunk_len) > context->length) return false;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// pre: ad_iterator_has_more() == 1
|
||||
@ -95,7 +95,7 @@ const uint8_t * ad_iterator_get_data(const ad_context_t * context){
|
||||
return &context->data[context->offset + 2];
|
||||
}
|
||||
|
||||
int ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid16){
|
||||
bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid16){
|
||||
ad_context_t context;
|
||||
for (ad_iterator_init(&context, ad_len, ad_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){
|
||||
uint8_t data_type = ad_iterator_get_data_type(&context);
|
||||
@ -110,7 +110,7 @@ int ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uu
|
||||
case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS:
|
||||
for (i=0; i<data_len; i+=2){
|
||||
uint16_t uuid = little_endian_read_16(data, i);
|
||||
if ( uuid == uuid16 ) return 1;
|
||||
if ( uuid == uuid16 ) return true;
|
||||
}
|
||||
break;
|
||||
case BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS:
|
||||
@ -119,17 +119,17 @@ int ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uu
|
||||
reverse_128(ad_uuid128, uuid128_bt);
|
||||
|
||||
for (i=0; i<data_len; i+=16){
|
||||
if (memcmp(uuid128_bt, &data[i], 16) == 0) return 1;
|
||||
if (memcmp(uuid128_bt, &data[i], 16) == 0) return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
int ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uint8_t * uuid128){
|
||||
bool ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uint8_t * uuid128){
|
||||
ad_context_t context;
|
||||
// input in big endian/network order, bluetooth data in little endian
|
||||
uint8_t uuid128_le[16];
|
||||
@ -150,20 +150,20 @@ int ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uint
|
||||
uint16_t uuid16 = little_endian_read_16(data, i);
|
||||
uuid_add_bluetooth_prefix(ad_uuid128, uuid16);
|
||||
|
||||
if (memcmp(ad_uuid128, uuid128_le, 16) == 0) return 1;
|
||||
if (memcmp(ad_uuid128, uuid128_le, 16) == 0) return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS:
|
||||
case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS:
|
||||
for (i=0; i<data_len; i+=16){
|
||||
if (memcmp(uuid128_le, &data[i], 16) == 0) return 1;
|
||||
if (memcmp(uuid128_le, &data[i], 16) == 0) return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,8 @@
|
||||
#define AD_PARSER_H
|
||||
|
||||
#include "btstack_config.h"
|
||||
#include "btstack_bool.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined __cplusplus
|
||||
@ -61,7 +63,7 @@ typedef struct ad_context {
|
||||
|
||||
// Advertising or Scan Response data iterator
|
||||
void ad_iterator_init(ad_context_t *context, uint8_t ad_len, const uint8_t * ad_data);
|
||||
int ad_iterator_has_more(const ad_context_t * context);
|
||||
bool ad_iterator_has_more(const ad_context_t * context);
|
||||
void ad_iterator_next(ad_context_t * context);
|
||||
|
||||
// Access functions
|
||||
@ -70,8 +72,8 @@ uint8_t ad_iterator_get_data_len(const ad_context_t * context);
|
||||
const uint8_t * ad_iterator_get_data(const ad_context_t * context);
|
||||
|
||||
// convenience function on complete advertisements
|
||||
int ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid);
|
||||
int ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uint8_t * uuid128);
|
||||
bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid);
|
||||
bool ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uint8_t * uuid128);
|
||||
|
||||
/* API_END */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user