Bluetooth: Mesh: Model message macros
Creates macros for determining model message lengths based on opcode, payload length and MIC size. Also adds macro wrapping NET_BUF_SIMPLE_DEFINE to serve the most common use case. Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
parent
a3bc87504c
commit
5aee3ee995
6 changed files with 127 additions and 91 deletions
|
@ -435,7 +435,7 @@ static void app_key_add(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 4 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_STATUS, 4);
|
||||
u16_t key_net_idx, key_app_idx;
|
||||
u8_t status;
|
||||
|
||||
|
@ -460,7 +460,7 @@ static void app_key_update(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 4 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_STATUS, 4);
|
||||
u16_t key_net_idx, key_app_idx;
|
||||
u8_t status;
|
||||
|
||||
|
@ -514,7 +514,7 @@ static void app_key_del(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 4 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_STATUS, 4);
|
||||
u16_t key_net_idx, key_app_idx;
|
||||
struct bt_mesh_app_key *key;
|
||||
u8_t status;
|
||||
|
@ -564,8 +564,8 @@ static void app_key_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 3 + 4 +
|
||||
IDX_LEN(CONFIG_BT_MESH_APP_KEY_COUNT));
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_LIST,
|
||||
3 + IDX_LEN(CONFIG_BT_MESH_APP_KEY_COUNT));
|
||||
u16_t get_idx, i, prev;
|
||||
u8_t status;
|
||||
|
||||
|
@ -623,8 +623,7 @@ static void beacon_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_BEACON_STATUS, 1);
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
|
@ -642,8 +641,7 @@ static void beacon_set(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_BEACON_STATUS, 1);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
|
@ -683,8 +681,7 @@ static void default_ttl_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_DEFAULT_TTL_STATUS, 1);
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
|
@ -702,8 +699,7 @@ static void default_ttl_set(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_DEFAULT_TTL_STATUS, 1);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
|
@ -736,8 +732,7 @@ static void default_ttl_set(struct bt_mesh_model *model,
|
|||
static void send_gatt_proxy_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_GATT_PROXY_STATUS, 1);
|
||||
|
||||
bt_mesh_model_msg_init(&msg, OP_GATT_PROXY_STATUS);
|
||||
net_buf_simple_add_u8(&msg, bt_mesh_gatt_proxy_get());
|
||||
|
@ -831,8 +826,7 @@ static void net_transmit_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_TRANSMIT_STATUS, 1);
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
|
@ -850,8 +844,7 @@ static void net_transmit_set(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_TRANSMIT_STATUS, 1);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
|
@ -884,8 +877,7 @@ static void relay_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 2 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_STATUS, 2);
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
|
@ -904,8 +896,7 @@ static void relay_set(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 2 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_STATUS, 2);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
|
@ -958,8 +949,7 @@ static void send_mod_pub_status(struct bt_mesh_model *cfg_mod,
|
|||
bool vnd, struct bt_mesh_model *mod,
|
||||
u8_t status, u8_t *mod_id)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 14 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_STATUS, 14);
|
||||
|
||||
bt_mesh_model_msg_init(&msg, OP_MOD_PUB_STATUS);
|
||||
|
||||
|
@ -1324,8 +1314,7 @@ static void send_mod_sub_status(struct bt_mesh_model *model,
|
|||
u16_t elem_addr, u16_t sub_addr, u8_t *mod_id,
|
||||
bool vnd)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 9 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_STATUS, 9);
|
||||
|
||||
BT_DBG("status 0x%02x elem_addr 0x%04x sub_addr 0x%04x", status,
|
||||
elem_addr, sub_addr);
|
||||
|
@ -1614,8 +1603,8 @@ static void mod_sub_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 5 + 4 +
|
||||
CONFIG_BT_MESH_MODEL_GROUP_COUNT * 2);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_LIST,
|
||||
5 + CONFIG_BT_MESH_MODEL_GROUP_COUNT * 2);
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t addr, id;
|
||||
|
@ -1670,8 +1659,8 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 7 + 4 +
|
||||
CONFIG_BT_MESH_MODEL_GROUP_COUNT * 2);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_LIST_VND,
|
||||
7 + CONFIG_BT_MESH_MODEL_GROUP_COUNT * 2);
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t company, addr, id;
|
||||
|
@ -2063,8 +2052,7 @@ static void send_net_key_status(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t idx, u8_t status)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 3 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_STATUS, 3);
|
||||
|
||||
bt_mesh_model_msg_init(&msg, OP_NET_KEY_STATUS);
|
||||
|
||||
|
@ -2276,8 +2264,8 @@ static void net_key_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg,
|
||||
2 + 4 + IDX_LEN(CONFIG_BT_MESH_SUBNET_COUNT));
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_LIST,
|
||||
IDX_LEN(CONFIG_BT_MESH_SUBNET_COUNT));
|
||||
u16_t prev, i;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, OP_NET_KEY_LIST);
|
||||
|
@ -2312,8 +2300,7 @@ static void node_identity_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 4 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_STATUS, 4);
|
||||
struct bt_mesh_subnet *sub;
|
||||
u8_t node_id;
|
||||
u16_t idx;
|
||||
|
@ -2351,8 +2338,7 @@ static void node_identity_set(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 4 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_STATUS, 4);
|
||||
struct bt_mesh_subnet *sub;
|
||||
u8_t node_id;
|
||||
u16_t idx;
|
||||
|
@ -2428,7 +2414,7 @@ static void mod_app_bind(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 9 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_STATUS, 9);
|
||||
u16_t elem_addr, key_app_idx;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
|
@ -2485,7 +2471,7 @@ static void mod_app_unbind(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 9 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_STATUS, 9);
|
||||
u16_t elem_addr, key_app_idx;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
|
@ -2537,7 +2523,11 @@ static void mod_app_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 9 + KEY_LIST_LEN + 4);
|
||||
NET_BUF_SIMPLE_DEFINE(msg,
|
||||
MAX(BT_MESH_MODEL_BUF_LEN(OP_VND_MOD_APP_LIST,
|
||||
9 + KEY_LIST_LEN),
|
||||
BT_MESH_MODEL_BUF_LEN(OP_SIG_MOD_APP_LIST,
|
||||
9 + KEY_LIST_LEN)));
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id, status;
|
||||
|
@ -2605,8 +2595,7 @@ static void node_reset(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 0 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_RESET_STATUS, 0);
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
|
@ -2628,8 +2617,7 @@ static void node_reset(struct bt_mesh_model *model,
|
|||
static void send_friend_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_FRIEND_STATUS, 1);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, OP_FRIEND_STATUS);
|
||||
|
@ -2701,8 +2689,7 @@ static void lpn_timeout_get(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 5 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_STATUS, 5);
|
||||
struct bt_mesh_friend *frnd;
|
||||
u16_t lpn_addr;
|
||||
s32_t timeout;
|
||||
|
@ -2747,8 +2734,7 @@ static void send_krp_status(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t idx, u8_t phase, u8_t status)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 4 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_STATUS, 4);
|
||||
|
||||
bt_mesh_model_msg_init(&msg, OP_KRP_STATUS);
|
||||
|
||||
|
@ -2885,8 +2871,7 @@ static void hb_pub_send_status(struct bt_mesh_model *model,
|
|||
struct bt_mesh_msg_ctx *ctx, u8_t status,
|
||||
struct hb_pub_param *orig_msg)
|
||||
{
|
||||
/* Needed size: opcode (1 byte) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 1 + 10 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_STATUS, 10);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
|
||||
BT_DBG("src 0x%04x status 0x%02x", ctx->addr, status);
|
||||
|
@ -3009,8 +2994,7 @@ failed:
|
|||
static void hb_sub_send_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, u8_t status)
|
||||
{
|
||||
/* Needed size: opcode (2 bytes) + msg + MIC */
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 2 + 9 + 4);
|
||||
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_STATUS, 9);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
u16_t period;
|
||||
s64_t uptime;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue