From c2589b0b57c48789851959155c6afd6afe5efd38 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 15 May 2020 10:33:24 +0800 Subject: [PATCH] ble_mesh: Add net_buf_simple_init_with_data [Zephyr] --- .../bt/esp_ble_mesh/mesh_common/include/mesh_buf.h | 12 ++++++++++++ components/bt/esp_ble_mesh/mesh_common/mesh_buf.c | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_buf.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_buf.h index 32c12817e..4a47b1c0c 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_buf.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_buf.h @@ -152,6 +152,18 @@ static inline void net_buf_simple_init(struct net_buf_simple *buf, buf->len = 0; } +/** + * @brief Initialize a net_buf_simple object with data. + * + * Initialized buffer object with external data. + * + * @param buf Buffer to initialize. + * @param data External data pointer + * @param size Amount of data the pointed data buffer if able to fit. + */ +void net_buf_simple_init_with_data(struct net_buf_simple *buf, + void *data, size_t size); + /** * @brief Reset buffer * diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c b/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c index 791948221..10a9e6566 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c @@ -383,6 +383,15 @@ void net_buf_reset(struct net_buf *buf) net_buf_simple_reset(&buf->b); } +void net_buf_simple_init_with_data(struct net_buf_simple *buf, + void *data, size_t size) +{ + buf->__buf = data; + buf->data = data; + buf->size = size; + buf->len = size; +} + void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve) { NET_BUF_ASSERT(buf);