Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
pbuf.h File Reference
pbuf API More...
Go to the source code of this file.
Data Structures | |
struct | pbuf |
Main packet buffer struct. More... | |
struct | pbuf_rom |
Helper struct for const-correctness only. More... | |
struct | pbuf_custom |
A custom pbuf: like a pbuf, but following a function pointer to free it. More... | |
Typedefs | |
typedef void(* | pbuf_free_custom_fn )(struct pbuf *p) |
Prototype for a function to free a custom pbuf. | |
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 } |
Enumeration of pbuf layers. More... | |
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) } |
Enumeration of pbuf types. More... | |
Functions | |
struct pbuf * | pbuf_alloc (pbuf_layer l, u16_t length, pbuf_type type) |
Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type). | |
struct pbuf * | pbuf_alloc_reference (void *payload, u16_t length, pbuf_type type) |
Allocates a pbuf for referenced data. | |
struct pbuf * | pbuf_alloced_custom (pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p, void *payload_mem, u16_t payload_mem_len) |
Initialize a custom pbuf (already allocated). | |
void | pbuf_realloc (struct pbuf *p, u16_t size) |
Shrink a pbuf chain to a desired length. | |
u8_t | pbuf_header (struct pbuf *p, s16_t header_size) |
Adjusts the payload pointer to hide or reveal headers in the payload. | |
u8_t | pbuf_header_force (struct pbuf *p, s16_t header_size) |
Same as pbuf_header but does not check if 'header_size > 0' is allowed. | |
u8_t | pbuf_add_header (struct pbuf *p, size_t header_size_increment) |
Adjusts the payload pointer to reveal headers in the payload. | |
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. | |
u8_t | pbuf_remove_header (struct pbuf *p, size_t header_size) |
Adjusts the payload pointer to hide headers in the payload. | |
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) | |
void | pbuf_ref (struct pbuf *p) |
Increment the reference count of the pbuf. | |
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. | |
u16_t | pbuf_clen (const struct pbuf *p) |
Count number of pbufs in a chain. | |
void | pbuf_cat (struct pbuf *head, struct pbuf *tail) |
Concatenate two pbufs (each may be a pbuf chain) and take over the caller's reference of the tail pbuf. | |
void | pbuf_chain (struct pbuf *head, struct pbuf *tail) |
Chain two pbufs (or pbuf chains) together. | |
struct pbuf * | pbuf_dechain (struct pbuf *p) |
Dechains the first pbuf from its succeeding pbufs in the chain. | |
err_t | pbuf_copy (struct pbuf *p_to, const struct pbuf *p_from) |
Create PBUF_RAM copies of pbufs. | |
u16_t | pbuf_copy_partial (const struct pbuf *p, void *dataptr, u16_t len, u16_t offset) |
Copy (part of) the contents of a packet buffer to an application supplied buffer. | |
void * | pbuf_get_contiguous (const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset) |
Get part of a pbuf's payload as contiguous memory. | |
err_t | pbuf_take (struct pbuf *buf, const void *dataptr, u16_t len) |
Copy application supplied data into a pbuf. | |
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. | |
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. | |
struct pbuf * | pbuf_coalesce (struct pbuf *p, pbuf_layer layer) |
Creates a single pbuf out of a queue of pbufs. | |
struct pbuf * | pbuf_clone (pbuf_layer l, pbuf_type type, struct pbuf *p) |
Allocates a new pbuf of same length (via pbuf_alloc()) and copies the source pbuf into this new pbuf (using pbuf_copy()). | |
err_t | pbuf_fill_chksum (struct pbuf *p, u16_t start_offset, const void *dataptr, u16_t len, u16_t *chksum) |
Copies data into a single pbuf (*not* into a pbuf queue!) and updates the checksum while copying. | |
void | pbuf_split_64k (struct pbuf *p, struct pbuf **rest) |
This method modifies a 'pbuf chain', so that its total length is smaller than 64K. | |
u8_t | pbuf_get_at (const struct pbuf *p, u16_t offset) |
Get one byte from the specified position in a pbuf WARNING: returns zero for offset >= p->tot_len. | |
int | pbuf_try_get_at (const struct pbuf *p, u16_t offset) |
Get one byte from the specified position in a pbuf. | |
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. | |
u16_t | pbuf_memcmp (const 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. | |
u16_t | pbuf_memfind (const 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. | |
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! |
Detailed Description
pbuf API
Definition in file pbuf.h.
Typedef Documentation
typedef void(* pbuf_free_custom_fn)(struct pbuf *p) |
Function Documentation
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:
-
p pbuf to change the header size. header_size_increment Number 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.
Definition at line 550 of file lwip_pbuf.c.
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.
Definition at line 560 of file lwip_pbuf.c.
u16_t pbuf_clen | ( | const struct pbuf * | p ) |
Count number of pbufs in a chain.
- Parameters:
-
p first pbuf of chain
- Returns:
- the number of pbufs in a chain
Definition at line 808 of file lwip_pbuf.c.
Dechains the first pbuf from its succeeding pbufs in the chain.
Makes p->tot_len field equal to p->len.
- Parameters:
-
p pbuf 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 911 of file lwip_pbuf.c.
err_t pbuf_fill_chksum | ( | struct pbuf * | p, |
u16_t | start_offset, | ||
const void * | dataptr, | ||
u16_t | len, | ||
u16_t * | chksum | ||
) |
Copies data into a single pbuf (*not* into a pbuf queue!) and updates the checksum while copying.
- Parameters:
-
p the pbuf to copy data into start_offset offset of p->payload where to copy the data to dataptr data to copy into the pbuf len length of data to copy into the pbuf chksum pointer to the checksum which is updated
- Returns:
- ERR_OK if successful, another error if the data does not fit within the (first) pbuf (no pbuf queues!)
Definition at line 1333 of file lwip_pbuf.c.
Similar to pbuf_header(-size) but de-refs header pbufs for (size >= p->len)
- Parameters:
-
q pbufs to operate on size The 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
Definition at line 670 of file lwip_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:
-
p pbuf to change the header size. header_size_increment Number 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.
Definition at line 645 of file lwip_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 655 of file lwip_pbuf.c.
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:
-
p pbuf to change the header size. header_size_decrement Number 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.
Definition at line 581 of file lwip_pbuf.c.
This method modifies a 'pbuf chain', so that its total length is smaller than 64K.
The remainder of the original pbuf chain is stored in *rest. This function never creates new pbufs, but splits an existing chain in two parts. The tot_len of the modified packet queue will likely be smaller than 64K. 'packet queues' are not supported by this function.
- Parameters:
-
p the pbuf queue to be split rest pointer to store the remainder (after the first 64K)
Definition at line 1112 of file lwip_pbuf.c.
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:
-
p pbuf to search, maximum length is 0xFFFE since 0xFFFF is used as return value 'not found' substr string 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 1502 of file lwip_pbuf.c.
Generated on Tue Jul 12 2022 13:55:17 by
