STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
Data Structures | Macros | Enumerations | Functions
pbuf.h File Reference
#include "lwip/opt.h"
#include "lwip/err.h"

Go to the source code of this file.

Data Structures

struct  pbuf
 
struct  pbuf_rom
 

Macros

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
 
#define PBUF_TRANSPORT_HLEN   20
 
#define PBUF_IP_HLEN   20
 
#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_init()
 

Enumerations

enum  pbuf_layer {
  PBUF_TRANSPORT, PBUF_IP, PBUF_LINK, PBUF_RAW_TX,
  PBUF_RAW
}
 
enum  pbuf_type { PBUF_RAM, PBUF_ROM, PBUF_REF, PBUF_POOL }
 

Functions

struct pbufpbuf_alloc (pbuf_layer l, 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)
 
void pbuf_ref (struct pbuf *p)
 
u8_t pbuf_free (struct pbuf *p)
 
u8_t pbuf_clen (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, struct pbuf *p_from)
 
u16_t pbuf_copy_partial (struct pbuf *p, void *dataptr, 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)
 
u8_t pbuf_get_at (struct pbuf *p, u16_t offset)
 
void pbuf_put_at (struct pbuf *p, u16_t offset, u8_t data)
 
u16_t pbuf_memcmp (struct pbuf *p, u16_t offset, const void *s2, u16_t n)
 
u16_t pbuf_memfind (struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
 
u16_t pbuf_strstr (struct pbuf *p, const char *substr)
 

Macro Definition Documentation

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !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.

Definition at line 50 of file pbuf.h.

#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)

Definition at line 98 of file pbuf.h.

#define PBUF_FLAG_LLBCAST   0x08U

indicates this pbuf was received as link-level broadcast

Definition at line 102 of file pbuf.h.

#define PBUF_FLAG_LLMCAST   0x10U

indicates this pbuf was received as link-level multicast

Definition at line 104 of file pbuf.h.

#define PBUF_FLAG_MCASTLOOP   0x04U

indicates this pbuf is UDP multicast to be looped back

Definition at line 100 of file pbuf.h.

#define PBUF_FLAG_PUSH   0x01U

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

Definition at line 95 of file pbuf.h.

#define PBUF_FLAG_TCP_FIN   0x20U

indicates this pbuf includes a TCP FIN flag

Definition at line 106 of file pbuf.h.

#define pbuf_init ( )

Definition at line 186 of file pbuf.h.

#define PBUF_IP_HLEN   20

Definition at line 60 of file pbuf.h.

#define PBUF_TRANSPORT_HLEN   20

Definition at line 56 of file pbuf.h.

Enumeration Type Documentation

enum pbuf_layer
Enumerator
PBUF_TRANSPORT 
PBUF_IP 
PBUF_LINK 
PBUF_RAW_TX 
PBUF_RAW 

Definition at line 63 of file pbuf.h.

enum pbuf_type
Enumerator
PBUF_RAM 

pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload are allocated in one piece of contiguous memory (so the first payload byte can be calculated from struct pbuf) pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might change in future versions)

PBUF_ROM 

pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in totally different memory areas. Since it points to ROM, payload does not have to be copied when queued for transmission.

PBUF_REF 

pbuf comes from the pbuf pool. Much like PBUF_ROM but payload might change so it has to be duplicated when queued before transmitting, depending on who has a 'ref' to it.

PBUF_POOL 

pbuf payload refers to RAM. This one comes from a pool and should be used for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct pbuf and its payload are allocated in one piece of contiguous memory (so the first payload byte can be calculated from struct pbuf)

Definition at line 71 of file pbuf.h.

Function Documentation

struct pbuf* pbuf_alloc ( pbuf_layer  layer,
u16_t  length,
pbuf_type  type 
)

Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).

The actual memory allocated for the pbuf is determined by the layer at which the pbuf is allocated and the requested size (from the size parameter).

