From 880d52460ecbc7c20ff137419d6f6717a6d9c433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Thu, 26 Jul 2018 13:50:40 +0200 Subject: [PATCH] mesh: glue: Add utility net_buf functions for later use These functions will be used in an app that will be added in the future. --- nimble/host/mesh/include/mesh/glue.h | 2 ++ nimble/host/mesh/src/glue.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/nimble/host/mesh/include/mesh/glue.h b/nimble/host/mesh/include/mesh/glue.h index 7237a82af..b458ffebf 100644 --- a/nimble/host/mesh/include/mesh/glue.h +++ b/nimble/host/mesh/include/mesh/glue.h @@ -215,11 +215,13 @@ void net_buf_unref(struct os_mbuf *om); uint16_t net_buf_simple_pull_le16(struct os_mbuf *om); uint16_t net_buf_simple_pull_be16(struct os_mbuf *om); uint32_t net_buf_simple_pull_be32(struct os_mbuf *om); +uint32_t net_buf_simple_pull_le32(struct os_mbuf *om); uint8_t net_buf_simple_pull_u8(struct os_mbuf *om); void net_buf_simple_add_le16(struct os_mbuf *om, uint16_t val); void net_buf_simple_add_be16(struct os_mbuf *om, uint16_t val); void net_buf_simple_add_u8(struct os_mbuf *om, uint8_t val); void net_buf_simple_add_be32(struct os_mbuf *om, uint32_t val); +void net_buf_simple_add_le32(struct os_mbuf *om, uint32_t val); void net_buf_add_zeros(struct os_mbuf *om, uint8_t len); void net_buf_simple_push_le16(struct os_mbuf *om, uint16_t val); void net_buf_simple_push_be16(struct os_mbuf *om, uint16_t val); diff --git a/nimble/host/mesh/src/glue.c b/nimble/host/mesh/src/glue.c index 5933bb5ca..01dbdf431 100644 --- a/nimble/host/mesh/src/glue.c +++ b/nimble/host/mesh/src/glue.c @@ -183,6 +183,20 @@ net_buf_simple_pull_be32(struct os_mbuf *om) return val; } +uint32_t +net_buf_simple_pull_le32(struct os_mbuf *om) +{ + uint32_t val; + struct os_mbuf *old = om; + + om = os_mbuf_pullup(om, sizeof(val)); + assert(om == old); + val = get_le32(om->om_data); + os_mbuf_adj(om, sizeof(val)); + + return val; +} + uint8_t net_buf_simple_pull_u8(struct os_mbuf *om) { @@ -221,6 +235,14 @@ net_buf_simple_add_be32(struct os_mbuf *om, uint32_t val) ASSERT_NOT_CHAIN(om); } +void +net_buf_simple_add_le32(struct os_mbuf *om, uint32_t val) +{ + val = htole32(val); + os_mbuf_append(om, &val, sizeof(val)); + ASSERT_NOT_CHAIN(om); +} + void net_buf_simple_add_u8(struct os_mbuf *om, uint8_t val) {