Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
msg.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2021 Nordic Semiconductor ASA
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_MSG_H_
11#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_MSG_H_
12
20#include <zephyr/kernel.h>
21#include <zephyr/net/buf.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27struct bt_mesh_model;
28
30#define BT_MESH_MIC_SHORT 4
32#define BT_MESH_MIC_LONG 8
33
39#define BT_MESH_MODEL_OP_LEN(_op) ((_op) <= 0xff ? 1 : (_op) <= 0xffff ? 2 : 3)
40
50#define BT_MESH_MODEL_BUF_LEN(_op, _payload_len) \
51 (BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_SHORT)
52
62#define BT_MESH_MODEL_BUF_LEN_LONG_MIC(_op, _payload_len) \
63 (BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_LONG)
64
72#define BT_MESH_MODEL_BUF_DEFINE(_buf, _op, _payload_len) \
73 NET_BUF_SIMPLE_DEFINE(_buf, BT_MESH_MODEL_BUF_LEN(_op, (_payload_len)))
74
79
82
85
88
90 const uint8_t *uuid;
91
94
97
100
103
106};
107
119#define BT_MESH_MSG_CTX_INIT(net_key_idx, app_key_idx, dst, ttl) \
120 { \
121 .net_idx = (net_key_idx), \
122 .app_idx = (app_key_idx), \
123 .addr = (dst), \
124 .send_ttl = (ttl), \
125 }
126
133#define BT_MESH_MSG_CTX_INIT_APP(app_key_idx, dst) \
134 BT_MESH_MSG_CTX_INIT(0, app_key_idx, dst, BT_MESH_TTL_DEFAULT)
135
143#define BT_MESH_MSG_CTX_INIT_DEV(net_key_idx, dst) \
144 BT_MESH_MSG_CTX_INIT(net_key_idx, BT_MESH_KEY_DEV_REMOTE, dst, BT_MESH_TTL_DEFAULT)
145
151#define BT_MESH_MSG_CTX_INIT_PUB(pub) \
152 { \
153 .app_idx = (pub)->key, \
154 .addr = (pub)->addr, \
155 .send_ttl = (pub)->ttl, \
156 .uuid = (pub)->uuid, \
157 }
158
168
173 struct k_sem sem;
176 void *user_data;
177};
178
186static inline void bt_mesh_msg_ack_ctx_init(struct bt_mesh_msg_ack_ctx *ack)
187{
188 k_sem_init(&ack->sem, 0, 1);
189}
190
197static inline void bt_mesh_msg_ack_ctx_reset(struct bt_mesh_msg_ack_ctx *ack)
198{
199 k_sem_reset(&ack->sem);
200}
201
210
224 uint32_t op, uint16_t dst, void *user_data);
225
233static inline bool bt_mesh_msg_ack_ctx_busy(struct bt_mesh_msg_ack_ctx *ack)
234{
235 return (ack->op != 0);
236}
237
248
255static inline void bt_mesh_msg_ack_ctx_rx(struct bt_mesh_msg_ack_ctx *ack)
256{
257 k_sem_give(&ack->sem);
258}
259
271 uint32_t op, uint16_t addr, void **user_data);
272
273#ifdef __cplusplus
274}
275#endif
276
281#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_MSG_H_ */
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 void bt_mesh_msg_ack_ctx_rx(struct bt_mesh_msg_ack_ctx *ack)
Mark a message as acknowledged.
Definition: msg.h:255
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_wait(struct bt_mesh_msg_ack_ctx *ack, k_timeout_t timeout)
Wait for a message acknowledge.
static void bt_mesh_msg_ack_ctx_reset(struct bt_mesh_msg_ack_ctx *ack)
Reset the synchronization semaphore in an acknowledged message context.
Definition: msg.h:197
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.
Definition: msg.h:233
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.
Definition: msg.h:186
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.
void k_sem_reset(struct k_sem *sem)
Resets a semaphore's count to zero.
void k_sem_give(struct k_sem *sem)
Give a semaphore.
int k_sem_init(struct k_sem *sem, unsigned int initial_count, unsigned int limit)
Initialize a semaphore.
Public kernel APIs.
Buffer management.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
__INT8_TYPE__ int8_t
Definition: stdint.h:72
Abstraction that describes a Mesh Model instance.
Definition: access.h:887
Acknowledged message context for tracking the status of model messages pending a response.
Definition: msg.h:172
uint32_t op
Opcode we're waiting for.
Definition: msg.h:174
void * user_data
User specific parameter.
Definition: msg.h:176
struct k_sem sem
Sync semaphore.
Definition: msg.h:173
uint16_t dst
Address of the node that should respond.
Definition: msg.h:175
Message sending context.
Definition: msg.h:76
uint16_t net_idx
NetKey Index of the subnet to send the message on.
Definition: msg.h:78
int8_t recv_rssi
RSSI of received packet.
Definition: msg.h:93
bool send_rel
Force sending reliably by using segment acknowledgment.
Definition: msg.h:99
uint16_t addr
Remote address.
Definition: msg.h:84
uint8_t send_ttl
TTL, or BT_MESH_TTL_DEFAULT for default TTL.
Definition: msg.h:105
const uint8_t * uuid
Label UUID if Remote address is Virtual address, or NULL otherwise.
Definition: msg.h:90
uint16_t app_idx
AppKey Index to encrypt the message with.
Definition: msg.h:81
uint16_t recv_dst
Destination address of a received message.
Definition: msg.h:87
bool rnd_delay
Send message with a random delay according to the Access layer transmitting rules.
Definition: msg.h:102
uint8_t recv_ttl
Received TTL value.
Definition: msg.h:96
Kernel timeout type.
Definition: sys_clock.h:65
Simple network buffer representation.
Definition: buf.h:87