Functions | |
struct pbuf * | pbuf_alloc (pbuf_layer layer, u16_t length, pbuf_type type) |
void | pbuf_realloc (struct pbuf *p, u16_t new_len) |
u8_t | pbuf_header (struct pbuf *p, s16_t header_size_increment) |
u8_t | pbuf_free (struct pbuf *p) |
u8_t | pbuf_clen (struct pbuf *p) |
void | pbuf_ref (struct pbuf *p) |
void | pbuf_cat (struct pbuf *h, struct pbuf *t) |
void | pbuf_chain (struct pbuf *h, struct pbuf *t) |
struct pbuf * | pbuf_dechain (struct pbuf *p) |
err_t | pbuf_copy (struct pbuf *p_to, struct pbuf *p_from) |
u16_t | pbuf_copy_partial (struct pbuf *buf, void *dataptr, u16_t len, u16_t offset) |
Packets are built from the pbuf data structure. It supports dynamic memory allocation for packet contents or can reference externally managed packet contents both in RAM and ROM. Quick allocation for incoming packets is provided through pools with fixed sized pbufs.
A packet may span over multiple pbufs, chained as a singly linked list. This is called a "pbuf chain".
Multiple packets may be queued, also using this singly linked list. This is called a "packet queue".
So, a packet queue consists of one or more pbuf chains, each of which consist of one or more pbufs. CURRENTLY, PACKET QUEUES ARE NOT SUPPORTED!!! Use helper structs to queue multiple packets.
The differences between a pbuf chain and a packet queue are very precise but subtle.
The last pbuf of a packet has a ->tot_len field that equals the ->len field. It can be found by traversing the list. If the last pbuf of a packet has a ->next field other than NULL, more packets are on the queue.
Therefore, looping through a pbuf of a single packet, has an loop end condition (tot_len == p->len), NOT (next == NULL).
struct pbuf* pbuf_alloc | ( | pbuf_layer | layer, | |
u16_t | length, | |||
pbuf_type | type | |||
) | [read] |
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).
layer | flag to define header size | |
length | size of the pbuf's payload | |
type | this parameter decides how and where the pbuf should be allocated as follows: |
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.
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.
h | head pbuf (chain) | |
t | tail pbuf (chain) |
MAY NOT be called on a packet queue.
u8_t pbuf_clen | ( | struct pbuf * | p | ) |
Count number of pbufs in a chain
p | first pbuf of chain |
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.
Only one packet is copied, no packet queue!
p_to | pbuf source of the copy | |
p_from | pbuf destination of the copy |
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.
buf | the pbuf from which to copy data | |
dataptr | the application supplied buffer | |
len | length of data to copy (dataptr must be big enough) | |
offset | offset into the packet buffer from where to begin copying len bytes |
struct pbuf* pbuf_dechain | ( | struct pbuf * | p | ) | [read] |
Dechains the first pbuf from its succeeding pbufs in the chain.
Makes p->tot_len field equal to p->len.
p | pbuf to dechain |
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.
p | The pbuf (chain) to be dereferenced. |
the reference counter of a pbuf equals the number of pointers that refer to the pbuf (or into the pbuf).
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.
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 hdr_size_inc is 0, this function does nothing and returns succesful. |
void pbuf_realloc | ( | struct pbuf * | p, | |
u16_t | new_len | |||
) |
Shrink a pbuf chain to a desired length.
p | pbuf to shrink. | |
new_len | desired new length of pbuf chain |
May not be called on a packet queue.
Despite its name, pbuf_realloc cannot grow the size of a pbuf (chain).
void pbuf_ref | ( | struct pbuf * | p | ) |
Increment the reference count of the pbuf.
p | pbuf to increase reference counter of |