Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Network Buffer Library

Network buffer library. More...

Data Structures

struct  net_buf_simple
 Simple network buffer representation. More...
 
struct  net_buf_simple_state
 Parsing state of a buffer. More...
 
struct  net_buf
 Network buffer representation. More...
 
struct  net_buf_data_cb
 
struct  net_buf_data_alloc
 
struct  net_buf_pool
 Network buffer pool representation. More...
 
struct  net_buf_pool_fixed
 

Macros

#define NET_BUF_SIMPLE_DEFINE(_name, _size)
 Define a net_buf_simple stack variable.
 
#define NET_BUF_SIMPLE_DEFINE_STATIC(_name, _size)
 Define a static net_buf_simple variable.
 
#define NET_BUF_SIMPLE(_size)
 Define a net_buf_simple stack variable and get a pointer to it.
 
#define NET_BUF_EXTERNAL_DATA   BIT(0)
 Flag indicating that the buffer's associated data pointer, points to externally allocated memory.
 
#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy)
 Define a new pool for buffers using the heap for the data.
 
#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy)
 Define a new pool for buffers based on fixed-size data.
 
#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy)
 Define a new pool for buffers with variable size payloads.
 
#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy)    NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)
 Define a new pool for buffers.
 

Typedefs

typedef struct net_buf *(* net_buf_allocator_cb) (k_timeout_t timeout, void *user_data)
 Network buffer allocator callback.
 

Functions

static void net_buf_simple_init (struct net_buf_simple *buf, size_t reserve_head)
 Initialize a net_buf_simple object.
 
void net_buf_simple_init_with_data (struct net_buf_simple *buf, void *data, size_t size)
 Initialize a net_buf_simple object with data.
 
static void net_buf_simple_reset (struct net_buf_simple *buf)
 Reset buffer.
 
void net_buf_simple_clone (const struct net_buf_simple *original, struct net_buf_simple *clone)
 Clone buffer state, using the same data buffer.
 
void * net_buf_simple_add (struct net_buf_simple *buf, size_t len)
 Prepare data to be added at the end of the buffer.
 
void * net_buf_simple_add_mem (struct net_buf_simple *buf, const void *mem, size_t len)
 Copy given number of bytes from memory to the end of the buffer.
 
uint8_tnet_buf_simple_add_u8 (struct net_buf_simple *buf, uint8_t val)
 Add (8-bit) byte at the end of the buffer.
 
void net_buf_simple_add_le16 (struct net_buf_simple *buf, uint16_t val)
 Add 16-bit value at the end of the buffer.
 
void net_buf_simple_add_be16 (struct net_buf_simple *buf, uint16_t val)
 Add 16-bit value at the end of the buffer.
 
void net_buf_simple_add_le24 (struct net_buf_simple *buf, uint32_t val)
 Add 24-bit value at the end of the buffer.
 
void net_buf_simple_add_be24 (struct net_buf_simple *buf, uint32_t val)
 Add 24-bit value at the end of the buffer.
 
void net_buf_simple_add_le32 (struct net_buf_simple *buf, uint32_t val)
 Add 32-bit value at the end of the buffer.
 
void net_buf_simple_add_be32 (struct net_buf_simple *buf, uint32_t val)
 Add 32-bit value at the end of the buffer.
 
void net_buf_simple_add_le40 (struct net_buf_simple *buf, uint64_t val)
 Add 40-bit value at the end of the buffer.
 
void net_buf_simple_add_be40 (struct net_buf_simple *buf, uint64_t val)
 Add 40-bit value at the end of the buffer.
 
void net_buf_simple_add_le48 (struct net_buf_simple *buf, uint64_t val)
 Add 48-bit value at the end of the buffer.
 
void net_buf_simple_add_be48 (struct net_buf_simple *buf, uint64_t val)
 Add 48-bit value at the end of the buffer.
 
void net_buf_simple_add_le64 (struct net_buf_simple *buf, uint64_t val)
 Add 64-bit value at the end of the buffer.
 
void net_buf_simple_add_be64 (struct net_buf_simple *buf, uint64_t val)
 Add 64-bit value at the end of the buffer.
 
void * net_buf_simple_remove_mem (struct net_buf_simple *buf, size_t len)
 Remove data from the end of the buffer.
 
uint8_t net_buf_simple_remove_u8 (struct net_buf_simple *buf)
 Remove a 8-bit value from the end of the buffer.
 
uint16_t net_buf_simple_remove_le16 (struct net_buf_simple *buf)
 Remove and convert 16 bits from the end of the buffer.
 
uint16_t net_buf_simple_remove_be16 (struct net_buf_simple *buf)
 Remove and convert 16 bits from the end of the buffer.
 
uint32_t net_buf_simple_remove_le24 (struct net_buf_simple *buf)
 Remove and convert 24 bits from the end of the buffer.
 
uint32_t net_buf_simple_remove_be24 (struct net_buf_simple *buf)
 Remove and convert 24 bits from the end of the buffer.
 
uint32_t net_buf_simple_remove_le32 (struct net_buf_simple *buf)
 Remove and convert 32 bits from the end of the buffer.
 
uint32_t net_buf_simple_remove_be32 (struct net_buf_simple *buf)
 Remove and convert 32 bits from the end of the buffer.
 
uint64_t net_buf_simple_remove_le40 (struct net_buf_simple *buf)
 Remove and convert 40 bits from the end of the buffer.
 
uint64_t net_buf_simple_remove_be40 (struct net_buf_simple *buf)
 Remove and convert 40 bits from the end of the buffer.
 
uint64_t net_buf_simple_remove_le48 (struct net_buf_simple *buf)
 Remove and convert 48 bits from the end of the buffer.
 
uint64_t net_buf_simple_remove_be48 (struct net_buf_simple *buf)
 Remove and convert 48 bits from the end of the buffer.
 
uint64_t net_buf_simple_remove_le64 (struct net_buf_simple *buf)
 Remove and convert 64 bits from the end of the buffer.
 
uint64_t net_buf_simple_remove_be64 (struct net_buf_simple *buf)
 Remove and convert 64 bits from the end of the buffer.
 
void * net_buf_simple_push (struct net_buf_simple *buf, size_t len)
 Prepare data to be added to the start of the buffer.
 
void * net_buf_simple_push_mem (struct net_buf_simple *buf, const void *mem, size_t len)
 Copy given number of bytes from memory to the start of the buffer.
 
void net_buf_simple_push_le16 (struct net_buf_simple *buf, uint16_t val)
 Push 16-bit value to the beginning of the buffer.
 
void net_buf_simple_push_be16 (struct net_buf_simple *buf, uint16_t val)
 Push 16-bit value to the beginning of the buffer.
 
void net_buf_simple_push_u8 (struct net_buf_simple *buf, uint8_t val)
 Push 8-bit value to the beginning of the buffer.
 
void net_buf_simple_push_le24 (struct net_buf_simple *buf, uint32_t val)
 Push 24-bit value to the beginning of the buffer.
 
void net_buf_simple_push_be24 (struct net_buf_simple *buf, uint32_t val)
 Push 24-bit value to the beginning of the buffer.
 
void net_buf_simple_push_le32 (struct net_buf_simple *buf, uint32_t val)
 Push 32-bit value to the beginning of the buffer.
 
void net_buf_simple_push_be32 (struct net_buf_simple *buf, uint32_t val)
 Push 32-bit value to the beginning of the buffer.
 
void net_buf_simple_push_le40 (struct net_buf_simple *buf, uint64_t val)
 Push 40-bit value to the beginning of the buffer.
 
void net_buf_simple_push_be40 (struct net_buf_simple *buf, uint64_t val)
 Push 40-bit value to the beginning of the buffer.
 
void net_buf_simple_push_le48 (struct net_buf_simple *buf, uint64_t val)
 Push 48-bit value to the beginning of the buffer.
 
void net_buf_simple_push_be48 (struct net_buf_simple *buf, uint64_t val)
 Push 48-bit value to the beginning of the buffer.
 
void net_buf_simple_push_le64 (struct net_buf_simple *buf, uint64_t val)
 Push 64-bit value to the beginning of the buffer.
 
void net_buf_simple_push_be64 (struct net_buf_simple *buf, uint64_t val)
 Push 64-bit value to the beginning of the buffer.
 
void * net_buf_simple_pull (struct net_buf_simple *buf, size_t len)
 Remove data from the beginning of the buffer.
 
void * net_buf_simple_pull_mem (struct net_buf_simple *buf, size_t len)
 Remove data from the beginning of the buffer.
 
uint8_t net_buf_simple_pull_u8 (struct net_buf_simple *buf)
 Remove a 8-bit value from the beginning of the buffer.
 
uint16_t net_buf_simple_pull_le16 (struct net_buf_simple *buf)
 Remove and convert 16 bits from the beginning of the buffer.
 
uint16_t net_buf_simple_pull_be16 (struct net_buf_simple *buf)
 Remove and convert 16 bits from the beginning of the buffer.
 
uint32_t net_buf_simple_pull_le24 (struct net_buf_simple *buf)
 Remove and convert 24 bits from the beginning of the buffer.
 
