I am working on a BLE mesh project, and I have created my own BLE mesh publish and send functions,
int vendor_model_send(uint16_t addr, uint8_t * p_data, uint16_t length) { int err = 0; // create a dummy context struct bt_mesh_msg_ctx context = { .addr = addr, .app_idx = 0, .net_idx = 0, .send_rel = false, }; struct net_buf_simple *msg = NET_BUF_SIMPLE(VND_MSG_BUFFER_SIZE); bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_3(0x04, CID_ZEPHYR)); uint16_t old_size = msg->len; net_buf_simple_add(msg, length); (void)memcpy(msg->data + old_size, p_data, length); err = bt_mesh_model_send(&vnd_models[0], &context, msg, NULL, NULL); if (err != 0) { printk("\rUnable to send VENDOR Status response\n"); } else { // do nothing, sending was successful } return err; }
int vendor_model_publish(enum vendor_model_opcodes opcode, uint8_t *p_data, uint16_t length) { int err = 0; bt_mesh_model_msg_init(vnd_models[0].pub->msg, BT_MESH_MODEL_OP_3((uint32_t)opcode, CID_ZEPHYR)); for (uint16_t packet_num = 0; packet_num < length; packet_num++) { uint8_t packet_data = 0; (void)memcpy(&packet_data, &p_data[packet_num], sizeof(packet_data)); net_buf_simple_add_u8(vnd_models[0].pub->msg, packet_data); } err = bt_mesh_model_publish(&vnd_models[0]); if (err != 0) { printk("bt_mesh_model_publish: err: %d\n", err); } else { // do nothing, publish was successful } return err; }
My concern is, I am creating buffers using the bt_mesh_model_msg_init()
and NET_BUF_SIMPLE()
functions, which I suspect might perform dynamic allocation. And I'm not freeing these variables. Can anyone kindly confirm if that is not the case? Or tell me how I can find that out for myself?
Any help would be much appreciated.
Best regards,