Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_buf.h File Reference

Buffer management. More...

#include <stddef.h>
#include <zephyr/types.h>
#include <zephyr/sys/util.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/iterable_sections.h>

Go to the source code of this file.

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_pool
 Network buffer pool representation. More...
 

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)
 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 (const struct net_buf_simple *buf)
 Get the tail pointer for a buffer.
 
size_t net_buf_simple_headroom (const struct net_buf_simple *buf)
 Check buffer headroom.
 
size_t net_buf_simple_tailroom (const struct net_buf_simple *buf)
 Check buffer tailroom.
 
uint16_t net_buf_simple_max_len (const struct net_buf_simple *buf)
 Check maximum net_buf_simple::len value.
 
static void net_buf_simple_save (const 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 (const 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 (const struct net_buf *buf)
 Check buffer tailroom.
 
static size_t net_buf_headroom (const struct net_buf *buf)
 Check buffer headroom.
 
static uint16_t net_buf_max_len (const struct net_buf *buf)
 Check maximum net_buf::len value.
 
static uint8_tnet_buf_tail (const 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, const 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 (const struct net_buf *buf)
 Calculate amount of bytes stored in fragments.
 

Detailed Description

Buffer management.