ConOpSys V2970  P004.07
ANVILEX control operating system
Classes | Macros | Enumerations | Functions
pbuf.h File Reference
#include "lwip/opt.h"
#include "lwip/err.h"
Include dependency graph for pbuf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pbuf
 
struct  pbuf_rom
 

Macros

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
 
#define PBUF_NEEDS_COPY(p)   ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)
 
#define PBUF_TRANSPORT_HLEN   20
 
#define PBUF_IP_HLEN   20
 
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS   0x80
 
#define PBUF_TYPE_FLAG_DATA_VOLATILE   0x40
 
#define PBUF_TYPE_ALLOC_SRC_MASK   0x0F
 
#define PBUF_ALLOC_FLAG_RX   0x0100
 
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS   0x0200
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP   0x00
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF   0x01
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL   0x02
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX   PBUF_TYPE_ALLOC_SRC_MASK
 
#define PBUF_FLAG_PUSH   0x01U
 
#define PBUF_FLAG_IS_CUSTOM   0x02U
 
#define PBUF_FLAG_MCASTLOOP   0x04U
 
#define PBUF_FLAG_LLBCAST   0x08U
 
#define PBUF_FLAG_LLMCAST   0x10U
 
#define PBUF_FLAG_TCP_FIN   0x20U
 
#define PBUF_POOL_FREE_OOSEQ   1
 
#define PBUF_CHECK_FREE_OOSEQ()
 
#define pbuf_init()
 
#define pbuf_get_allocsrc(p)   ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK)
 
#define pbuf_match_allocsrc(p, type)   (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK))
 
#define pbuf_match_type(p, type)   pbuf_match_allocsrc(p, type)
 

Enumerations

enum  pbuf_layer {
  PBUF_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN , PBUF_IP = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN , PBUF_LINK = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN , PBUF_RAW_TX = PBUF_LINK_ENCAPSULATION_HLEN ,
  PBUF_RAW = 0
}
 
enum  pbuf_type { PBUF_RAM = (PBUF_ALLOC_FLAG_DATA_CONTIGUOUS | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP) , PBUF_ROM = PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF , PBUF_REF = (PBUF_TYPE_FLAG_DATA_VOLATILE | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF) , PBUF_POOL = (PBUF_ALLOC_FLAG_RX | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL) }
 

Functions

struct pbufpbuf_alloc (pbuf_layer l, u16_t length, pbuf_type type)
 
struct pbufpbuf_alloc_reference (void *payload, u16_t length, pbuf_type type)
 
void pbuf_realloc (struct pbuf *p, u16_t size)
 
u8_t pbuf_header (struct pbuf *p, s16_t header_size)
 
u8_t pbuf_header_force (struct pbuf *p, s16_t header_size)
 
u8_t pbuf_add_header (struct pbuf *p, size_t header_size_increment)
 
u8_t pbuf_add_header_force (struct pbuf *p, size_t header_size_increment)
 
u8_t pbuf_remove_header (struct pbuf *p, size_t header_size)
 
struct pbufpbuf_free_header (struct pbuf *q, u16_t size)
 
void pbuf_ref (struct pbuf *p)
 
u8_t pbuf_free (struct pbuf *p)
 
u16_t pbuf_clen (const struct pbuf *p)
 
void pbuf_cat (struct pbuf *head, struct pbuf *tail)
 
void pbuf_chain (struct pbuf *head, struct pbuf *tail)
 
struct pbufpbuf_dechain (struct pbuf *p)
 
err_t pbuf_copy (struct pbuf *p_to, const struct pbuf *p_from)
 