Parameters
layerflag to define header size
lengthsize of the pbuf's payload
typethis parameter decides how and where the pbuf should be allocated as follows:
  • PBUF_RAM: buffer memory for pbuf is allocated as one large chunk. This includes protocol headers as well.
  • PBUF_ROM: no buffer memory is allocated for the pbuf, even for protocol headers. Additional headers must be prepended by allocating another pbuf and chain in to the front of the ROM pbuf. It is assumed that the memory used is really similar to ROM in that it is immutable and will not be changed. Memory which is dynamic should generally not be attached to PBUF_ROM pbufs. Use PBUF_REF instead.
  • PBUF_REF: no buffer memory is allocated for the pbuf, even for protocol headers. It is assumed that the pbuf is only being used in a single thread. If the pbuf gets queued, then pbuf_take should be called to copy the buffer.
  • PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from the pbuf pool that is allocated during pbuf_init().
Returns
the allocated pbuf. If multiple pbufs where allocated, this is the first pbuf of a pbuf chain.

Definition at line 199 of file pbuf.c.

void pbuf_cat ( struct pbuf h,
struct pbuf t 
)

Concatenate two pbufs (each may be a pbuf chain) and take over the caller's reference of the tail pbuf.

Note
The caller MAY NOT reference the tail pbuf afterwards. Use pbuf_chain() for that purpose.
See also
pbuf_chain()

Definition at line 779 of file pbuf.c.

void pbuf_chain ( struct pbuf h,
struct pbuf t 
)

Chain two pbufs (or pbuf chains) together.

The caller MUST call pbuf_free(t) once it has stopped using it. Use pbuf_cat() instead if you no longer use t.

Parameters
hhead pbuf (chain)
ttail pbuf (chain)
Note
The pbufs MUST belong to the same packet.
MAY NOT be called on a packet queue.

The ->tot_len fields of all pbufs of the head chain are adjusted. The ->next field of the last pbuf of the head chain is adjusted. The ->ref field of the first pbuf of the tail chain is adjusted.

Definition at line 820 of file pbuf.c.

u8_t pbuf_clen ( struct pbuf p)

Count number of pbufs in a chain

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

Definition at line 738 of file pbuf.c.

struct pbuf* pbuf_coalesce ( struct pbuf p,
pbuf_layer  layer 
)

Creates a single pbuf out of a queue of pbufs.

Remarks
: Either the source pbuf 'p' is freed by this function or the original pbuf 'p' is returned, therefore the caller has to check the result!
Parameters
pthe source pbuf
layerpbuf_layer of the new pbuf
Returns
a new, single pbuf (p->next is NULL) or the old pbuf if allocation fails

Definition at line 1152 of file pbuf.c.

err_t pbuf_copy ( struct pbuf p_to,
struct pbuf p_from 
)

Create PBUF_RAM copies of pbufs.

Used to queue packets on behalf of the lwIP stack, such as ARP based queueing.

Note
You MUST explicitly use p = pbuf_take(p);
Only one packet is copied, no packet queue!
Parameters
p_topbuf destination of the copy
p_frompbuf source of the copy
Returns
ERR_OK if pbuf was copied ERR_ARG if one of the pbufs is NULL or p_to is not big enough to hold p_from

Definition at line 886 of file pbuf.c.

u16_t pbuf_copy_partial ( struct pbuf buf,
void *  dataptr,
u16_t  len,
u16_t  offset 
)

Copy (part of) the contents of a packet buffer to an application supplied buffer.

Parameters
bufthe pbuf from which to copy data
dataptrthe application supplied buffer
lenlength of data to copy (dataptr must be big enough). No more than buf->tot_len will be copied, irrespective of len
offsetoffset into the packet buffer from where to begin copying len bytes
Returns
the number of bytes copied, or 0 on failure

Definition at line 952 of file pbuf.c.

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.

Definition at line 837 of file pbuf.c.

u8_t pbuf_free ( struct pbuf p)

Dereference a pbuf chain or queue and deallocate any no-longer-used pbufs at the head of this chain or queue.

Decrements the pbuf reference count. If it reaches zero, the pbuf is deallocated.

For a pbuf chain, this is repeated for each pbuf in the chain, up to the first pbuf which has a non-zero reference count after decrementing. So, when all reference counts are one, the whole chain is free'd.

Parameters
pThe pbuf (chain) to be dereferenced.
Returns
the number of pbufs that were de-allocated from the head of the chain.
Note
MUST NOT be called on a packet queue (Not verified to work yet).
the reference counter of a pbuf equals the number of pointers that refer to the pbuf (or into the pbuf).

