Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Message . More...

Data Structures

struct  bt_mesh_msg_ctx
 Message sending context. More...
 
struct  bt_mesh_msg_ack_ctx
 Acknowledged message context for tracking the status of model messages pending a response. More...
 

Macros

#define BT_MESH_MIC_SHORT   4
 Length of a short Mesh MIC.
 
#define BT_MESH_MIC_LONG   8
 Length of a long Mesh MIC.
 
#define BT_MESH_MODEL_OP_LEN(_op)
 Helper to determine the length of an opcode.
 
#define BT_MESH_MODEL_BUF_LEN(_op, _payload_len)
 Helper for model message buffer length.
 
#define BT_MESH_MODEL_BUF_LEN_LONG_MIC(_op, _payload_len)
 Helper for model message buffer length.
 
#define BT_MESH_MODEL_BUF_DEFINE(_buf, _op, _payload_len)
 Define a Mesh model message buffer using NET_BUF_SIMPLE_DEFINE.
 
#define BT_MESH_MSG_CTX_INIT(net_key_idx, app_key_idx, dst, ttl)
 Helper for bt_mesh_msg_ctx structure initialization.
 
#define BT_MESH_MSG_CTX_INIT_APP(app_key_idx, dst)
 Helper for bt_mesh_msg_ctx structure initialization secured with Application Key.
 
#define BT_MESH_MSG_CTX_INIT_DEV(net_key_idx, dst)
 Helper for bt_mesh_msg_ctx structure initialization secured with Device Key of a remote device.
 
#define BT_MESH_MSG_CTX_INIT_PUB(pub)
 Helper for bt_mesh_msg_ctx structure initialization using Model Publication context.
 

Functions

void bt_mesh_model_msg_init (struct net_buf_simple *msg, uint32_t opcode)
 Initialize a model message.
 
static void bt_mesh_msg_ack_ctx_init (struct bt_mesh_msg_ack_ctx *ack)
 Initialize an acknowledged message context.
 
static void bt_mesh_msg_ack_ctx_reset (struct bt_mesh_msg_ack_ctx *ack)
 Reset the synchronization semaphore in an acknowledged message context.
 
void bt_mesh_msg_ack_ctx_clear (struct bt_mesh_msg_ack_ctx *ack)
 Clear parameters of an acknowledged message context.
 
int bt_mesh_msg_ack_ctx_prepare (struct bt_mesh_msg_ack_ctx *ack, uint32_t op, uint16_t dst, void *user_data)
 Prepare an acknowledged message context for the incoming message to wait.
 
static bool bt_mesh_msg_ack_ctx_busy (struct bt_mesh_msg_ack_ctx *ack)
 Check if the acknowledged message context is initialized with an opcode.
 
int bt_mesh_msg_ack_ctx_wait (struct bt_mesh_msg_ack_ctx *ack, k_timeout_t timeout)
 Wait for a message acknowledge.
 
static void bt_mesh_msg_ack_ctx_rx (struct bt_mesh_msg_ack_ctx *ack)
 Mark a message as acknowledged.
 
bool bt_mesh_msg_ack_ctx_match (const struct bt_mesh_msg_ack_ctx *ack, uint32_t op, uint16_t addr, void **user_data)
 Check if an opcode and address of a message matches the expected one.
 

Detailed Description

Message .

Macro Definition Documentation

◆ BT_MESH_MIC_LONG

#define BT_MESH_MIC_LONG   8

#include <zephyr/bluetooth/mesh/msg.h>

Length of a long Mesh MIC.

◆ BT_MESH_MIC_SHORT

#define BT_MESH_MIC_SHORT   4

#include <zephyr/bluetooth/mesh/msg.h>

Length of a short Mesh MIC.

◆ BT_MESH_MODEL_BUF_DEFINE

#define BT_MESH_MODEL_BUF_DEFINE ( _buf,
_op,
_payload_len )

#include <zephyr/bluetooth/mesh/msg.h>

Value:
NET_BUF_SIMPLE_DEFINE(_buf, BT_MESH_MODEL_BUF_LEN(_op, (_payload_len)))
#define BT_MESH_MODEL_BUF_LEN(_op, _payload_len)
Helper for model message buffer length.
Definition msg.h:50
#define NET_BUF_SIMPLE_DEFINE(_name, _size)
Define a net_buf_simple stack variable.
Definition net_buf.h:48