u16_t pbuf_copy_partial (const struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
 
void * pbuf_get_contiguous (const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset)
 
err_t pbuf_take (struct pbuf *buf, const void *dataptr, u16_t len)
 
err_t pbuf_take_at (struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
 
struct pbufpbuf_skip (struct pbuf *in, u16_t in_offset, u16_t *out_offset)
 
struct pbufpbuf_coalesce (struct pbuf *p, pbuf_layer layer)
 
struct pbufpbuf_clone (pbuf_layer l, pbuf_type type, struct pbuf *p)
 
u8_t pbuf_get_at (const struct pbuf *p, u16_t offset)
 
int pbuf_try_get_at (const struct pbuf *p, u16_t offset)
 
void pbuf_put_at (struct pbuf *p, u16_t offset, u8_t data)
 
u16_t pbuf_memcmp (const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
 
u16_t pbuf_memfind (const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
 
u16_t pbuf_strstr (const struct pbuf *p, const char *substr)
 

Detailed Description

pbuf API

Macro Definition Documentation

◆ LWIP_SUPPORT_CUSTOM_PBUF

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))

LWIP_SUPPORT_CUSTOM_PBUF==1: Custom pbufs behave much like their pbuf type but they are allocated by external code (initialised by calling pbuf_alloced_custom()) and when pbuf_free gives up their last reference, they are freed by calling pbuf_custom->custom_free_function(). Currently, the pbuf_custom code is only needed for one specific configuration of IP_FRAG, unless required by external driver/application code.

◆ PBUF_ALLOC_FLAG_DATA_CONTIGUOUS

#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS   0x0200

Indicates the application needs the pbuf payload to be in one piece

◆ PBUF_ALLOC_FLAG_RX

#define PBUF_ALLOC_FLAG_RX   0x0100

Indicates this pbuf is used for RX (if not set, indicates use for TX). This information can be used to keep some spare RX buffers e.g. for receiving TCP ACKs to unblock a connection)

◆ PBUF_CHECK_FREE_OOSEQ

#define PBUF_CHECK_FREE_OOSEQ ( )

◆ PBUF_FLAG_IS_CUSTOM

#define PBUF_FLAG_IS_CUSTOM   0x02U

indicates this is a custom pbuf: pbuf_free calls pbuf_custom->custom_free_function() when the last reference is released (plus custom PBUF_RAM cannot be trimmed)

◆ PBUF_FLAG_LLBCAST

#define PBUF_FLAG_LLBCAST   0x08U

indicates this pbuf was received as link-level broadcast

◆ PBUF_FLAG_LLMCAST

#define PBUF_FLAG_LLMCAST   0x10U

indicates this pbuf was received as link-level multicast

◆ PBUF_FLAG_MCASTLOOP

#define PBUF_FLAG_MCASTLOOP   0x04U

indicates this pbuf is UDP multicast to be looped back

◆ PBUF_FLAG_PUSH

#define PBUF_FLAG_PUSH   0x01U

indicates this packet's data should be immediately passed to the application

◆ PBUF_FLAG_TCP_FIN

#define PBUF_FLAG_TCP_FIN   0x20U

indicates this pbuf includes a TCP FIN flag

◆ pbuf_get_allocsrc

#define pbuf_get_allocsrc (   p)    ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK)

◆ pbuf_init

#define pbuf_init ( )

◆ PBUF_IP_HLEN

#define PBUF_IP_HLEN   20

◆ pbuf_match_allocsrc

#define pbuf_match_allocsrc (   p,
  type 
)    (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK))

◆ pbuf_match_type

#define pbuf_match_type (   p,
  type 
)    pbuf_match_allocsrc(p, type)

◆ PBUF_POOL_FREE_OOSEQ

#define PBUF_POOL_FREE_OOSEQ   1

Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty

◆ PBUF_TRANSPORT_HLEN

#define PBUF_TRANSPORT_HLEN   20

◆ PBUF_TYPE_ALLOC_SRC_MASK

#define PBUF_TYPE_ALLOC_SRC_MASK   0x0F

4 bits are reserved for 16 allocation sources (e.g. heap, pool1, pool2, etc) Internally, we use: 0=heap, 1=MEMP_PBUF, 2=MEMP_PBUF_POOL -> 13 types free

◆ PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX

#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX   PBUF_TYPE_ALLOC_SRC_MASK

Last pbuf allocation type for applications

◆ PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN

#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03

First pbuf allocation type for applications

◆ PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP

#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP   0x00

◆ PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF

#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF   0x01

◆ PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL

#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL   0x02

◆ PBUF_TYPE_FLAG_DATA_VOLATILE

#define PBUF_TYPE_FLAG_DATA_VOLATILE   0x40

Indicates the data stored in this pbuf can change. If this pbuf needs to be queued, it must be copied/duplicated.

◆ PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS

#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS   0x80

Indicates that the payload directly follows the struct pbuf. This makes pbuf_header work in both directions.

Function Documentation

◆ pbuf_add_header()

u8_t pbuf_add_header ( struct pbuf p,
size_t  header_size_increment 
)

Adjusts the payload pointer to reveal headers in the payload.

Adjusts the ->payload pointer so that space for a header appears in the pbuf payload.

The ->payload, ->tot_len and ->len fields are adjusted.

Parameters
ppbuf to change the header size.
header_size_incrementNumber of bytes to increment header size which increases the size of the pbuf. New space is on the front. If header_size_increment is 0, this function does nothing and returns successful.