Definition at line 652 of file pbuf.c.

u8_t pbuf_get_at ( struct pbuf p,
u16_t  offset 
)

Get one byte from the specified position in a pbuf WARNING: returns zero for offset >= p->tot_len

Parameters
ppbuf to parse
offsetoffset into p of the byte to return
Returns
byte at an offset into p OR ZERO IF 'offset' >= p->tot_len

Definition at line 1219 of file pbuf.c.

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 hdr_size_inc 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.

Definition at line 603 of file pbuf.c.

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.

Definition at line 613 of file pbuf.c.

u16_t pbuf_memcmp ( struct pbuf p,
u16_t  offset,
const void *  s2,
u16_t  n 
)

Compare pbuf contents at specified offset with memory s2, both of length n

Parameters
ppbuf to compare
offsetoffset into p at which to start comparing
s2buffer to compare
nlength of buffer to compare
Returns
zero if equal, nonzero otherwise (0xffff if p is too short, diffoffset+1 otherwise)

Definition at line 1260 of file pbuf.c.

u16_t pbuf_memfind ( struct pbuf p,
const void *  mem,
u16_t  mem_len,
u16_t  start_offset 
)

Find occurrence of mem (with length mem_len) in pbuf p, starting at offset start_offset.

Parameters
ppbuf to search, maximum length is 0xFFFE since 0xFFFF is used as return value 'not found'
memsearch for the contents of this buffer
mem_lenlength of 'mem'
start_offsetoffset into p at which to start searching
Returns
0xFFFF if substr was not found in p or the index where it was found

Definition at line 1296 of file pbuf.c.

void pbuf_put_at ( struct pbuf p,
u16_t  offset,
u8_t  data 
)

Put one byte to the specified position in a pbuf WARNING: silently ignores offset >= p->tot_len

Parameters
ppbuf to fill
offsetoffset into p of the byte to write
databyte to write at an offset into p

Definition at line 1239 of file pbuf.c.

void pbuf_realloc ( struct pbuf p,
u16_t  new_len 
)

Shrink a pbuf chain to a desired length.

Parameters
ppbuf to shrink.
new_lendesired new length of pbuf chain

Depending on the desired length, the first few pbufs in a chain might be skipped and left unchanged. The new last pbuf in the chain will be resized, and any remaining pbufs will be freed.

Note
If the pbuf is ROM/REF, only the ->tot_len and ->len fields are adjusted.
May not be called on a packet queue.
Despite its name, pbuf_realloc cannot grow the size of a pbuf (chain).

Definition at line 431 of file pbuf.c.

void pbuf_ref ( struct pbuf p)

Increment the reference count of the pbuf.

Parameters
ppbuf to increase reference counter of

Definition at line 757 of file pbuf.c.

struct pbuf* pbuf_skip ( struct pbuf in,
u16_t  in_offset,
u16_t out_offset 
)

Skip a number of bytes at the start of a pbuf

Parameters
ininput pbuf
in_offsetoffset to skip
out_offsetresulting offset in the returned pbuf
Returns
the pbuf in the queue where the offset is

Definition at line 1048 of file pbuf.c.

u16_t pbuf_strstr ( 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

Definition at line 1322 of file pbuf.c.

err_t pbuf_take ( struct pbuf buf,
const void *  dataptr,
u16_t  len 
)

Copy application supplied data into a pbuf. This function can only be used to copy the equivalent of buf->tot_len data.

Parameters
bufpbuf to fill with data
dataptrapplication supplied data buffer
lenlength of the application supplied data buffer
Returns
ERR_OK if successful, ERR_MEM if the pbuf is not big enough

Definition at line 1075 of file pbuf.c.

err_t pbuf_take_at ( struct pbuf buf,
const void *  dataptr,
u16_t  len,
u16_t  offset 
)

Same as pbuf_take() but puts data at an offset

Parameters
bufpbuf to fill with data
dataptrapplication supplied data buffer
lenlength of the application supplied data buffer
Returns
ERR_OK if successful, ERR_MEM if the pbuf is not big enough

Definition at line 1117 of file pbuf.c.