uint32_t net_buf_simple_pull_be24 (struct net_buf_simple *buf)
 Remove and convert 24 bits from the beginning of the buffer.
 
uint32_t net_buf_simple_pull_le32 (struct net_buf_simple *buf)
 Remove and convert 32 bits from the beginning of the buffer.
 
uint32_t net_buf_simple_pull_be32 (struct net_buf_simple *buf)
 Remove and convert 32 bits from the beginning of the buffer.
 
uint64_t net_buf_simple_pull_le40 (struct net_buf_simple *buf)
 Remove and convert 40 bits from the beginning of the buffer.
 
uint64_t net_buf_simple_pull_be40 (struct net_buf_simple *buf)
 Remove and convert 40 bits from the beginning of the buffer.
 
uint64_t net_buf_simple_pull_le48 (struct net_buf_simple *buf)
 Remove and convert 48 bits from the beginning of the buffer.
 
uint64_t net_buf_simple_pull_be48 (struct net_buf_simple *buf)
 Remove and convert 48 bits from the beginning of the buffer.
 
uint64_t net_buf_simple_pull_le64 (struct net_buf_simple *buf)
 Remove and convert 64 bits from the beginning of the buffer.
 
uint64_t net_buf_simple_pull_be64 (struct net_buf_simple *buf)
 Remove and convert 64 bits from the beginning of the buffer.
 
static uint8_tnet_buf_simple_tail (struct net_buf_simple *buf)
 Get the tail pointer for a buffer.
 
size_t net_buf_simple_headroom (struct net_buf_simple *buf)
 Check buffer headroom.
 
size_t net_buf_simple_tailroom (struct net_buf_simple *buf)
 Check buffer tailroom.
 
uint16_t net_buf_simple_max_len (struct net_buf_simple *buf)
 Check maximum net_buf_simple::len value.
 
static void net_buf_simple_save (struct net_buf_simple *buf, struct net_buf_simple_state *state)
 Save the parsing state of a buffer.
 
static void net_buf_simple_restore (struct net_buf_simple *buf, struct net_buf_simple_state *state)
 Restore the parsing state of a buffer.
 
struct net_buf_poolnet_buf_pool_get (int id)
 Looks up a pool based on its ID.
 
int net_buf_id (struct net_buf *buf)
 Get a zero-based index for a buffer.
 
struct net_bufnet_buf_alloc_fixed (struct net_buf_pool *pool, k_timeout_t timeout)
 Allocate a new fixed buffer from a pool.
 
static struct net_bufnet_buf_alloc (struct net_buf_pool *pool, k_timeout_t timeout)
 
struct net_bufnet_buf_alloc_len (struct net_buf_pool *pool, size_t size, k_timeout_t timeout)
 Allocate a new variable length buffer from a pool.
 
struct net_bufnet_buf_alloc_with_data (struct net_buf_pool *pool, void *data, size_t size, k_timeout_t timeout)
 Allocate a new buffer from a pool but with external data pointer.
 
struct net_bufnet_buf_get (struct k_fifo *fifo, k_timeout_t timeout)
 Get a buffer from a FIFO.
 
static void net_buf_destroy (struct net_buf *buf)
 Destroy buffer from custom destroy callback.
 
void net_buf_reset (struct net_buf *buf)
 Reset buffer.
 
void net_buf_simple_reserve (struct net_buf_simple *buf, size_t reserve)
 Initialize buffer with the given headroom.
 
void net_buf_slist_put (sys_slist_t *list, struct net_buf *buf)
 Put a buffer into a list.
 
struct net_bufnet_buf_slist_get (sys_slist_t *list)
 Get a buffer from a list.
 
void net_buf_put (struct k_fifo *fifo, struct net_buf *buf)
 Put a buffer to the end of a FIFO.
 
void net_buf_unref (struct net_buf *buf)
 Decrements the reference count of a buffer.
 
struct net_bufnet_buf_ref (struct net_buf *buf)
 Increment the reference count of a buffer.
 
struct net_bufnet_buf_clone (struct net_buf *buf, k_timeout_t timeout)
 Clone buffer.
 
static void * net_buf_user_data (const struct net_buf *buf)
 Get a pointer to the user data of a buffer.
 
int net_buf_user_data_copy (struct net_buf *dst, const struct net_buf *src)
 Copy user data from one to another buffer.
 
static void net_buf_reserve (struct net_buf *buf, size_t reserve)
 Initialize buffer with the given headroom.
 
static void * net_buf_add (struct net_buf *buf, size_t len)
 Prepare data to be added at the end of the buffer.
 
static void * net_buf_add_mem (struct net_buf *buf, const void *mem, size_t len)
 Copies the given number of bytes to the end of the buffer.
 
static uint8_tnet_buf_add_u8 (struct net_buf *buf, uint8_t val)
 Add (8-bit) byte at the end of the buffer.
 
static void net_buf_add_le16 (struct net_buf *buf, uint16_t val)
 Add 16-bit value at the end of the buffer.
 
static void net_buf_add_be16 (struct net_buf *buf, uint16_t val)
 Add 16-bit value at the end of the buffer.
 
static void net_buf_add_le24 (struct net_buf *buf, uint32_t val)
 Add 24-bit value at the end of the buffer.
 
static void net_buf_add_be24 (struct net_buf *buf, uint32_t val)
 Add 24-bit value at the end of the buffer.
 
static void net_buf_add_le32 (struct net_buf *buf, uint32_t val)
 Add 32-bit value at the end of the buffer.
 
static void net_buf_add_be32 (struct net_buf *buf, uint32_t val)
 Add 32-bit value at the end of the buffer.
 
static void net_buf_add_le40 (struct net_buf *buf, uint64_t val)
 Add 40-bit value at the end of the buffer.
 
static void net_buf_add_be40 (struct net_buf *buf, uint64_t val)
 Add 40-bit value at the end of the buffer.
 
static void net_buf_add_le48 (struct net_buf *buf, uint64_t val)
 Add 48-bit value at the end of the buffer.
 
static void net_buf_add_be48 (struct net_buf *buf, uint64_t val)
 Add 48-bit value at the end of the buffer.
 
static void net_buf_add_le64 (struct net_buf *buf, uint64_t val)
 Add 64-bit value at the end of the buffer.
 
static void net_buf_add_be64 (struct net_buf *buf, uint64_t val)
 Add 64-bit value at the end of the buffer.
 
static void * net_buf_remove_mem (struct net_buf *buf, size_t len)
 Remove data from the end of the buffer.
 
static uint8_t net_buf_remove_u8 (struct net_buf *buf)
 Remove a 8-bit value from the end of the buffer.
 
static uint16_t net_buf_remove_le16 (struct net_buf *buf)
 Remove and convert 16 bits from the end of the buffer.
 
static uint16_t net_buf_remove_be16 (struct net_buf *buf)
 Remove and convert 16 bits from the end of the buffer.
 
static uint32_t net_buf_remove_be24 (struct net_buf *buf)
 Remove and convert 24 bits from the end of the buffer.
 
static uint32_t net_buf_remove_le24 (struct net_buf *buf)
 Remove and convert 24 bits from the end of the buffer.
 
static uint32_t net_buf_remove_le32 (struct net_buf *buf)
 Remove and convert 32 bits from the end of the buffer.
 
static uint32_t net_buf_remove_be32 (struct net_buf *buf)
 Remove and convert 32 bits from the end of the buffer.
 
static uint64_t net_buf_remove_le40 (struct net_buf *buf)
 Remove and convert 40 bits from the end of the buffer.
 
static uint64_t net_buf_remove_be40 (struct net_buf *buf)
 Remove and convert 40 bits from the end of the buffer.
 
static uint64_t net_buf_remove_le48 (struct net_buf *buf)
 Remove and convert 48 bits from the end of the buffer.
 
static uint64_t net_buf_remove_be48 (struct net_buf *buf)
 Remove and convert 48 bits from the end of the buffer.
 
static uint64_t net_buf_remove_le64 (struct net_buf *buf)
 Remove and convert 64 bits from the end of the buffer.
 
static uint64_t net_buf_remove_be64 (struct net_buf *buf)
 Remove and convert 64 bits from the end of the buffer.
 
static void * net_buf_push (struct net_buf *buf, size_t len)
 Prepare data to be added at the start of the buffer.
 
static void * net_buf_push_mem (struct net_buf *buf, const void *mem, size_t len)
 Copies the given number of bytes to the start of the buffer.
 
static void net_buf_push_u8 (struct net_buf *buf, uint8_t val)
 Push 8-bit value to the beginning of the buffer.
 
static void net_buf_push_le16 (struct net_buf *buf, uint16_t val)
 Push 16-bit value to the beginning of the buffer.
 
static void net_buf_push_be16 (struct net_buf *buf, uint16_t val)
 Push 16-bit value to the beginning of the buffer.
 
static void net_buf_push_le24 (struct net_buf *buf, uint32_t val)
 Push 24-bit value to the beginning of the buffer.
 
static void net_buf_push_be24 (struct net_buf *buf, uint32_t val)
 Push 24-bit value to the beginning of the buffer.
 
