Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
data.h File Reference

Bluetooth data types and helpers. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  bt_data
 Bluetooth data. More...

Macros

#define BT_DATA_SERIALIZED_SIZE(data_len)
 Get the size of a serialized bt_data given its data length.
#define BT_DATA(_type, _data, _data_len)
 Helper to declare elements of bt_data arrays.
#define BT_DATA_BYTES(_type, _bytes...)
 Helper to declare elements of bt_data arrays.

Functions

size_t bt_data_get_len (const struct bt_data data[], size_t data_count)
 Get the total size (in octets) of a given set of bt_data structures.
size_t bt_data_serialize (const struct bt_data *input, uint8_t *output)
 Serialize a bt_data struct into an advertising structure (a flat array).

Detailed Description

Bluetooth data types and helpers.

Macro Definition Documentation

◆ BT_DATA

#define BT_DATA ( _type,
_data,
_data_len )
Value:
{ \
.type = (_type), \
.data_len = (_data_len), \
.data = (const uint8_t *)(_data), \
}
__UINT8_TYPE__ uint8_t
Definition stdint.h:88

Helper to declare elements of bt_data arrays.

This macro is mainly for creating an array of struct bt_data elements which is then passed to e.g. bt_le_adv_start function.

Parameters
_typeType of advertising data field
_dataPointer to the data field payload
_data_lenNumber of octets behind the _data pointer

◆ BT_DATA_BYTES

#define BT_DATA_BYTES ( _type,
_bytes... )
Value:
BT_DATA(_type, ((uint8_t []) { _bytes }), \
sizeof((uint8_t []) { _bytes }))
#define BT_DATA(_type, _data, _data_len)
Helper to declare elements of bt_data arrays.
Definition data.h:59

Helper to declare elements of bt_data arrays.

This macro is mainly for creating an array of struct bt_data elements which is then passed to e.g. bt_le_adv_start function.

Parameters
_typeType of advertising data field
_bytesVariable number of single-byte parameters

◆ BT_DATA_SERIALIZED_SIZE

#define BT_DATA_SERIALIZED_SIZE ( data_len)
Value:
((data_len) + 2)

Get the size of a serialized bt_data given its data length.

Size of 'AD Structure'->'Length' field, equal to 1. Size of 'AD Structure'->'Data'->'AD Type' field, equal to 1. Size of 'AD Structure'->'Data'->'AD Data' field, equal to data_len.

See Core Specification Version 5.4 Vol. 3 Part C, 11, Figure 11.1.

Function Documentation

◆ bt_data_get_len()

size_t bt_data_get_len ( const struct bt_data data[],
size_t data_count )

Get the total size (in octets) of a given set of bt_data structures.

The total size includes the length (1 octet) and type (1 octet) fields for each element, plus their respective data lengths.

Parameters
[in]dataArray of bt_data structures.
[in]data_countNumber of bt_data structures in data.
Returns
Size of the concatenated data, built from the bt_data structure set.

◆ bt_data_serialize()

size_t bt_data_serialize ( const struct bt_data * input,
uint8_t * output )

Serialize a bt_data struct into an advertising structure (a flat array).

The data are formatted according to the Bluetooth Core Specification v. 5.4, vol. 3, part C, 11.

Parameters
[in]inputSingle bt_data structure to read from.
[out]outputBuffer large enough to store the advertising structure in input. The size of it must be at least the size of the input->data_len + 2 (for the type and the length).
Returns
Number of octets written in output.