PBUF_ROM and PBUF_REF type buffers cannot have their sizes increased, so the call will fail. A check is made that the increase in header size does not move the payload pointer in front of the start of the buffer.

Returns
non-zero on failure, zero on success.

References pbuf_add_header_impl().

Here is the call graph for this function:

◆ pbuf_add_header_force()

u8_t pbuf_add_header_force ( struct pbuf p,
size_t  header_size_increment 
)

Same as pbuf_add_header but does not check if 'header_size > 0' is allowed. This is used internally only, to allow PBUF_REF for RX.

References pbuf_add_header_impl().

Here is the call graph for this function:

◆ pbuf_clen()

u16_t pbuf_clen ( const struct pbuf p)

Count number of pbufs in a chain

Parameters
pfirst pbuf of chain
Returns
the number of pbufs in a chain

References pbuf::next, and NULL.

◆ pbuf_dechain()

struct pbuf* pbuf_dechain ( struct pbuf p)

Dechains the first pbuf from its succeeding pbufs in the chain.

Makes p->tot_len field equal to p->len.

Parameters
ppbuf to dechain
Returns
remainder of the pbuf chain, or NULL if it was de-allocated.
Note
May not be called on a packet queue.

References pbuf::len, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, pbuf::next, NULL, PBUF_DEBUG, pbuf_free(), and pbuf::tot_len.

Here is the call graph for this function:

◆ pbuf_free_header()

struct pbuf* pbuf_free_header ( struct pbuf q,
u16_t  size 
)

Similar to pbuf_header(-size) but de-refs header pbufs for (size >= p->len)

Parameters
qpbufs to operate on
sizeThe number of bytes to remove from the beginning of the pbuf list. While size >= p->len, pbufs are freed. ATTENTION: this is the opposite direction as pbuf_header, but takes an u16_t not s16_t!
Returns
the new head pbuf

References pbuf::len, pbuf::next, pbuf_free(), and pbuf_remove_header().

Here is the call graph for this function:

◆ pbuf_header()

u8_t pbuf_header ( struct pbuf p,
s16_t  header_size_increment 
)

Adjusts the payload pointer to hide or reveal headers in the payload.

Adjusts the ->payload pointer so that space for a header (dis)appears in the pbuf payload.

The ->payload, ->tot_len and ->len fields are adjusted.

Parameters
ppbuf to change the header size.
header_size_incrementNumber of bytes to increment header size which increases the size of the pbuf. New space is on the front. (Using a negative value decreases the header size.) If header_size_increment is 0, this function does nothing and returns successful.

PBUF_ROM and PBUF_REF type buffers cannot have their sizes increased, so the call will fail. A check is made that the increase in header size does not move the payload pointer in front of the start of the buffer.

Returns
non-zero on failure, zero on success.

References pbuf_header_impl().

Here is the call graph for this function:

◆ pbuf_header_force()

u8_t pbuf_header_force ( struct pbuf p,
s16_t  header_size_increment 
)

Same as pbuf_header but does not check if 'header_size > 0' is allowed. This is used internally only, to allow PBUF_REF for RX.

References pbuf_header_impl().

Here is the call graph for this function:

◆ pbuf_remove_header()

u8_t pbuf_remove_header ( struct pbuf p,
size_t  header_size_decrement 
)

Adjusts the payload pointer to hide headers in the payload.

Adjusts the ->payload pointer so that space for a header disappears in the pbuf payload.

The ->payload, ->tot_len and ->len fields are adjusted.

Parameters
ppbuf to change the header size.
header_size_decrementNumber of bytes to decrement header size which decreases the size of the pbuf. If header_size_decrement is 0, this function does nothing and returns successful.
Returns
non-zero on failure, zero on success.

References pbuf::len, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR, LWIP_UNUSED_ARG, NULL, pbuf::payload, PBUF_DEBUG, pbuf::tot_len, and U16_F.

Referenced by pbuf_free_header(), and pbuf_header_impl().

Here is the caller graph for this function:

◆ pbuf_strstr()

u16_t pbuf_strstr ( const struct pbuf p,
const char *  substr 
)

Find occurrence of substr with length substr_len in pbuf p, start at offset start_offset WARNING: in contrast to strstr(), this one does not stop at the first \0 in the pbuf/source string!

Parameters
ppbuf to search, maximum length is 0xFFFE since 0xFFFF is used as return value 'not found'
substrstring to search for in p, maximum length is 0xFFFE
Returns
0xFFFF if substr was not found in p or the index where it was found

References NULL, pbuf_memfind(), and pbuf::tot_len.

Here is the call graph for this function: