in nimble/host/mesh/src/cfg_srv.c [2041:2123]
static int mod_app_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct os_mbuf *buf)
{
struct os_mbuf *msg = NET_BUF_SIMPLE(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;
uint8_t *mod_id, status;
uint16_t elem_addr;
bool vnd;
int err = 0;
if ((buf->om_len != 4U) && (buf->om_len != 6U)) {
BT_ERR("The message size for the application opcode is incorrect.");
return -EMSGSIZE;
}
elem_addr = net_buf_simple_pull_le16(buf);
if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) {
BT_WARN("Prohibited element address");
err = -EINVAL;
goto done;
}
mod_id = buf->om_data;
BT_DBG("elem_addr 0x%04x", elem_addr);
elem = bt_mesh_elem_find(elem_addr);
if (!elem) {
mod = NULL;
vnd = (buf->om_len == 4);
status = STATUS_INVALID_ADDRESS;
goto send_list;
}
mod = get_model(elem, buf, &vnd);
if (!mod) {
status = STATUS_INVALID_MODEL;
goto send_list;
}
status = STATUS_SUCCESS;
send_list:
if (vnd) {
bt_mesh_model_msg_init(msg, OP_VND_MOD_APP_LIST);
} else {
bt_mesh_model_msg_init(msg, OP_SIG_MOD_APP_LIST);
}
net_buf_simple_add_u8(msg, status);
net_buf_simple_add_le16(msg, elem_addr);
if (vnd) {
net_buf_simple_add_mem(msg, mod_id, 4);
} else {
net_buf_simple_add_mem(msg, mod_id, 2);
}
if (mod) {
int i;
for (i = 0; i < ARRAY_SIZE(mod->keys); i++) {
if (mod->keys[i] != BT_MESH_KEY_UNUSED) {
net_buf_simple_add_le16(msg, mod->keys[i]);
}
}
}
if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) {
BT_ERR("Unable to send Model Application List message");
}
done:
os_mbuf_free_chain(msg);
return err;
}