NimBLE-Arduino 2.1.2
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
11#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_MSG_H_
12#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_MSG_H_
13
21#ifdef __cplusplus
22extern "C" {
23#endif
24
26#define BT_MESH_MIC_SHORT 4
28#define BT_MESH_MIC_LONG 8
29
36#define BT_MESH_MODEL_OP_LEN(_op) ((_op) <= 0xff ? 1 : (_op) <= 0xffff ? 2 : 3)
37
38
49#define BT_MESH_MODEL_BUF_LEN(_op, _payload_len) \
50 (BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_SHORT)
51
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
66
75#define BT_MESH_MODEL_BUF(_op, _payload_len) \
76 NET_BUF_SIMPLE(BT_MESH_MODEL_BUF_LEN(_op, (_payload_len)))
77
78
82 uint16_t net_idx;
83
85 uint16_t app_idx;
86
88 uint16_t addr;
89
91 uint16_t recv_dst;
92
94 int8_t recv_rssi;
95
97 uint8_t recv_ttl;
98
101
103 uint8_t send_ttl;
104};
105
114void bt_mesh_model_msg_init(struct os_mbuf *msg, uint32_t opcode);
115
120 struct k_sem sem;
121 uint32_t op;
122 uint16_t dst;
123 void *user_data;
124};
125
133static inline void bt_mesh_msg_ack_ctx_init(struct bt_mesh_msg_ack_ctx *ack)
134{
135 k_sem_init(&ack->sem, 0, 1);
136}
137
144static inline void bt_mesh_msg_ack_ctx_reset(struct bt_mesh_msg_ack_ctx *ack)
145{
146 k_sem_reset(&ack->sem);
147}
148
157
171 uint32_t op, uint16_t dst, void *user_data);
179static inline bool bt_mesh_msg_ack_ctx_busy(struct bt_mesh_msg_ack_ctx *ack)
180{
181 return (ack->op != 0);
182}
183
193int bt_mesh_msg_ack_ctx_wait(struct bt_mesh_msg_ack_ctx *ack, int32_t timeout);
194
201static inline void bt_mesh_msg_ack_ctx_rx(struct bt_mesh_msg_ack_ctx *ack)
202{
203 k_sem_give(&ack->sem);
204}
205
217 uint32_t op, uint16_t addr, void **user_data);
218
219#ifdef __cplusplus
220}
221#endif
225#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.
int bt_mesh_msg_ack_ctx_wait(struct bt_mesh_msg_ack_ctx *ack, int32_t timeout)
Wait for a message acknowledge.
void bt_mesh_msg_ack_ctx_clear(struct bt_mesh_msg_ack_ctx *ack)
Clear parameters of an acknowledged message context.
void bt_mesh_model_msg_init(struct os_mbuf *msg, uint32_t opcode)
Initialize a model message.
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.
Definition msg.h:119
uint32_t op
Definition msg.h:121
void * user_data
Definition msg.h:123
struct k_sem sem
Definition msg.h:120
uint16_t dst
Definition msg.h:122
Definition msg.h:80
uint16_t net_idx
Definition msg.h:82
int8_t recv_rssi
Definition msg.h:94
bool send_rel
Definition msg.h:100
uint16_t addr
Definition msg.h:88
uint8_t send_ttl
Definition msg.h:103
uint16_t app_idx
Definition msg.h:85
uint16_t recv_dst
Definition msg.h:91
uint8_t recv_ttl
Definition msg.h:97
Definition os_mbuf.h:86