BT Mesh Database#
Modules#
Typedefs#
Common model identifier structure for Bluetooth SIG and Vendor models.
Node element represention in the Device Composition Data (DCD)
Representation of Device Composition Data (DCD)
The provisioning-related information of a node.
Struct representing one single node.
Helper struct to keep track of which nodes are part of a given network.
Functions#
Typedef Documentation#
btmesh_db_model_id_t#
typedef struct btmesh_db_model_id_t btmesh_db_model_id_t
Common model identifier structure for Bluetooth SIG and Vendor models.
btmesh_db_element_t#
typedef struct btmesh_db_element_t btmesh_db_element_t
Node element represention in the Device Composition Data (DCD)
btmesh_db_node_dcd_t#
typedef struct btmesh_db_node_dcd_t btmesh_db_node_dcd_t
Representation of Device Composition Data (DCD)
btmesh_db_node_prov_t#
typedef struct btmesh_db_node_prov_t btmesh_db_node_prov_t
The provisioning-related information of a node.
btmesh_db_node_t#
typedef struct btmesh_db_node_t btmesh_db_node_t
Struct representing one single node.
btmesh_db_nodelist_elem_t#
typedef struct btmesh_db_nodelist_elem_t btmesh_db_nodelist_elem_t
Helper struct to keep track of which nodes are part of a given network.
Function Documentation#
btmesh_db_init#
void btmesh_db_init (void )
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Initialize the database.
btmesh_db_get_node_list#
sl_slist_node_t * btmesh_db_get_node_list (void )
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Get the node list.
Returns
Pointer to the head of the node linked list
btmesh_db_get_network_list#
sl_slist_node_t * btmesh_db_get_network_list (void )
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Get the network list.
Returns
Pointer to the head of the network linked list
btmesh_db_create_network#
sl_status_t btmesh_db_create_network (uint16_t netkey_index)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | netkey_index of the network |
Create a new BT Mesh network in the database.
Returns
Status of the network creation.
Return values
SL_STATUS_OK: If network is correctly created.
SL_STATUS_ALREADY_EXIST: If a network with the given netkey_index already exists.
SL_STATUS_ALLOCATION_FAILED: If allocating memory for the network struct fails.
btmesh_db_remove_network#
void btmesh_db_remove_network (btmesh_db_network_t * network)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| btmesh_db_network_t * | [in] | network | Pointer to the network to be deleted |
Remove network from the database. This also removes the reference to the network in all nodes that were part of it.
btmesh_db_create_node#
sl_status_t btmesh_db_create_node (uuid_128 uuid, bd_addr mac_address, uint16_t prim_address, uint8_t element_count, uint8_t bearer_type, uint16_t oob_capabilities)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uuid_128 | [in] | uuid | UUID of the node |
| bd_addr | [in] | mac_address | Bluetooth address of the node |
| uint16_t | [in] | prim_address | Primary address of the node in a network |
| uint8_t | [in] | element_count | Element count of the node |
| uint8_t | [in] | bearer_type | Type of the provisioning bearer layer. Can be PB-ADV (0) or PB-GATT (1). |
| uint16_t | N/A | oob_capabilities |
Create a new node and add it to the node list.
Returns
Status of the node creation.
Return values
SL_STATUS_OK: If node is successfully created.
SL_STATUS_ALREADY_EXIST: If a node with the given UUID already exists.
SL_STATUS_ALLOCATION_FAILED: If allocating memory for the node struct fails.
btmesh_db_remove_node_by_uuid#
sl_status_t btmesh_db_remove_node_by_uuid (uuid_128 uuid)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uuid_128 | [in] | uuid | UUID of the node to be removed |
Remove a node from the database by its UUID. This function removes the node from all networks it is present in.
Returns
Status of the removal.
Return values
SL_STATUS_OK: If node is successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node does not exist.
btmesh_db_remove_node_by_addr#
sl_status_t btmesh_db_remove_node_by_addr (uint16_t prim_address)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | prim_address | Primary element address of the node to be removed |
Remove a node from the database by its primary element address. This function removes the node from all networks it is present in.
Returns
Status of the removal.
Return values
SL_STATUS_OK: If node is successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node does not exist.
btmesh_db_remove_node_by_mac#
sl_status_t btmesh_db_remove_node_by_mac (bd_addr mac)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| bd_addr | [in] | mac | Bluetooth address of the node to be removed |
Remove a node from the database by its Bluetooth address. This function removes the node from all networks it is present in.
Returns
Status of the removal.
Return values
SL_STATUS_OK: If node is successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node does not exist.
btmesh_db_add_node_to_network_by_uuid#
sl_status_t btmesh_db_add_node_to_network_by_uuid (uint16_t netkey_index, uuid_128 uuid)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the network |
| uuid_128 | [in] | uuid | UUID of the node |
Add an already created node to a network by UUID
Returns
Status of the addition.
Return values
SL_STATUS_OK: If node is successfully added to the network.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If either the node or the network does not exist.
SL_STATUS_ALREADY_EXISTS: If the node is already in the network.
SL_STATUS_ALLOCATION_FAILED: If the node
btmesh_db_node_dcd_set_available#
sl_status_t btmesh_db_node_dcd_set_available (uint16_t prim_address)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | prim_address | Primary element address of the node |
Makes the DCD information available for reading in the BT Mesh database
Returns
Status of the set available operation
Return values
SL_STATUS_OK: If DCD information is set available
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node does not exist.
The DCD information of a node is built in several steps in btmesh database:
btmesh_db_node_dcd_add_element (element count times)
btmesh_db_node_dcd_add_model (on each element model count times)
The DCD information is not valid until all necessary functions are called. This function marks when the DCD information is complete in the database.
btmesh_db_node_dcd_set_header#
sl_status_t btmesh_db_node_dcd_set_header (uint16_t prim_address, uint16_t company_id, uint16_t product_id, uint16_t version_id, uint16_t min_replay_prot_list_len, bool feature_relay, bool feature_proxy, bool feature_friend, bool feature_low_power)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | prim_address | Primary element address of the node |
| uint16_t | [in] | company_id | Company identifier assigned by the Bluetooth SIG |
| uint16_t | [in] | product_id | Vendor-assigned product identifier |
| uint16_t | [in] | version_id | Vendor-assigned product version identifier |
| uint16_t | [in] | min_replay_prot_list_len | Min number of replay protection list entries |
| bool | [in] | feature_relay | Relay feature support |
| bool | [in] | feature_proxy | Proxy feature support |
| bool | [in] | feature_friend | Friend feature support |
| bool | [in] | feature_low_power | Low power feature support |
Sets the DCD header data (page 0) in the BT Mesh database
Returns
Status of the set node DCD header operation
Return values
SL_STATUS_OK: If DCD header data is set successfully.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node does not exist.
SL_STATUS_INVALID_STATE: If the DCD can't be modified because it was set available previously.
Sets DCD header data of the node chosen by prim_address in BT Mesh database. The DCD header data not vary with the number of elements or models.
If the DCD is set available then the DCD data can be modified only if it is cleared first by the btmesh_db_node_dcd_clear function.
Note
If the firmware is updated on the node then the DCD of the node might change (not necessarily). The BT Mesh specification guarantees that the DCD is constant between firmware updates.
btmesh_db_node_dcd_add_element#
sl_status_t btmesh_db_node_dcd_add_element (uint16_t prim_address, uint16_t location)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | prim_address | Primary element address of the node |
| uint16_t | [in] | location | Location description as defined in the GATT Bluetooth Namespace Descriptors section of the Bluetooth SIG Assigned Numbers |
Adds an empty element to the DCD of specified node in BT Mesh database
Returns
Status of element addition
Return values
SL_STATUS_OK: If the element is added successfully.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node does not exist.
SL_STATUS_INVALID_STATE: If the DCD can't be modified because it was set available previously.
SL_STATUS_ALLOCATION_FAILED: If the memory allocation for the new element is failed.
The new empty element is added to end of element array of DCD in BT Mesh database. Therefore the elements shall be added in the increasing order of element indexes.
btmesh_db_node_dcd_add_model#
sl_status_t btmesh_db_node_dcd_add_model (uint16_t prim_address, uint16_t element_index, btmesh_db_model_id_t model_id)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | prim_address | Primary element address of the node |
| uint16_t | [in] | element_index | Index of element where the model resides on the node |
| btmesh_db_model_id_t | [in] | model_id | Model ID of the model |
Adds a model to the specified DCD element in BT Mesh database
Returns
Status of the model addition
Return values
SL_STATUS_OK: If the model is added successfully.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node or element does not exist.
SL_STATUS_INVALID_STATE: If the DCD can't be modified because it was set available previously.
SL_STATUS_ALREADY_EXISTS: If the model ID is already added to element. The model IDs shall be unique in the context of a node element.
SL_STATUS_ALLOCATION_FAILED: If the memory allocation for the new model is failed.
btmesh_db_node_dcd_clear#
sl_status_t btmesh_db_node_dcd_clear (uint16_t prim_address)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | prim_address | Primary element address of the node |
Clears the DCD of the specified node in BT Mesh database
Returns
Status of the DCD clear operation
Return values
SL_STATUS_OK: If the DCD is cleared successfully.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the node does not exist.
The DCD clear operation deallocates all dynamically allocated resources belonging to the DCD of the specified node and sets the DCD unavailable. If the DCD was set available then it can be modified only if the current DCD of the node is cleared first by calling this function.
btmesh_db_remove_node_from_network#
sl_status_t btmesh_db_remove_node_from_network (uint16_t netkey_index, btmesh_db_node_t * node)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the network |
| btmesh_db_node_t * | [in] | node | Pointer to the node |
Remove a node from a given network.
Returns
Status of the node removal.
Return values
SL_STATUS_OK: If node is successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If either the network does not exist or the node is not in the network.
btmesh_db_remove_node_from_network_by_addr#
sl_status_t btmesh_db_remove_node_from_network_by_addr (uint16_t netkey_index, uint16_t prim_address)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the network |
| uint16_t | [in] | prim_address | Primary address of the node |
Remove a node from a given network by the node's primary element address.
Returns
Status of the node removal.
Return values
SL_STATUS_OK: If node is successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If either the network or node does not exist, or the node is not in the network.
btmesh_db_remove_node_from_network_by_uuid#
sl_status_t btmesh_db_remove_node_from_network_by_uuid (uint16_t netkey_index, uuid_128 uuid)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the network |
| uuid_128 | [in] | uuid | UUID of the network |
Remove a node from a given network by the node's UUID.
Returns
Status of the node removal.
Return values
SL_STATUS_OK: If node is successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If either the network or node does not exist, or the node is not in the network.
btmesh_db_remove_node_from_network_by_mac#
sl_status_t btmesh_db_remove_node_from_network_by_mac (uint16_t netkey_index, bd_addr mac)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the network |
| bd_addr | [in] | mac | Bluetooth address of the node |
Remove a node from a given network by the node's Bluetooth address.
Returns
Status of the node removal.
Return values
SL_STATUS_OK: If node is successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If either the network or node does not exist, or the node is not in the network.
btmesh_db_remove_all_nodes_from_network#
sl_status_t btmesh_db_remove_all_nodes_from_network (uint16_t netkey_index)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the network |
Remove all nodes from a give network
Returns
Status of the node removal.
Return values
SL_STATUS_OK: If nodes are successfully removed.
SL_STATUS_BT_MESH_DOES_NOT_EXIST: If the network does not exist.
btmesh_db_node_get_by_addr#
btmesh_db_node_t * btmesh_db_node_get_by_addr (uint16_t address)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | address | Primary element address of the node |
Get a node by its primary element address
Returns
Pointer to the node, NULL if it does not exist.
btmesh_db_node_get_by_uuid#
btmesh_db_node_t * btmesh_db_node_get_by_uuid (uuid_128 uuid)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uuid_128 | [in] | uuid | UUID of the node |
Get a node by its UUID
Returns
Pointer to the node, NULL if it does not exist.
btmesh_db_node_get_by_mac#
btmesh_db_node_t * btmesh_db_node_get_by_mac (bd_addr mac)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| bd_addr | [in] | mac | Bluetooth address of the node |
Get a node by its Bluetooth address
Returns
Pointer to the node, NULL if it does not exist.
btmesh_db_node_set_availability#
sl_status_t btmesh_db_node_set_availability (btmesh_db_node_t * node, bool availability)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| btmesh_db_node_t * | [in] | node | Pointer to the node |
| bool | [in] | availability | The requested status of the availability flag |
Set the availability parameter of a given node
Returns
Status of the command.
Return values
SL_STATUS_OK: If availability flag is set.
SL_STATUS_NULL_POINTER: If the node does not exist.
btmesh_db_node_set_primary_address#
sl_status_t btmesh_db_node_set_primary_address (btmesh_db_node_t * node, uint16_t primary_address)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| btmesh_db_node_t * | [in] | node | Pointer to the node |
| uint16_t | [in] | primary_address | The requested primary element address |
Set the Primary element address of a given node
Returns
Status of the command.
Return values
SL_STATUS_OK: If primary element address is set.
SL_STATUS_NULL_POINTER: If the node does not exist.
btmesh_db_network_get_network#
btmesh_db_network_t * btmesh_db_network_get_network (uint16_t netkey_index)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the requested network |
Get a network by its netkey index
Returns
pointer to the network. NULL if network does not exist.
btmesh_db_is_node_in_network#
bool btmesh_db_is_node_in_network (uint16_t netkey_index, btmesh_db_node_t * node)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | netkey_index | Netkey index of the network |
| btmesh_db_node_t * | [in] | node | Pointer to the node |
Check if a given node is part of a network
btmesh_db_is_node_in_any_network#
bool btmesh_db_is_node_in_any_network (btmesh_db_node_t * node)
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| btmesh_db_node_t * | [in] | node | Pointer to the node |
Check if a given node is part of any network