Define a Mesh model message buffer using NET_BUF_SIMPLE_DEFINE.

Parameters
_bufBuffer name.
_opOpcode of the message.
_payload_lenLength of the model message payload.

◆ BT_MESH_MODEL_BUF_LEN

#define BT_MESH_MODEL_BUF_LEN ( _op,
_payload_len )

#include <zephyr/bluetooth/mesh/msg.h>

Value:
(BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_SHORT)
#define BT_MESH_MIC_SHORT
Length of a short Mesh MIC.
Definition msg.h:30
#define BT_MESH_MODEL_OP_LEN(_op)
Helper to determine the length of an opcode.
Definition msg.h:39

Helper for model message buffer length.

Returns the length of a Mesh model message buffer, including the opcode length and a short MIC.

Parameters
_opOpcode of the message.
_payload_lenLength of the model payload.

◆ BT_MESH_MODEL_BUF_LEN_LONG_MIC

#define BT_MESH_MODEL_BUF_LEN_LONG_MIC ( _op,
_payload_len )

#include <zephyr/bluetooth/mesh/msg.h>

Value:
(BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_LONG)
#define BT_MESH_MIC_LONG
Length of a long Mesh MIC.
Definition msg.h:32

Helper for model message buffer length.

Returns the length of a Mesh model message buffer, including the opcode length and a long MIC.

Parameters
_opOpcode of the message.
_payload_lenLength of the model payload.

◆ BT_MESH_MODEL_OP_LEN

#define BT_MESH_MODEL_OP_LEN ( _op)

#include <zephyr/bluetooth/mesh/msg.h>

Value:
((_op) <= 0xff ? 1 : (_op) <= 0xffff ? 2 : 3)

Helper to determine the length of an opcode.

Parameters
_opOpcode.

◆ BT_MESH_MSG_CTX_INIT

#define BT_MESH_MSG_CTX_INIT ( net_key_idx,
app_key_idx,
dst,
ttl )

#include <zephyr/bluetooth/mesh/msg.h>

Value:
{ \
.net_idx = (net_key_idx), \
.app_idx = (app_key_idx), \
.addr = (dst), \
.send_ttl = (ttl), \
}

Helper for bt_mesh_msg_ctx structure initialization.

Note
If dst is a Virtual Address, Label UUID shall be initialized separately.
Parameters
net_key_idxNetKey Index of the subnet to send the message on. Only used if app_key_idx points to devkey.
app_key_idxAppKey Index to encrypt the message with.
dstRemote addr.
ttlTime To Live.

◆ BT_MESH_MSG_CTX_INIT_APP

#define BT_MESH_MSG_CTX_INIT_APP ( app_key_idx,
dst )

#include <zephyr/bluetooth/mesh/msg.h>

Value:
#define BT_MESH_TTL_DEFAULT
Special TTL value to request using configured default TTL.
Definition access.h:960
#define BT_MESH_MSG_CTX_INIT(net_key_idx, app_key_idx, dst, ttl)
Helper for bt_mesh_msg_ctx structure initialization.
Definition msg.h:119

Helper for bt_mesh_msg_ctx structure initialization secured with Application Key.

Parameters
app_key_idxAppKey Index to encrypt the message with.
dstRemote addr.

◆ BT_MESH_MSG_CTX_INIT_DEV

#define BT_MESH_MSG_CTX_INIT_DEV ( net_key_idx,
dst )

#include <zephyr/bluetooth/mesh/msg.h>

Value:
#define BT_MESH_KEY_DEV_REMOTE
Remote device key.
Definition access.h:71

Helper for bt_mesh_msg_ctx structure initialization secured with Device Key of a remote device.

Parameters
net_key_idxNetKey Index of the subnet to send the message on.
dstRemote addr.

◆ BT_MESH_MSG_CTX_INIT_PUB

#define BT_MESH_MSG_CTX_INIT_PUB ( pub)

#include <zephyr/bluetooth/mesh/msg.h>

Value:
{ \
.app_idx = (pub)->key, \
.addr = (pub)->addr, \
.send_ttl = (pub)->ttl, \
.uuid = (pub)->uuid, \
}

Helper for bt_mesh_msg_ctx structure initialization using Model Publication context.

Parameters
pubPointer to a model publication context.

Function Documentation

◆ bt_mesh_model_msg_init()

void bt_mesh_model_msg_init ( struct net_buf_simple * msg,
uint32_t opcode )

