Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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.h>
21#include <net/buf.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
28#define BT_MESH_MIC_SHORT 4
30#define BT_MESH_MIC_LONG 8
31
38#define BT_MESH_MODEL_OP_LEN(_op) ((_op) <= 0xff ? 1 : (_op) <= 0xffff ? 2 : 3)
39
50#define BT_MESH_MODEL_BUF_LEN(_op, _payload_len) \
51 (BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_SHORT)
52
63#define BT_MESH_MODEL_BUF_LEN_LONG_MIC(_op, _payload_len) \
64 (BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_LONG)
65
74#define BT_MESH_MODEL_BUF_DEFINE(_buf, _op, _payload_len) \
75 NET_BUF_SIMPLE_DEFINE(_buf, BT_MESH_MODEL_BUF_LEN(_op, (_payload_len)))
76
81
84
87
90
93
96
99
102};
103
113
118 struct k_sem sem;
121 void *user_data;
122};
123
131static inline void bt_mesh_msg_ack_ctx_init(struct bt_mesh_msg_ack_ctx *ack)
132{
133 k_sem_init(&ack->sem, 0, 1);
134}
135
142static inline void bt_mesh_msg_ack_ctx_reset(struct bt_mesh_msg_ack_ctx *ack)
143{
144 k_sem_reset(&ack->sem);
145}
146
155
169 uint32_t op, uint16_t dst, void *user_data);
170
178static inline bool bt_mesh_msg_ack_ctx_busy(struct bt_mesh_msg_ack_ctx *ack)
179{
180 return (ack->op != 0);
181}
182
193
200static inline void bt_mesh_msg_ack_ctx_rx(struct bt_mesh_msg_ack_ctx *ack)
201{
202 k_sem_give(&ack->sem);
203}
204
216 uint32_t op, uint16_t addr, void **user_data);
217
218#ifdef __cplusplus
219}
220#endif
221
226#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_MSG_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
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:200
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:142
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:178
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:131
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.
Buffer management.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
__INT8_TYPE__ int8_t
Definition: stdint.h:42
Definition: msg.h:117
uint32_t op
Definition: msg.h:119
void * user_data
Definition: msg.h:121
struct k_sem sem
Definition: msg.h:118
uint16_t dst
Definition: msg.h:120
Definition: msg.h:78
uint16_t net_idx
Definition: msg.h:80
int8_t recv_rssi
Definition: msg.h:92
bool send_rel
Definition: msg.h:98
uint16_t addr
Definition: msg.h:86
uint8_t send_ttl
Definition: msg.h:101
uint16_t app_idx
Definition: msg.h:83
uint16_t recv_dst
Definition: msg.h:89
uint8_t recv_ttl
Definition: msg.h:95
Kernel timeout type.
Definition: sys_clock.h:65
Simple network buffer representation.
Definition: buf.h:87
static const intptr_t user_data[5]
Definition: main.c:590