static void net_buf_push_le32 (struct net_buf *buf, uint32_t val)
 Push 32-bit value to the beginning of the buffer.
 
static void net_buf_push_be32 (struct net_buf *buf, uint32_t val)
 Push 32-bit value to the beginning of the buffer.
 
static void net_buf_push_le40 (struct net_buf *buf, uint64_t val)
 Push 40-bit value to the beginning of the buffer.
 
static void net_buf_push_be40 (struct net_buf *buf, uint64_t val)
 Push 40-bit value to the beginning of the buffer.
 
static void net_buf_push_le48 (struct net_buf *buf, uint64_t val)
 Push 48-bit value to the beginning of the buffer.
 
static void net_buf_push_be48 (struct net_buf *buf, uint64_t val)
 Push 48-bit value to the beginning of the buffer.
 
static void net_buf_push_le64 (struct net_buf *buf, uint64_t val)
 Push 64-bit value to the beginning of the buffer.
 
static void net_buf_push_be64 (struct net_buf *buf, uint64_t val)
 Push 64-bit value to the beginning of the buffer.
 
static void * net_buf_pull (struct net_buf *buf, size_t len)
 Remove data from the beginning of the buffer.
 
static void * net_buf_pull_mem (struct net_buf *buf, size_t len)
 Remove data from the beginning of the buffer.
 
static uint8_t net_buf_pull_u8 (struct net_buf *buf)
 Remove a 8-bit value from the beginning of the buffer.
 
static uint16_t net_buf_pull_le16 (struct net_buf *buf)
 Remove and convert 16 bits from the beginning of the buffer.
 
static uint16_t net_buf_pull_be16 (struct net_buf *buf)
 Remove and convert 16 bits from the beginning of the buffer.
 
static uint32_t net_buf_pull_le24 (struct net_buf *buf)
 Remove and convert 24 bits from the beginning of the buffer.
 
static uint32_t net_buf_pull_be24 (struct net_buf *buf)
 Remove and convert 24 bits from the beginning of the buffer.
 
static uint32_t net_buf_pull_le32 (struct net_buf *buf)
 Remove and convert 32 bits from the beginning of the buffer.
 
static uint32_t net_buf_pull_be32 (struct net_buf *buf)
 Remove and convert 32 bits from the beginning of the buffer.
 
static uint64_t net_buf_pull_le40 (struct net_buf *buf)
 Remove and convert 40 bits from the beginning of the buffer.
 
static uint64_t net_buf_pull_be40 (struct net_buf *buf)
 Remove and convert 40 bits from the beginning of the buffer.
 
static uint64_t net_buf_pull_le48 (struct net_buf *buf)
 Remove and convert 48 bits from the beginning of the buffer.
 
static uint64_t net_buf_pull_be48 (struct net_buf *buf)
 Remove and convert 48 bits from the beginning of the buffer.
 
static uint64_t net_buf_pull_le64 (struct net_buf *buf)
 Remove and convert 64 bits from the beginning of the buffer.
 
static uint64_t net_buf_pull_be64 (struct net_buf *buf)
 Remove and convert 64 bits from the beginning of the buffer.
 
static size_t net_buf_tailroom (struct net_buf *buf)
 Check buffer tailroom.
 
static size_t net_buf_headroom (struct net_buf *buf)
 Check buffer headroom.
 
static uint16_t net_buf_max_len (struct net_buf *buf)
 Check maximum net_buf::len value.
 
static uint8_tnet_buf_tail (struct net_buf *buf)
 Get the tail pointer for a buffer.
 
struct net_bufnet_buf_frag_last (struct net_buf *frags)
 Find the last fragment in the fragment list.
 
void net_buf_frag_insert (struct net_buf *parent, struct net_buf *frag)
 Insert a new fragment to a chain of bufs.
 
struct net_bufnet_buf_frag_add (struct net_buf *head, struct net_buf *frag)
 Add a new fragment to the end of a chain of bufs.
 
struct net_bufnet_buf_frag_del (struct net_buf *parent, struct net_buf *frag)
 Delete existing fragment from a chain of bufs.
 
size_t net_buf_linearize (void *dst, size_t dst_len, struct net_buf *src, size_t offset, size_t len)
 Copy bytes from net_buf chain starting at offset to linear buffer.
 
size_t net_buf_append_bytes (struct net_buf *buf, size_t len, const void *value, k_timeout_t timeout, net_buf_allocator_cb allocate_cb, void *user_data)
 Append data to a list of net_buf.
 
size_t net_buf_data_match (const struct net_buf *buf, size_t offset, const void *data, size_t len)
 Match data with a net_buf's content.
 
static struct net_bufnet_buf_skip (struct net_buf *buf, size_t len)
 Skip N number of bytes in a net_buf.
 
static size_t net_buf_frags_len (struct net_buf *buf)
 Calculate amount of bytes stored in fragments.
 

Detailed Description

Network buffer library.

Macro Definition Documentation

◆ NET_BUF_EXTERNAL_DATA

#define NET_BUF_EXTERNAL_DATA   BIT(0)

#include <zephyr/net/buf.h>

Flag indicating that the buffer's associated data pointer, points to externally allocated memory.

Therefore once ref goes down to zero, the pointed data will not need to be deallocated. This never needs to be explicitly set or unset by the net_buf API user. Such net_buf is exclusively instantiated via net_buf_alloc_with_data() function. Reference count mechanism however will behave the same way, and ref count going to 0 will free the net_buf but no the data pointer in it.

◆ NET_BUF_POOL_DEFINE

#define NET_BUF_POOL_DEFINE (   _name,
  _count,
  _size,
  _ud_size,
  _destroy 
)     NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)

#include <zephyr/net/buf.h>

Define a new pool for buffers.

Defines a net_buf_pool struct and the necessary memory storage (array of structs) for the needed amount of buffers. After this,the buffers can be accessed from the pool through net_buf_alloc. The pool is defined as a static variable, so if it needs to be exported outside the current module this needs to happen with the help of a separate pointer rather than an extern declaration.

If provided with a custom destroy callback this callback is responsible for eventually calling net_buf_destroy() to complete the process of returning the buffer to the pool.

Parameters
_nameName of the pool variable.
_countNumber of buffers in the pool.
_sizeMaximum data size for each buffer.
_ud_sizeAmount of user data space to reserve.
_destroyOptional destroy callback when buffer is freed.

◆ NET_BUF_POOL_FIXED_DEFINE

#define NET_BUF_POOL_FIXED_DEFINE (   _name,
  _count,
  _data_size,
  _ud_size,
  _destroy 
)

#include <zephyr/net/buf.h>

Value:
_NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \
static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \
.data_pool = (uint8_t *)net_buf_data_##_name, \
}; \
static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \
.cb = &net_buf_fixed_cb, \
.alloc_data = (void *)&net_buf_fixed_##_name, \
.max_alloc_size = _data_size, \
}; \
NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \
_net_buf_##_name, _count, _ud_size, \
_destroy)
#define STRUCT_SECTION_ITERABLE(struct_type, varname)
Defines a new element for an iterable section.
Definition: iterable_sections.h:216
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Definition: buf.h:1059
size_t max_alloc_size
Definition: buf.h:1062
Definition: buf.h:1175
uint8_t * data_pool
Definition: buf.h:1176
Network buffer pool representation.
Definition: buf.h:1070

Define a new pool for buffers based on fixed-size data.

Defines a net_buf_pool struct and the necessary memory storage (array of structs) for the needed amount of buffers. After this, the buffers can be accessed from the pool through net_buf_alloc. The pool is defined as a static variable, so if it needs to be exported outside the current module this needs to happen with the help of a separate pointer rather than an extern declaration.

The data payload of the buffers will be allocated from a byte array of fixed sized chunks. This kind of pool does not support blocking on the data allocation, so the timeout passed to net_buf_alloc will be always treated as K_NO_WAIT when trying to allocate the data. This means that allocation failures, i.e. NULL returns, must always be handled cleanly.

If provided with a custom destroy callback, this callback is responsible for eventually calling net_buf_destroy() to complete the process of returning the buffer to the pool.

Parameters
_nameName of the pool variable.
_countNumber of buffers in the pool.
_data_sizeMaximum data payload per buffer.
_ud_sizeUser data space to reserve per buffer.
_destroyOptional destroy callback when buffer is freed.

◆ NET_BUF_POOL_HEAP_DEFINE

#define NET_BUF_POOL_HEAP_DEFINE (   _name,
  _count,
  _ud_size,
  _destroy 
)

#include <zephyr/net/buf.h>

Value:
_NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \
_net_buf_##_name, _count, _ud_size, \
_destroy)

Define a new pool for buffers using the heap for the data.

Defines a net_buf_pool struct and the necessary memory storage (array of structs) for the needed amount of buffers. After this, the buffers can be accessed from the pool through net_buf_alloc. The pool is defined as a static variable, so if it needs to be exported outside the current module this needs to happen with the help of a separate pointer rather than an extern declaration.