#include <zephyr/bluetooth/mesh/msg.h>

Initialize a model message.

Clears the message buffer contents, and encodes the given opcode. The message buffer will be ready for filling in payload data.

Parameters
msgMessage buffer.
opcodeOpcode to encode.

◆ bt_mesh_msg_ack_ctx_busy()

static bool bt_mesh_msg_ack_ctx_busy ( struct bt_mesh_msg_ack_ctx * ack)
inlinestatic

#include <zephyr/bluetooth/mesh/msg.h>

Check if the acknowledged message context is initialized with an opcode.

Parameters
ackAcknowledged message context.
Returns
true if the acknowledged message context is initialized with an opcode, false otherwise.

◆ bt_mesh_msg_ack_ctx_clear()

void bt_mesh_msg_ack_ctx_clear ( struct bt_mesh_msg_ack_ctx * ack)

#include <zephyr/bluetooth/mesh/msg.h>

Clear parameters of an acknowledged message context.

This function clears the opcode, remote address and user data set by bt_mesh_msg_ack_ctx_prepare.

Parameters
ackAcknowledged message context to be cleared.

◆ bt_mesh_msg_ack_ctx_init()

static void bt_mesh_msg_ack_ctx_init ( struct bt_mesh_msg_ack_ctx * ack)
inlinestatic

#include <zephyr/bluetooth/mesh/msg.h>

Initialize an acknowledged message context.

Initializes semaphore used for synchronization between bt_mesh_msg_ack_ctx_wait and bt_mesh_msg_ack_ctx_rx calls. Call this function before using bt_mesh_msg_ack_ctx.

Parameters
ackAcknowledged message context to initialize.

◆ bt_mesh_msg_ack_ctx_match()

bool bt_mesh_msg_ack_ctx_match ( const struct bt_mesh_msg_ack_ctx * ack,
uint32_t op,
uint16_t addr,
void ** user_data )

#include <zephyr/bluetooth/mesh/msg.h>

Check if an opcode and address of a message matches the expected one.

Parameters
ackAcknowledged message context to be checked.
opOpCode of the incoming message.
addrSource address of the incoming message.
user_dataIf not NULL, returns a user data stored in the acknowledged message context by bt_mesh_msg_ack_ctx_prepare.
Returns
true if the incoming message matches the expected one, false otherwise.

◆ bt_mesh_msg_ack_ctx_prepare()

int bt_mesh_msg_ack_ctx_prepare ( struct bt_mesh_msg_ack_ctx * ack,
uint32_t op,
uint16_t dst,
void * user_data )

#include <zephyr/bluetooth/mesh/msg.h>

Prepare an acknowledged message context for the incoming message to wait.

This function sets the opcode, remote address of the incoming message and stores the user data. Use this function before calling bt_mesh_msg_ack_ctx_wait.

Parameters
ackAcknowledged message context to prepare.
opThe message OpCode.
dstDestination address of the message.
user_dataUser data for the acknowledged message context.
Returns
0 on success, or (negative) error code on failure.

◆ bt_mesh_msg_ack_ctx_reset()

static void bt_mesh_msg_ack_ctx_reset ( struct bt_mesh_msg_ack_ctx * ack)
inlinestatic

#include <zephyr/bluetooth/mesh/msg.h>

Reset the synchronization semaphore in an acknowledged message context.

This function aborts call to bt_mesh_msg_ack_ctx_wait.

Parameters
ackAcknowledged message context to be reset.

◆ bt_mesh_msg_ack_ctx_rx()

static void bt_mesh_msg_ack_ctx_rx ( struct bt_mesh_msg_ack_ctx * ack)
inlinestatic

#include <zephyr/bluetooth/mesh/msg.h>

Mark a message as acknowledged.

This function unblocks call to bt_mesh_msg_ack_ctx_wait.

Parameters
ackContext of a message to be acknowledged.

◆ bt_mesh_msg_ack_ctx_wait()

int bt_mesh_msg_ack_ctx_wait ( struct bt_mesh_msg_ack_ctx * ack,
k_timeout_t timeout )

#include <zephyr/bluetooth/mesh/msg.h>

Wait for a message acknowledge.

This function blocks execution until bt_mesh_msg_ack_ctx_rx is called or by timeout.

Parameters
ackAcknowledged message context of the message to wait for.
timeoutWait timeout.
Returns
0 on success, or (negative) error code on failure.