The data payload of the buffers will be allocated from the heap using k_malloc, so CONFIG_HEAP_MEM_POOL_SIZE must be set to a positive value. This kind of pool does not support blocking on the data allocation, so the timeout passed to net_buf_alloc will be always treated as K_NO_WAIT when trying to allocate the data. This means that allocation failures, i.e. NULL returns, must always be handled cleanly.

If provided with a custom destroy callback, this callback is responsible for eventually calling net_buf_destroy() to complete the process of returning the buffer to the pool.

Parameters
_nameName of the pool variable.
_countNumber of buffers in the pool.
_ud_sizeUser data space to reserve per buffer.
_destroyOptional destroy callback when buffer is freed.

◆ NET_BUF_POOL_VAR_DEFINE

#define NET_BUF_POOL_VAR_DEFINE (   _name,
  _count,
  _data_size,
  _ud_size,
  _destroy 
)

#include <zephyr/net/buf.h>

Value:
_NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
.cb = &net_buf_var_cb, \
.alloc_data = &net_buf_mem_pool_##_name, \
}; \
NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
_net_buf_##_name, _count, _ud_size, \
_destroy)
const struct net_buf_data_cb * cb
Definition: buf.h:1060

Define a new pool for buffers with variable size payloads.

Defines a net_buf_pool struct and the necessary memory storage (array of structs) for the needed amount of buffers. After this, the buffers can be accessed from the pool through net_buf_alloc. The pool is defined as a static variable, so if it needs to be exported outside the current module this needs to happen with the help of a separate pointer rather than an extern declaration.

The data payload of the buffers will be based on a memory pool from which variable size payloads may be allocated.

If provided with a custom destroy callback, this callback is responsible for eventually calling net_buf_destroy() to complete the process of returning the buffer to the pool.

Parameters
_nameName of the pool variable.
_countNumber of buffers in the pool.
_data_sizeTotal amount of memory available for data payloads.
_ud_sizeUser data space to reserve per buffer.
_destroyOptional destroy callback when buffer is freed.

◆ NET_BUF_SIMPLE

#define NET_BUF_SIMPLE (   _size)

#include <zephyr/net/buf.h>

Value:
((struct net_buf_simple *)(&(struct { \
struct net_buf_simple buf; \
uint8_t data[_size]; \
}) { \
.buf.size = _size, \
}))
Simple network buffer representation.
Definition: buf.h:87
uint8_t * data
Pointer to the start of data in the buffer.
Definition: buf.h:89

Define a net_buf_simple stack variable and get a pointer to it.

This is a helper macro which is used to define a net_buf_simple object on the stack and the get a pointer to it as follows:

struct net_buf_simple *my_buf = NET_BUF_SIMPLE(10);

After creating the object it needs to be initialized by calling net_buf_simple_init().

Parameters
_sizeMaximum data storage for the buffer.
Returns
Pointer to stack-allocated net_buf_simple object.

◆ NET_BUF_SIMPLE_DEFINE

#define NET_BUF_SIMPLE_DEFINE (   _name,
  _size 
)

#include <zephyr/net/buf.h>

Value:
uint8_t net_buf_data_##_name[_size]; \
struct net_buf_simple _name = { \
.data = net_buf_data_##_name, \
.len = 0, \
.size = _size, \
.__buf = net_buf_data_##_name, \
}
uint16_t len
Length of the data behind the data pointer.
Definition: buf.h:96

Define a net_buf_simple stack variable.

This is a helper macro which is used to define a net_buf_simple object on the stack.

Parameters
_nameName of the net_buf_simple object.
_sizeMaximum data storage for the buffer.

◆ NET_BUF_SIMPLE_DEFINE_STATIC

#define NET_BUF_SIMPLE_DEFINE_STATIC (   _name,
  _size 
)

#include <zephyr/net/buf.h>

Value:
static __noinit uint8_t net_buf_data_##_name[_size]; \
static struct net_buf_simple _name = { \
.data = net_buf_data_##_name, \
.len = 0, \
.size = _size, \
.__buf = net_buf_data_##_name, \
}

Define a static net_buf_simple variable.

This is a helper macro which is used to define a static net_buf_simple object.

Parameters
_nameName of the net_buf_simple object.
_sizeMaximum data storage for the buffer.

Typedef Documentation

◆ net_buf_allocator_cb

net_buf_allocator_cb

#include <zephyr/net/buf.h>

Network buffer allocator callback.

The allocator callback is called when net_buf_append_bytes needs to allocate a new net_buf.

Parameters
timeoutAffects the action taken should the net buf pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait until the specified timeout.
user_dataThe user data given in net_buf_append_bytes call.
Returns
pointer to allocated net_buf or NULL on error.

Function Documentation

◆ net_buf_add()

static void * net_buf_add ( struct net_buf buf,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Prepare data to be added at the end of the buffer.

Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
lenNumber of bytes to increment the length with.
Returns
The original tail of the buffer.

◆ net_buf_add_be16()

static void net_buf_add_be16 ( struct net_buf buf,
uint16_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 16-bit value at the end of the buffer.

Adds 16-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val16-bit value to be added.

◆ net_buf_add_be24()

static void net_buf_add_be24 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 24-bit value at the end of the buffer.

Adds 24-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val24-bit value to be added.

◆ net_buf_add_be32()

static void net_buf_add_be32 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 32-bit value at the end of the buffer.

Adds 32-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val32-bit value to be added.

◆ net_buf_add_be40()

static void net_buf_add_be40 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 40-bit value at the end of the buffer.

Adds 40-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val40-bit value to be added.

◆ net_buf_add_be48()

static void net_buf_add_be48 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 48-bit value at the end of the buffer.

Adds 48-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val48-bit value to be added.

◆ net_buf_add_be64()

static void net_buf_add_be64 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 64-bit value at the end of the buffer.

Adds 64-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val64-bit value to be added.

◆ net_buf_add_le16()

static void net_buf_add_le16 ( struct net_buf buf,
uint16_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 16-bit value at the end of the buffer.

Adds 16-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val16-bit value to be added.

◆ net_buf_add_le24()

static void net_buf_add_le24 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 24-bit value at the end of the buffer.

Adds 24-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val24-bit value to be added.

◆ net_buf_add_le32()

static void net_buf_add_le32 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 32-bit value at the end of the buffer.

Adds 32-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val32-bit value to be added.

◆ net_buf_add_le40()

static void net_buf_add_le40 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 40-bit value at the end of the buffer.

Adds 40-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val40-bit value to be added.

◆ net_buf_add_le48()

static void net_buf_add_le48 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 48-bit value at the end of the buffer.

Adds 48-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val48-bit value to be added.

◆ net_buf_add_le64()

static void net_buf_add_le64 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add 64-bit value at the end of the buffer.

Adds 64-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val64-bit value to be added.

◆ net_buf_add_mem()

static void * net_buf_add_mem ( struct net_buf buf,
const void *  mem,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Copies the given number of bytes to the end of the buffer.

Increments the data length of the buffer to account for more data at the end.

Parameters
bufBuffer to update.
memLocation of data to be added.
lenLength of data to be added
Returns
The original tail of the buffer.

◆ net_buf_add_u8()

static uint8_t * net_buf_add_u8 ( struct net_buf buf,
uint8_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Add (8-bit) byte at the end of the buffer.

Increments the data length of the buffer to account for more data at the end.

Parameters
bufBuffer to update.
valbyte value to be added.
Returns
Pointer to the value added

◆ net_buf_alloc()

static struct net_buf * net_buf_alloc ( struct net_buf_pool pool,
k_timeout_t  timeout 
)
inlinestatic

#include <zephyr/net/buf.h>

Note
Some types of data allocators do not support blocking (such as the HEAP type). In this case it's still possible for net_buf_alloc() to fail (return NULL) even if it was given K_FOREVER.
The timeout value will be overridden to K_NO_WAIT if called from the system workqueue.
Parameters
poolWhich pool to allocate the buffer from.
timeoutAffects the action taken should the pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait until the specified timeout.
Returns
New buffer or NULL if out of buffers.

◆ net_buf_alloc_fixed()

struct net_buf * net_buf_alloc_fixed ( struct net_buf_pool pool,
k_timeout_t  timeout 
)

#include <zephyr/net/buf.h>

Allocate a new fixed buffer from a pool.

Note
Some types of data allocators do not support blocking (such as the HEAP type). In this case it's still possible for net_buf_alloc() to fail (return NULL) even if it was given K_FOREVER.
The timeout value will be overridden to K_NO_WAIT if called from the system workqueue.
Parameters
poolWhich pool to allocate the buffer from.
timeoutAffects the action taken should the pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait until the specified timeout.
Returns
New buffer or NULL if out of buffers.

◆ net_buf_alloc_len()

struct net_buf * net_buf_alloc_len ( struct net_buf_pool pool,
size_t  size,
k_timeout_t  timeout 
)

#include <zephyr/net/buf.h>

Allocate a new variable length buffer from a pool.

Note
Some types of data allocators do not support blocking (such as the HEAP type). In this case it's still possible for net_buf_alloc() to fail (return NULL) even if it was given K_FOREVER.
The timeout value will be overridden to K_NO_WAIT if called from the system workqueue.
Parameters
poolWhich pool to allocate the buffer from.
sizeAmount of data the buffer must be able to fit.
timeoutAffects the action taken should the pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait until the specified timeout.
Returns
New buffer or NULL if out of buffers.

◆ net_buf_alloc_with_data()

struct net_buf * net_buf_alloc_with_data ( struct net_buf_pool pool,
void *  data,
size_t  size,
k_timeout_t  timeout 
)

#include <zephyr/net/buf.h>

Allocate a new buffer from a pool but with external data pointer.

Allocate a new buffer from a pool, where the data pointer comes from the user and not from the pool.

Note
Some types of data allocators do not support blocking (such as the HEAP type). In this case it's still possible for net_buf_alloc() to fail (return NULL) even if it was given K_FOREVER.
The timeout value will be overridden to K_NO_WAIT if called from the system workqueue.
Parameters
poolWhich pool to allocate the buffer from.
dataExternal data pointer
sizeAmount of data the pointed data buffer if able to fit.
timeoutAffects the action taken should the pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait until the specified timeout.
Returns
New buffer or NULL if out of buffers.

◆ net_buf_append_bytes()

size_t net_buf_append_bytes ( struct net_buf buf,
size_t  len,
const void *  value,
k_timeout_t  timeout,
net_buf_allocator_cb  allocate_cb,
void *  user_data 
)

#include <zephyr/net/buf.h>

Append data to a list of net_buf.

Append data to a net_buf. If there is not enough space in the net_buf then more net_buf will be added, unless there are no free net_buf and timeout occurs. If not allocator is provided it attempts to allocate from the same pool as the original buffer.

Parameters
bufNetwork buffer.
lenTotal length of input data
valueData to be added
timeoutTimeout is passed to the net_buf allocator callback.
allocate_cbWhen a new net_buf is required, use this callback.
user_dataA user data pointer to be supplied to the allocate_cb. This pointer is can be anything from a mem_pool or a net_pkt, the logic is left up to the allocate_cb function.
Returns
Length of data actually added. This may be less than input length if other timeout than K_FOREVER was used, and there were no free fragments in a pool to accommodate all data.

◆ net_buf_clone()

struct net_buf * net_buf_clone ( struct net_buf buf,
k_timeout_t  timeout 
)

#include <zephyr/net/buf.h>

Clone buffer.

Duplicate given buffer including any (user) data and headers currently stored.

Parameters
bufA valid pointer on a buffer
timeoutAffects the action taken should the pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait until the specified timeout.
Returns
Cloned buffer or NULL if out of buffers.

◆ net_buf_data_match()

size_t net_buf_data_match ( const struct net_buf buf,
size_t  offset,
const void *  data,
size_t  len 
)

#include <zephyr/net/buf.h>

Match data with a net_buf's content.

Compare data with a content of a net_buf. Provide information about the number of bytes matching between both. If needed, traverse through multiple buffer fragments.

Parameters
bufNetwork buffer
offsetStarting offset to compare from
dataData buffer for comparison
lenNumber of bytes to compare
Returns
The number of bytes compared before the first difference.

◆ net_buf_destroy()

static void net_buf_destroy ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Destroy buffer from custom destroy callback.

This helper is only intended to be used from custom destroy callbacks. If no custom destroy callback is given to NET_BUF_POOL_*_DEFINE() then there is no need to use this API.

Parameters
bufBuffer to destroy.

◆ net_buf_frag_add()

struct net_buf * net_buf_frag_add ( struct net_buf head,
struct net_buf frag 
)

#include <zephyr/net/buf.h>

Add a new fragment to the end of a chain of bufs.

Append a new fragment into the buffer fragments list.

Note: This function takes ownership of the fragment reference so the caller is not required to unref.

Parameters
headHead of the fragment chain.
fragFragment to add.
Returns
New head of the fragment chain. Either head (if head was non-NULL) or frag (if head was NULL).

◆ net_buf_frag_del()

struct net_buf * net_buf_frag_del ( struct net_buf parent,
struct net_buf frag 
)

#include <zephyr/net/buf.h>

Delete existing fragment from a chain of bufs.

Parameters
parentParent buffer/fragment, or NULL if there is no parent.
fragFragment to delete.
Returns
Pointer to the buffer following the fragment, or NULL if it had no further fragments.

◆ net_buf_frag_insert()

void net_buf_frag_insert ( struct net_buf parent,
struct net_buf frag 
)

#include <zephyr/net/buf.h>

Insert a new fragment to a chain of bufs.

Insert a new fragment into the buffer fragments list after the parent.

Note: This function takes ownership of the fragment reference so the caller is not required to unref.

Parameters
parentParent buffer/fragment.
fragFragment to insert.

◆ net_buf_frag_last()

struct net_buf * net_buf_frag_last ( struct net_buf frags)

#include <zephyr/net/buf.h>

Find the last fragment in the fragment list.

Returns
Pointer to last fragment in the list.

◆ net_buf_frags_len()

static size_t net_buf_frags_len ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Calculate amount of bytes stored in fragments.

Calculates the total amount of data stored in the given buffer and the fragments linked to it.

Parameters
bufBuffer to start off with.
Returns
Number of bytes in the buffer and its fragments.

◆ net_buf_get()

struct net_buf * net_buf_get ( struct k_fifo fifo,
k_timeout_t  timeout 
)

#include <zephyr/net/buf.h>

Get a buffer from a FIFO.

This function is NOT thread-safe if the buffers in the FIFO contain fragments.

Parameters
fifoWhich FIFO to take the buffer from.
timeoutAffects the action taken should the FIFO be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait until the specified timeout.
Returns
New buffer or NULL if the FIFO is empty.

◆ net_buf_headroom()

static size_t net_buf_headroom ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Check buffer headroom.

Check how much free space there is in the beginning of the buffer.

buf A valid pointer on a buffer

Returns
Number of bytes available in the beginning of the buffer.

◆ net_buf_id()

int net_buf_id ( struct net_buf buf)

#include <zephyr/net/buf.h>

Get a zero-based index for a buffer.

This function will translate a buffer into a zero-based index, based on its placement in its buffer pool. This can be useful if you want to associate an external array of meta-data contexts with the buffers of a pool.

Parameters
bufNetwork buffer.
Returns
Zero-based index for the buffer.

◆ net_buf_linearize()

size_t net_buf_linearize ( void *  dst,
size_t  dst_len,
struct net_buf src,
size_t  offset,
size_t  len 
)

#include <zephyr/net/buf.h>

Copy bytes from net_buf chain starting at offset to linear buffer.

Copy (extract) len bytes from src net_buf chain, starting from offset in it, to a linear buffer dst. Return number of bytes actually copied, which may be less than requested, if net_buf chain doesn't have enough data, or destination buffer is too small.

Parameters
dstDestination buffer
dst_lenDestination buffer length
srcSource net_buf chain
offsetStarting offset to copy from
lenNumber of bytes to copy
Returns
number of bytes actually copied

◆ net_buf_max_len()

static uint16_t net_buf_max_len ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Check maximum net_buf::len value.

This value is depending on the number of bytes being reserved as headroom.

Parameters
bufA valid pointer on a buffer
Returns
Number of bytes usable behind the net_buf::data pointer.

◆ net_buf_pool_get()

struct net_buf_pool * net_buf_pool_get ( int  id)

#include <zephyr/net/buf.h>

Looks up a pool based on its ID.

Parameters
idPool ID (e.g. from buf->pool_id).
Returns
Pointer to pool.

◆ net_buf_pull()

static void * net_buf_pull ( struct net_buf buf,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Remove data from the beginning of the buffer.

Removes data from the beginning of the buffer by modifying the data pointer and buffer length.

Parameters
bufBuffer to update.
lenNumber of bytes to remove.
Returns
New beginning of the buffer data.

◆ net_buf_pull_be16()

static uint16_t net_buf_pull_be16 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 16-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from big endian to host endian.

◆ net_buf_pull_be24()

static uint32_t net_buf_pull_be24 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 24-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from big endian to host endian.

◆ net_buf_pull_be32()

static uint32_t net_buf_pull_be32 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 32-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
32-bit value converted from big endian to host endian.

◆ net_buf_pull_be40()

static uint64_t net_buf_pull_be40 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 40-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
40-bit value converted from big endian to host endian.

◆ net_buf_pull_be48()

static uint64_t net_buf_pull_be48 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 48-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
48-bit value converted from big endian to host endian.

◆ net_buf_pull_be64()

static uint64_t net_buf_pull_be64 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 64-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
64-bit value converted from big endian to host endian.

◆ net_buf_pull_le16()

static uint16_t net_buf_pull_le16 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 16-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from little endian to host endian.

◆ net_buf_pull_le24()

static uint32_t net_buf_pull_le24 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 24-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from little endian to host endian.

◆ net_buf_pull_le32()

static uint32_t net_buf_pull_le32 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 32-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
32-bit value converted from little endian to host endian.

◆ net_buf_pull_le40()

static uint64_t net_buf_pull_le40 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 40-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
40-bit value converted from little endian to host endian.

◆ net_buf_pull_le48()

static uint64_t net_buf_pull_le48 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 48-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
48-bit value converted from little endian to host endian.

◆ net_buf_pull_le64()

static uint64_t net_buf_pull_le64 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 64-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
64-bit value converted from little endian to host endian.

◆ net_buf_pull_mem()

static void * net_buf_pull_mem ( struct net_buf buf,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Remove data from the beginning of the buffer.

Removes data from the beginning of the buffer by modifying the data pointer and buffer length.

Parameters
bufBuffer to update.
lenNumber of bytes to remove.
Returns
Pointer to the old beginning of the buffer data.

◆ net_buf_pull_u8()

static uint8_t net_buf_pull_u8 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove a 8-bit value from the beginning of the buffer.

Same idea as with net_buf_pull(), but a helper for operating on 8-bit values.

Parameters
bufA valid pointer on a buffer.
Returns
The 8-bit removed value

◆ net_buf_push()

static void * net_buf_push ( struct net_buf buf,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Prepare data to be added at the start of the buffer.

Modifies the data pointer and buffer length to account for more data in the beginning of the buffer.

Parameters
bufBuffer to update.
lenNumber of bytes to add to the beginning.
Returns
The new beginning of the buffer data.

◆ net_buf_push_be16()

static void net_buf_push_be16 ( struct net_buf buf,
uint16_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 16-bit value to the beginning of the buffer.

Adds 16-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val16-bit value to be pushed to the buffer.

◆ net_buf_push_be24()

static void net_buf_push_be24 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 24-bit value to the beginning of the buffer.

Adds 24-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val24-bit value to be pushed to the buffer.

◆ net_buf_push_be32()

static void net_buf_push_be32 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 32-bit value to the beginning of the buffer.

Adds 32-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val32-bit value to be pushed to the buffer.

◆ net_buf_push_be40()

static void net_buf_push_be40 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 40-bit value to the beginning of the buffer.

Adds 40-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val40-bit value to be pushed to the buffer.

◆ net_buf_push_be48()

static void net_buf_push_be48 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 48-bit value to the beginning of the buffer.

Adds 48-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val48-bit value to be pushed to the buffer.

◆ net_buf_push_be64()

static void net_buf_push_be64 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 64-bit value to the beginning of the buffer.

Adds 64-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val64-bit value to be pushed to the buffer.

◆ net_buf_push_le16()

static void net_buf_push_le16 ( struct net_buf buf,
uint16_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 16-bit value to the beginning of the buffer.

Adds 16-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val16-bit value to be pushed to the buffer.

◆ net_buf_push_le24()

static void net_buf_push_le24 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 24-bit value to the beginning of the buffer.

Adds 24-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val24-bit value to be pushed to the buffer.

◆ net_buf_push_le32()

static void net_buf_push_le32 ( struct net_buf buf,
uint32_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 32-bit value to the beginning of the buffer.

Adds 32-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val32-bit value to be pushed to the buffer.

◆ net_buf_push_le40()

static void net_buf_push_le40 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 40-bit value to the beginning of the buffer.

Adds 40-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val40-bit value to be pushed to the buffer.

◆ net_buf_push_le48()

static void net_buf_push_le48 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 48-bit value to the beginning of the buffer.

Adds 48-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val48-bit value to be pushed to the buffer.

◆ net_buf_push_le64()

static void net_buf_push_le64 ( struct net_buf buf,
uint64_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 64-bit value to the beginning of the buffer.

Adds 64-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val64-bit value to be pushed to the buffer.

◆ net_buf_push_mem()

static void * net_buf_push_mem ( struct net_buf buf,
const void *  mem,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Copies the given number of bytes to the start of the buffer.

Modifies the data pointer and buffer length to account for more data in the beginning of the buffer.

Parameters
bufBuffer to update.
memLocation of data to be added.
lenLength of data to be added.
Returns
The new beginning of the buffer data.

◆ net_buf_push_u8()

static void net_buf_push_u8 ( struct net_buf buf,
uint8_t  val 
)
inlinestatic

#include <zephyr/net/buf.h>

Push 8-bit value to the beginning of the buffer.

Adds 8-bit value the beginning of the buffer.

Parameters
bufBuffer to update.
val8-bit value to be pushed to the buffer.

◆ net_buf_put()

void net_buf_put ( struct k_fifo fifo,
struct net_buf buf 
)

#include <zephyr/net/buf.h>

Put a buffer to the end of a FIFO.

If the buffer contains follow-up fragments this function will take care of inserting them as well into the FIFO.

Parameters
fifoWhich FIFO to put the buffer to.
bufBuffer.

◆ net_buf_ref()

struct net_buf * net_buf_ref ( struct net_buf buf)

#include <zephyr/net/buf.h>

Increment the reference count of a buffer.

Parameters
bufA valid pointer on a buffer
Returns
the buffer newly referenced

◆ net_buf_remove_be16()

static uint16_t net_buf_remove_be16 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 16-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from big endian to host endian.

◆ net_buf_remove_be24()

static uint32_t net_buf_remove_be24 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 24-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from big endian to host endian.

◆ net_buf_remove_be32()

static uint32_t net_buf_remove_be32 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 32-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
32-bit value converted from big endian to host endian.

◆ net_buf_remove_be40()

static uint64_t net_buf_remove_be40 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 40-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
40-bit value converted from big endian to host endian.

◆ net_buf_remove_be48()

static uint64_t net_buf_remove_be48 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 48-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
48-bit value converted from big endian to host endian.

◆ net_buf_remove_be64()

static uint64_t net_buf_remove_be64 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 64-bit big endian data.

Parameters
bufA valid pointer on a buffer
Returns
64-bit value converted from big endian to host endian.

◆ net_buf_remove_le16()

static uint16_t net_buf_remove_le16 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 16-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from little endian to host endian.

◆ net_buf_remove_le24()

static uint32_t net_buf_remove_le24 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 24-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from little endian to host endian.

◆ net_buf_remove_le32()

static uint32_t net_buf_remove_le32 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 32-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
32-bit value converted from little endian to host endian.

◆ net_buf_remove_le40()

static uint64_t net_buf_remove_le40 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 40-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
40-bit value converted from little endian to host endian.

◆ net_buf_remove_le48()

static uint64_t net_buf_remove_le48 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 48-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
48-bit value converted from little endian to host endian.

◆ net_buf_remove_le64()

static uint64_t net_buf_remove_le64 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 64-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
64-bit value converted from little endian to host endian.

◆ net_buf_remove_mem()

static void * net_buf_remove_mem ( struct net_buf buf,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Remove data from the end of the buffer.

Removes data from the end of the buffer by modifying the buffer length.

Parameters
bufBuffer to update.
lenNumber of bytes to remove.
Returns
New end of the buffer data.

◆ net_buf_remove_u8()

static uint8_t net_buf_remove_u8 ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Remove a 8-bit value from the end of the buffer.

Same idea as with net_buf_remove_mem(), but a helper for operating on 8-bit values.

Parameters
bufA valid pointer on a buffer.
Returns
The 8-bit removed value

◆ net_buf_reserve()

static void net_buf_reserve ( struct net_buf buf,
size_t  reserve 
)
inlinestatic

#include <zephyr/net/buf.h>

Initialize buffer with the given headroom.

The buffer is not expected to contain any data when this API is called.

Parameters
bufBuffer to initialize.
reserveHow much headroom to reserve.

◆ net_buf_reset()

void net_buf_reset ( struct net_buf buf)

#include <zephyr/net/buf.h>

Reset buffer.

Reset buffer data and flags so it can be reused for other purposes.

Parameters
bufBuffer to reset.

◆ net_buf_simple_add()

void * net_buf_simple_add ( struct net_buf_simple buf,
size_t  len 
)

#include <zephyr/net/buf.h>

Prepare data to be added at the end of the buffer.

Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
lenNumber of bytes to increment the length with.
Returns
The original tail of the buffer.

◆ net_buf_simple_add_be16()

void net_buf_simple_add_be16 ( struct net_buf_simple buf,
uint16_t  val 
)

#include <zephyr/net/buf.h>

Add 16-bit value at the end of the buffer.

Adds 16-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val16-bit value to be added.

◆ net_buf_simple_add_be24()

void net_buf_simple_add_be24 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Add 24-bit value at the end of the buffer.

Adds 24-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val24-bit value to be added.

◆ net_buf_simple_add_be32()

void net_buf_simple_add_be32 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Add 32-bit value at the end of the buffer.

Adds 32-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val32-bit value to be added.

◆ net_buf_simple_add_be40()

void net_buf_simple_add_be40 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Add 40-bit value at the end of the buffer.

Adds 40-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val40-bit value to be added.

◆ net_buf_simple_add_be48()

void net_buf_simple_add_be48 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Add 48-bit value at the end of the buffer.

Adds 48-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val48-bit value to be added.

◆ net_buf_simple_add_be64()

void net_buf_simple_add_be64 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Add 64-bit value at the end of the buffer.

Adds 64-bit value in big endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val64-bit value to be added.

◆ net_buf_simple_add_le16()

void net_buf_simple_add_le16 ( struct net_buf_simple buf,
uint16_t  val 
)

#include <zephyr/net/buf.h>

Add 16-bit value at the end of the buffer.

Adds 16-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val16-bit value to be added.

◆ net_buf_simple_add_le24()

void net_buf_simple_add_le24 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Add 24-bit value at the end of the buffer.

Adds 24-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val24-bit value to be added.

◆ net_buf_simple_add_le32()

void net_buf_simple_add_le32 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Add 32-bit value at the end of the buffer.

Adds 32-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val32-bit value to be added.

◆ net_buf_simple_add_le40()

void net_buf_simple_add_le40 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Add 40-bit value at the end of the buffer.

Adds 40-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val40-bit value to be added.

◆ net_buf_simple_add_le48()

void net_buf_simple_add_le48 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Add 48-bit value at the end of the buffer.

Adds 48-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val48-bit value to be added.

◆ net_buf_simple_add_le64()

void net_buf_simple_add_le64 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Add 64-bit value at the end of the buffer.

Adds 64-bit value in little endian format at the end of buffer. Increments the data length of a buffer to account for more data at the end.

Parameters
bufBuffer to update.
val64-bit value to be added.

◆ net_buf_simple_add_mem()

void * net_buf_simple_add_mem ( struct net_buf_simple buf,
const void *  mem,
size_t  len 
)

#include <zephyr/net/buf.h>

Copy given number of bytes from memory to the end of the buffer.

Increments the data length of the buffer to account for more data at the end.

Parameters
bufBuffer to update.
memLocation of data to be added.
lenLength of data to be added
Returns
The original tail of the buffer.

◆ net_buf_simple_add_u8()

uint8_t * net_buf_simple_add_u8 ( struct net_buf_simple buf,
uint8_t  val 
)

#include <zephyr/net/buf.h>

Add (8-bit) byte at the end of the buffer.

Increments the data length of the buffer to account for more data at the end.

Parameters
bufBuffer to update.
valbyte value to be added.
Returns
Pointer to the value added

◆ net_buf_simple_clone()

void net_buf_simple_clone ( const struct net_buf_simple original,
struct net_buf_simple clone 
)

#include <zephyr/net/buf.h>

Clone buffer state, using the same data buffer.

Initializes a buffer to point to the same data as an existing buffer. Allows operations on the same data without altering the length and offset of the original.

Parameters
originalBuffer to clone.
cloneThe new clone.

◆ net_buf_simple_headroom()

size_t net_buf_simple_headroom ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Check buffer headroom.

Check how much free space there is in the beginning of the buffer.

buf A valid pointer on a buffer

Returns
Number of bytes available in the beginning of the buffer.

◆ net_buf_simple_init()

static void net_buf_simple_init ( struct net_buf_simple buf,
size_t  reserve_head 
)
inlinestatic

#include <zephyr/net/buf.h>

Initialize a net_buf_simple object.

This needs to be called after creating a net_buf_simple object using the NET_BUF_SIMPLE macro.

Parameters
bufBuffer to initialize.
reserve_headHeadroom to reserve.

◆ net_buf_simple_init_with_data()

void net_buf_simple_init_with_data ( struct net_buf_simple buf,
void *  data,
size_t  size 
)

#include <zephyr/net/buf.h>

Initialize a net_buf_simple object with data.

Initialized buffer object with external data.

Parameters
bufBuffer to initialize.
dataExternal data pointer
sizeAmount of data the pointed data buffer if able to fit.

◆ net_buf_simple_max_len()

uint16_t net_buf_simple_max_len ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Check maximum net_buf_simple::len value.

This value is depending on the number of bytes being reserved as headroom.

Parameters
bufA valid pointer on a buffer
Returns
Number of bytes usable behind the net_buf_simple::data pointer.

◆ net_buf_simple_pull()

void * net_buf_simple_pull ( struct net_buf_simple buf,
size_t  len 
)

#include <zephyr/net/buf.h>

Remove data from the beginning of the buffer.

Removes data from the beginning of the buffer by modifying the data pointer and buffer length.

Parameters
bufBuffer to update.
lenNumber of bytes to remove.
Returns
New beginning of the buffer data.

◆ net_buf_simple_pull_be16()

uint16_t net_buf_simple_pull_be16 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 16-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from big endian to host endian.

◆ net_buf_simple_pull_be24()

uint32_t net_buf_simple_pull_be24 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 24-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from big endian to host endian.

◆ net_buf_simple_pull_be32()

uint32_t net_buf_simple_pull_be32 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 32-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
32-bit value converted from big endian to host endian.

◆ net_buf_simple_pull_be40()

uint64_t net_buf_simple_pull_be40 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 40-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
40-bit value converted from big endian to host endian.

◆ net_buf_simple_pull_be48()

uint64_t net_buf_simple_pull_be48 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 48-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
48-bit value converted from big endian to host endian.

◆ net_buf_simple_pull_be64()

uint64_t net_buf_simple_pull_be64 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 64-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
64-bit value converted from big endian to host endian.

◆ net_buf_simple_pull_le16()

uint16_t net_buf_simple_pull_le16 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 16-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from little endian to host endian.

◆ net_buf_simple_pull_le24()

uint32_t net_buf_simple_pull_le24 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 24-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from little endian to host endian.

◆ net_buf_simple_pull_le32()

uint32_t net_buf_simple_pull_le32 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 32-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
32-bit value converted from little endian to host endian.

◆ net_buf_simple_pull_le40()

uint64_t net_buf_simple_pull_le40 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 40-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
40-bit value converted from little endian to host endian.

◆ net_buf_simple_pull_le48()

uint64_t net_buf_simple_pull_le48 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 48-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
48-bit value converted from little endian to host endian.

◆ net_buf_simple_pull_le64()

uint64_t net_buf_simple_pull_le64 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 64-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
64-bit value converted from little endian to host endian.

◆ net_buf_simple_pull_mem()

void * net_buf_simple_pull_mem ( struct net_buf_simple buf,
size_t  len 
)

#include <zephyr/net/buf.h>

Remove data from the beginning of the buffer.

Removes data from the beginning of the buffer by modifying the data pointer and buffer length.

Parameters
bufBuffer to update.
lenNumber of bytes to remove.
Returns
Pointer to the old location of the buffer data.

◆ net_buf_simple_pull_u8()

uint8_t net_buf_simple_pull_u8 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove a 8-bit value from the beginning of the buffer.

Same idea as with net_buf_simple_pull(), but a helper for operating on 8-bit values.

Parameters
bufA valid pointer on a buffer.
Returns
The 8-bit removed value

◆ net_buf_simple_push()

void * net_buf_simple_push ( struct net_buf_simple buf,
size_t  len 
)

#include <zephyr/net/buf.h>

Prepare data to be added to the start of the buffer.

Modifies the data pointer and buffer length to account for more data in the beginning of the buffer.

Parameters
bufBuffer to update.
lenNumber of bytes to add to the beginning.
Returns
The new beginning of the buffer data.

◆ net_buf_simple_push_be16()

void net_buf_simple_push_be16 ( struct net_buf_simple buf,
uint16_t  val 
)

#include <zephyr/net/buf.h>

Push 16-bit value to the beginning of the buffer.

Adds 16-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val16-bit value to be pushed to the buffer.

◆ net_buf_simple_push_be24()

void net_buf_simple_push_be24 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Push 24-bit value to the beginning of the buffer.

Adds 24-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val24-bit value to be pushed to the buffer.

◆ net_buf_simple_push_be32()

void net_buf_simple_push_be32 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Push 32-bit value to the beginning of the buffer.

Adds 32-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val32-bit value to be pushed to the buffer.

◆ net_buf_simple_push_be40()

void net_buf_simple_push_be40 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Push 40-bit value to the beginning of the buffer.

Adds 40-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val40-bit value to be pushed to the buffer.

◆ net_buf_simple_push_be48()

void net_buf_simple_push_be48 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Push 48-bit value to the beginning of the buffer.

Adds 48-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val48-bit value to be pushed to the buffer.

◆ net_buf_simple_push_be64()

void net_buf_simple_push_be64 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Push 64-bit value to the beginning of the buffer.

Adds 64-bit value in big endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val64-bit value to be pushed to the buffer.

◆ net_buf_simple_push_le16()

void net_buf_simple_push_le16 ( struct net_buf_simple buf,
uint16_t  val 
)

#include <zephyr/net/buf.h>

Push 16-bit value to the beginning of the buffer.

Adds 16-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val16-bit value to be pushed to the buffer.

◆ net_buf_simple_push_le24()

void net_buf_simple_push_le24 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Push 24-bit value to the beginning of the buffer.

Adds 24-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val24-bit value to be pushed to the buffer.

◆ net_buf_simple_push_le32()

void net_buf_simple_push_le32 ( struct net_buf_simple buf,
uint32_t  val 
)

#include <zephyr/net/buf.h>

Push 32-bit value to the beginning of the buffer.

Adds 32-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val32-bit value to be pushed to the buffer.

◆ net_buf_simple_push_le40()

void net_buf_simple_push_le40 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Push 40-bit value to the beginning of the buffer.

Adds 40-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val40-bit value to be pushed to the buffer.

◆ net_buf_simple_push_le48()

void net_buf_simple_push_le48 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Push 48-bit value to the beginning of the buffer.

Adds 48-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val48-bit value to be pushed to the buffer.

◆ net_buf_simple_push_le64()

void net_buf_simple_push_le64 ( struct net_buf_simple buf,
uint64_t  val 
)

#include <zephyr/net/buf.h>

Push 64-bit value to the beginning of the buffer.

Adds 64-bit value in little endian format to the beginning of the buffer.

Parameters
bufBuffer to update.
val64-bit value to be pushed to the buffer.

◆ net_buf_simple_push_mem()

void * net_buf_simple_push_mem ( struct net_buf_simple buf,
const void *  mem,
size_t  len 
)

#include <zephyr/net/buf.h>

Copy given number of bytes from memory to the start of the buffer.

Modifies the data pointer and buffer length to account for more data in the beginning of the buffer.

Parameters
bufBuffer to update.
memLocation of data to be added.
lenLength of data to be added.
Returns
The new beginning of the buffer data.

◆ net_buf_simple_push_u8()

void net_buf_simple_push_u8 ( struct net_buf_simple buf,
uint8_t  val 
)

#include <zephyr/net/buf.h>

Push 8-bit value to the beginning of the buffer.

Adds 8-bit value the beginning of the buffer.

Parameters
bufBuffer to update.
val8-bit value to be pushed to the buffer.

◆ net_buf_simple_remove_be16()

uint16_t net_buf_simple_remove_be16 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 16-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from big endian to host endian.

◆ net_buf_simple_remove_be24()

uint32_t net_buf_simple_remove_be24 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 24-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from big endian to host endian.

◆ net_buf_simple_remove_be32()

uint32_t net_buf_simple_remove_be32 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 32-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
32-bit value converted from big endian to host endian.

◆ net_buf_simple_remove_be40()

uint64_t net_buf_simple_remove_be40 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 40-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
40-bit value converted from big endian to host endian.

◆ net_buf_simple_remove_be48()

uint64_t net_buf_simple_remove_be48 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 48-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
48-bit value converted from big endian to host endian.

◆ net_buf_simple_remove_be64()

uint64_t net_buf_simple_remove_be64 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 64-bit big endian data.

Parameters
bufA valid pointer on a buffer.
Returns
64-bit value converted from big endian to host endian.

◆ net_buf_simple_remove_le16()

uint16_t net_buf_simple_remove_le16 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 16 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 16-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
16-bit value converted from little endian to host endian.

◆ net_buf_simple_remove_le24()

uint32_t net_buf_simple_remove_le24 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 24 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 24-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
24-bit value converted from little endian to host endian.

◆ net_buf_simple_remove_le32()

uint32_t net_buf_simple_remove_le32 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 32 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 32-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
32-bit value converted from little endian to host endian.

◆ net_buf_simple_remove_le40()

uint64_t net_buf_simple_remove_le40 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 40 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 40-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
40-bit value converted from little endian to host endian.

◆ net_buf_simple_remove_le48()

uint64_t net_buf_simple_remove_le48 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 48 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 48-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
48-bit value converted from little endian to host endian.

◆ net_buf_simple_remove_le64()

uint64_t net_buf_simple_remove_le64 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove and convert 64 bits from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 64-bit little endian data.

Parameters
bufA valid pointer on a buffer.
Returns
64-bit value converted from little endian to host endian.

◆ net_buf_simple_remove_mem()

void * net_buf_simple_remove_mem ( struct net_buf_simple buf,
size_t  len 
)

#include <zephyr/net/buf.h>

Remove data from the end of the buffer.

Removes data from the end of the buffer by modifying the buffer length.

Parameters
bufBuffer to update.
lenNumber of bytes to remove.
Returns
New end of the buffer data.

◆ net_buf_simple_remove_u8()

uint8_t net_buf_simple_remove_u8 ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Remove a 8-bit value from the end of the buffer.

Same idea as with net_buf_simple_remove_mem(), but a helper for operating on 8-bit values.

Parameters
bufA valid pointer on a buffer.
Returns
The 8-bit removed value

◆ net_buf_simple_reserve()

void net_buf_simple_reserve ( struct net_buf_simple buf,
size_t  reserve 
)

#include <zephyr/net/buf.h>

Initialize buffer with the given headroom.

The buffer is not expected to contain any data when this API is called.

Parameters
bufBuffer to initialize.
reserveHow much headroom to reserve.

◆ net_buf_simple_reset()

static void net_buf_simple_reset ( struct net_buf_simple buf)
inlinestatic

#include <zephyr/net/buf.h>

Reset buffer.

Reset buffer data so it can be reused for other purposes.

Parameters
bufBuffer to reset.

◆ net_buf_simple_restore()

static void net_buf_simple_restore ( struct net_buf_simple buf,
struct net_buf_simple_state state 
)
inlinestatic

#include <zephyr/net/buf.h>

Restore the parsing state of a buffer.

Restores the parsing state of a buffer from a state previously stored by net_buf_simple_save().

Parameters
bufBuffer to which the state should be restored.
stateStored state.

◆ net_buf_simple_save()

static void net_buf_simple_save ( struct net_buf_simple buf,
struct net_buf_simple_state state 
)
inlinestatic

#include <zephyr/net/buf.h>

Save the parsing state of a buffer.

Saves the parsing state of a buffer so it can be restored later.

Parameters
bufBuffer from which the state should be saved.
stateStorage for the state.

◆ net_buf_simple_tail()

static uint8_t * net_buf_simple_tail ( struct net_buf_simple buf)
inlinestatic

#include <zephyr/net/buf.h>

Get the tail pointer for a buffer.

Get a pointer to the end of the data in a buffer.

Parameters
bufBuffer.
Returns
Tail pointer for the buffer.

◆ net_buf_simple_tailroom()

size_t net_buf_simple_tailroom ( struct net_buf_simple buf)

#include <zephyr/net/buf.h>

Check buffer tailroom.

Check how much free space there is at the end of the buffer.

Parameters
bufA valid pointer on a buffer
Returns
Number of bytes available at the end of the buffer.

◆ net_buf_skip()

static struct net_buf * net_buf_skip ( struct net_buf buf,
size_t  len 
)
inlinestatic

#include <zephyr/net/buf.h>

Skip N number of bytes in a net_buf.

Skip N number of bytes starting from fragment's offset. If the total length of data is placed in multiple fragments, this function will skip from all fragments until it reaches N number of bytes. Any fully skipped buffers are removed from the net_buf list.

Parameters
bufNetwork buffer.
lenTotal length of data to be skipped.
Returns
Pointer to the fragment or NULL and pos is 0 after successful skip, NULL and pos is 0xffff otherwise.

◆ net_buf_slist_get()

struct net_buf * net_buf_slist_get ( sys_slist_t list)

#include <zephyr/net/buf.h>

Get a buffer from a list.

If the buffer had any fragments, these will automatically be recovered from the list as well and be placed to the buffer's fragment list.

Parameters
listWhich list to take the buffer from.
Returns
New buffer or NULL if the FIFO is empty.

◆ net_buf_slist_put()

void net_buf_slist_put ( sys_slist_t list,
struct net_buf buf 
)

#include <zephyr/net/buf.h>

Put a buffer into a list.

If the buffer contains follow-up fragments this function will take care of inserting them as well into the list.

Parameters
listWhich list to append the buffer to.
bufBuffer.

◆ net_buf_tail()

static uint8_t * net_buf_tail ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Get the tail pointer for a buffer.

Get a pointer to the end of the data in a buffer.

Parameters
bufBuffer.
Returns
Tail pointer for the buffer.

◆ net_buf_tailroom()

static size_t net_buf_tailroom ( struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Check buffer tailroom.

Check how much free space there is at the end of the buffer.

Parameters
bufA valid pointer on a buffer
Returns
Number of bytes available at the end of the buffer.

◆ net_buf_unref()

void net_buf_unref ( struct net_buf buf)

#include <zephyr/net/buf.h>

Decrements the reference count of a buffer.

The buffer is put back into the pool if the reference count reaches zero.

Parameters
bufA valid pointer on a buffer

◆ net_buf_user_data()

static void * net_buf_user_data ( const struct net_buf buf)
inlinestatic

#include <zephyr/net/buf.h>

Get a pointer to the user data of a buffer.

Parameters
bufA valid pointer on a buffer
Returns
Pointer to the user data of the buffer.

◆ net_buf_user_data_copy()

int net_buf_user_data_copy ( struct net_buf dst,
const struct net_buf src 
)

#include <zephyr/net/buf.h>

Copy user data from one to another buffer.

Parameters
dstA valid pointer to a buffer gettings its user data overwritten.
srcA valid pointer to a buffer gettings its user data copied. User data size must be equal to or exceed dst.
Returns
0 on success or negative error number on failure.