NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
Queue of Mbufs

Functions

struct os_mbufos_mqueue_get (struct os_mqueue *mq)
 
int os_mqueue_put (struct os_mqueue *mq, struct ble_npl_eventq *evq, struct os_mbuf *m)
 
int os_msys_register (struct os_mbuf_pool *new_pool)
 
void os_msys_reset (void)
 
struct os_mbufos_msys_get (uint16_t dsize, uint16_t leadingspace)
 
struct os_mbufos_msys_get_pkthdr (uint16_t dsize, uint16_t user_hdr_len)
 
int os_msys_count (void)
 
int os_msys_num_free (void)
 
int os_mbuf_pool_init (struct os_mbuf_pool *omp, struct os_mempool *mp, uint16_t buf_len, uint16_t nbufs)
 
struct os_mbufos_mbuf_get (struct os_mbuf_pool *omp, uint16_t leadingspace)
 
struct os_mbufos_mbuf_get_pkthdr (struct os_mbuf_pool *omp, uint8_t user_pkthdr_len)
 
int os_mbuf_free (struct os_mbuf *om)
 
int os_mbuf_free_chain (struct os_mbuf *om)
 
uint16_t os_mbuf_len (const struct os_mbuf *om)
 Calculates the length of an mbuf chain.
 
int os_mbuf_append (struct os_mbuf *om, const void *data, uint16_t len)
 
int os_mbuf_appendfrom (struct os_mbuf *dst, const struct os_mbuf *src, uint16_t src_off, uint16_t len)
 
struct os_mbufos_mbuf_dup (struct os_mbuf *om)
 
struct os_mbufos_mbuf_off (const struct os_mbuf *om, int off, uint16_t *out_off)
 
void os_mbuf_adj (struct os_mbuf *mp, int req_len)
 
int os_mbuf_cmpf (const struct os_mbuf *om, int off, const void *data, int len)
 
int os_mbuf_cmpm (const struct os_mbuf *om1, uint16_t offset1, const struct os_mbuf *om2, uint16_t offset2, uint16_t len)
 
struct os_mbufos_mbuf_prepend (struct os_mbuf *om, int len)
 
struct os_mbufos_mbuf_prepend_pullup (struct os_mbuf *om, uint16_t len)
 
int os_mbuf_copyinto (struct os_mbuf *om, int off, const void *src, int len)
 
void os_mbuf_concat (struct os_mbuf *first, struct os_mbuf *second)
 
void * os_mbuf_extend (struct os_mbuf *om, uint16_t len)
 
struct os_mbufos_mbuf_pullup (struct os_mbuf *om, uint16_t len)
 
struct os_mbufos_mbuf_trim_front (struct os_mbuf *om)
 
int os_mbuf_widen (struct os_mbuf *om, uint16_t off, uint16_t len)
 
struct os_mbufos_mbuf_pack_chains (struct os_mbuf *m1, struct os_mbuf *m2)
 

Detailed Description

Function Documentation

◆ os_mbuf_adj()

void os_mbuf_adj ( struct os_mbuf mp,
int  req_len 
)

Adjust the length of a mbuf, trimming either from the head or the tail of the mbuf.

Parameters
mpThe mbuf chain to adjust
req_lenThe length to trim from the mbuf. If positive, trims from the head of the mbuf, if negative, trims from the tail of the mbuf.

◆ os_mbuf_append()

int os_mbuf_append ( struct os_mbuf m,
const void *  data,
uint16_t  len 
)

Append data onto a mbuf

Parameters
omThe mbuf to append the data onto
dataThe data to append onto the mbuf
lenThe length of the data to append
Returns
0 on success, and an error code on failure

◆ os_mbuf_appendfrom()

int os_mbuf_appendfrom ( struct os_mbuf dst,
const struct os_mbuf src,
uint16_t  src_off,
uint16_t  len 
)

Reads data from one mbuf and appends it to another. On error, the specified data range may be partially appended. Neither mbuf is required to contain an mbuf packet header.

Parameters
dstThe mbuf to append to.
srcThe mbuf to copy data from.
src_offThe absolute offset within the source mbuf chain to read from.
lenThe number of bytes to append.
Returns
0 on success; OS_EINVAL if the specified range extends beyond the end of the source mbuf chain.

◆ os_mbuf_cmpf()

int os_mbuf_cmpf ( const struct os_mbuf om,
int  off,
const void *  data,
int  len 
)

Performs a memory compare of the specified region of an mbuf chain against a flat buffer.

Parameters
omThe start of the mbuf chain to compare.
offThe offset within the mbuf chain to start the comparison.
dataThe flat buffer to compare.
lenThe length of the flat buffer.
Returns
0 if both memory regions are identical; A memcmp return code if there is a mismatch; INT_MAX if the mbuf is too short.

◆ os_mbuf_cmpm()

int os_mbuf_cmpm ( const struct os_mbuf om1,
uint16_t  offset1,
const struct os_mbuf om2,
uint16_t  offset2,
uint16_t  len 
)

Compares the contents of two mbuf chains. The ranges of the two chains to be compared are specified via the two offset parameters and the len parameter. Neither mbuf chain is required to contain a packet header.

Parameters
om1The first mbuf chain to compare.
offset1The absolute offset within om1 at which to start the comparison.
om2The second mbuf chain to compare.
offset2The absolute offset within om2 at which to start the comparison.
lenThe number of bytes to compare.
Returns
0 if both mbuf segments are identical; A memcmp() return code if the segment contents differ; INT_MAX if a specified range extends beyond the end of its corresponding mbuf chain.

◆ os_mbuf_concat()

void os_mbuf_concat ( struct os_mbuf first,
struct os_mbuf second 
)

Attaches a second mbuf chain onto the end of the first. If the first chain contains a packet header, the header's length is updated. If the second chain has a packet header, its header is cleared.

Parameters
firstThe mbuf chain being attached to.
secondThe mbuf chain that gets attached.

◆ os_mbuf_copyinto()

int os_mbuf_copyinto ( struct os_mbuf om,
int  off,
const void *  src,
int  len 
)

Copies the contents of a flat buffer into an mbuf chain, starting at the specified destination offset. If the mbuf is too small for the source data, it is extended as necessary. If the destination mbuf contains a packet header, the header length is updated.

Parameters
ompThe mbuf pool to allocate from.
omThe mbuf chain to copy into.
offThe offset within the chain to copy to.
srcThe source buffer to copy from.
lenThe number of bytes to copy.
Returns
0 on success; nonzero on failure.

◆ os_mbuf_dup()

struct os_mbuf * os_mbuf_dup ( struct os_mbuf m)

Duplicate a chain of mbufs. Return the start of the duplicated chain.

Parameters
ompThe mbuf pool to duplicate out of
omThe mbuf chain to duplicate
Returns
A pointer to the new chain of mbufs

◆ os_mbuf_extend()

void * os_mbuf_extend ( struct os_mbuf om,
uint16_t  len 
)

Increases the length of an mbuf chain by the specified amount. If there is not sufficient room in the last buffer, a new buffer is allocated and appended to the chain. It is an error to request more data than can fit in a single buffer.

Parameters
omp
omThe head of the chain to extend.
lenThe number of bytes to extend by.
Returns
A pointer to the new data on success; NULL on failure.

◆ os_mbuf_free()

int os_mbuf_free ( struct os_mbuf mb)

Release a mbuf back to the pool

Parameters
ompThe Mbuf pool to release back to
omThe Mbuf to release back to the pool
Returns
0 on success, -1 on failure

◆ os_mbuf_free_chain()

int os_mbuf_free_chain ( struct os_mbuf om)

Free a chain of mbufs

Parameters
ompThe mbuf pool to free the chain of mbufs into
omThe starting mbuf of the chain to free back into the pool
Returns
0 on success, -1 on failure

◆ os_mbuf_get()

struct os_mbuf * os_mbuf_get ( struct os_mbuf_pool omp,
uint16_t  leadingspace 
)

Get an mbuf from the mbuf pool. The mbuf is allocated, and initialized prior to being returned.

Parameters
ompThe mbuf pool to return the packet from
leadingspaceThe amount of leadingspace to put before the data section by default.
Returns
An initialized mbuf on success, and NULL on failure.

◆ os_mbuf_get_pkthdr()

struct os_mbuf * os_mbuf_get_pkthdr ( struct os_mbuf_pool omp,
uint8_t  pkthdr_len 
)

Allocate a new packet header mbuf out of the os_mbuf_pool.

Parameters
ompThe mbuf pool to allocate out of
user_pkthdr_lenThe packet header length to reserve for the caller.
Returns
A freshly allocated mbuf on success, NULL on failure.

◆ os_mbuf_len()

uint16_t os_mbuf_len ( const struct os_mbuf om)

Calculates the length of an mbuf chain.

Calculates the length of an mbuf chain. If the mbuf contains a packet header, you should use OS_MBUF_PKTLEN() as a more efficient alternative to this function.

Parameters
omThe mbuf to measure.
Returns
The length, in bytes, of the provided mbuf chain.

◆ os_mbuf_off()

struct os_mbuf * os_mbuf_off ( const struct os_mbuf om,
int  off,
uint16_t *  out_off 
)

Locates the specified absolute offset within an mbuf chain. The offset can be one past than the total length of the chain, but no greater.

Parameters
omThe start of the mbuf chain to seek within.
offThe absolute address to find.
out_offOn success, this points to the relative offset within the returned mbuf.
Returns
The mbuf containing the specified offset on success. NULL if the specified offset is out of bounds.

◆ os_mbuf_pack_chains()

struct os_mbuf * os_mbuf_pack_chains ( struct os_mbuf m1,
struct os_mbuf m2 
)

Creates a single chained mbuf from m1 and m2 utilizing all the available buffer space in all mbufs in the resulting chain. In other words, ensures there is no leading space in any mbuf in the resulting chain and trailing space only in the last mbuf in the chain. Mbufs from either chain may be freed if not needed. No mbufs are allocated. Note that mbufs from m2 are added to the end of m1. If m1 has a packet header, it is retained and length updated. If m2 has a packet header it is discarded. If m1 is NULL, NULL is returned and m2 is left untouched.

Parameters
m1Pointer to first mbuf chain to pack
m2Pointer to second mbuf chain to pack
Returns
struct os_mbuf* Pointer to resulting mbuf chain

◆ os_mbuf_pool_init()

int os_mbuf_pool_init ( struct os_mbuf_pool omp,
struct os_mempool mp,
uint16_t  buf_len,
uint16_t  nbufs 
)

Initialize a pool of mbufs.

Parameters
ompThe mbuf pool to initialize
mpThe memory pool that will hold this mbuf pool
buf_lenThe length of the buffer itself.
nbufsThe number of buffers in the pool
Returns
0 on success, error code on failure.

◆ os_mbuf_prepend()

struct os_mbuf * os_mbuf_prepend ( struct os_mbuf om,
int  len 
)

Increases the length of an mbuf chain by adding data to the front. If there is insufficient room in the leading mbuf, additional mbufs are allocated and prepended as necessary. If this function fails to allocate an mbuf, the entire chain is freed.

The specified mbuf chain does not need to contain a packet header.

Parameters
ompThe mbuf pool to allocate from.
omThe head of the mbuf chain.
lenThe number of bytes to prepend.
Returns
The new head of the chain on success; NULL on failure.

◆ os_mbuf_prepend_pullup()

struct os_mbuf * os_mbuf_prepend_pullup ( struct os_mbuf om,
uint16_t  len 
)

Prepends a chunk of empty data to the specified mbuf chain and ensures the chunk is contiguous. If either operation fails, the specified mbuf chain is freed and NULL is returned.

Parameters
omThe mbuf chain to prepend to.
lenThe number of bytes to prepend and pullup.
Returns
The modified mbuf on success; NULL on failure (and the mbuf chain is freed).

◆ os_mbuf_pullup()

struct os_mbuf * os_mbuf_pullup ( struct os_mbuf om,
uint16_t  len 
)

Rearrange a mbuf chain so that len bytes are contiguous, and in the data area of an mbuf (so that OS_MBUF_DATA() will work on a structure of size len.) Returns the resulting mbuf chain on success, free's it and returns NULL on failure.

If there is room, it will add up to "max_protohdr - len" extra bytes to the contiguous region, in an attempt to avoid being called next time.

Parameters
ompThe mbuf pool to take the mbufs out of
omThe mbuf chain to make contiguous
lenThe number of bytes in the chain to make contiguous
Returns
The contiguous mbuf chain on success, NULL on failure.

◆ os_mbuf_trim_front()

struct os_mbuf * os_mbuf_trim_front ( struct os_mbuf om)

Removes and frees empty mbufs from the front of a chain. If the chain contains a packet header, it is preserved.

Parameters
omThe mbuf chain to trim.
Returns
The head of the trimmed mbuf chain.

◆ os_mbuf_widen()

int os_mbuf_widen ( struct os_mbuf om,
uint16_t  off,
uint16_t  len 
)

Increases the length of an mbuf chain by inserting a gap at the specified offset. The contents of the gap are indeterminate. If the mbuf chain contains a packet header, its total length is increased accordingly.

This function never frees the provided mbuf chain.

Parameters
omThe mbuf chain to widen.
offThe offset at which to insert the gap.
lenThe size of the gap to insert.
Returns
0 on success; SYS_[...] error code on failure.

◆ os_mqueue_get()

struct os_mbuf * os_mqueue_get ( struct os_mqueue mq)

Remove and return a single mbuf from the mbuf queue. Does not block.

Parameters
mqThe mbuf queue to pull an element off of.
Returns
The next mbuf in the queue, or NULL if queue has no mbufs.

◆ os_mqueue_put()

int os_mqueue_put ( struct os_mqueue mq,
struct ble_npl_eventq *  evq,
struct os_mbuf m 
)

Adds a packet (i.e. packet header mbuf) to an mqueue. The event associated with the mqueue gets posted to the specified eventq.

Parameters
mqThe mbuf queue to append the mbuf to.
evqThe event queue to post an event to.
mThe mbuf to append to the mbuf queue.
Returns
0 on success, non-zero on failure.

◆ os_msys_count()

int os_msys_count ( void  )

Count the number of blocks in all the mbuf pools that are allocated.

Returns
total number of blocks allocated in Msys

◆ os_msys_get()

struct os_mbuf * os_msys_get ( uint16_t  dsize,
uint16_t  leadingspace 
)

Allocate a mbuf from msys. Based upon the data size requested, os_msys_get() will choose the mbuf pool that has the best fit.

Parameters
dsizeThe estimated size of the data being stored in the mbuf
leadingspaceThe amount of leadingspace to allocate in the mbuf
Returns
A freshly allocated mbuf on success, NULL on failure.

◆ os_msys_get_pkthdr()

struct os_mbuf * os_msys_get_pkthdr ( uint16_t  dsize,
uint16_t  user_hdr_len 
)

Allocate a packet header structure from the MSYS pool. See os_msys_register() for a description of MSYS.

Parameters
dsizeThe estimated size of the data being stored in the mbuf
user_hdr_lenThe length to allocate for the packet header structure
Returns
A freshly allocated mbuf on success, NULL on failure.

◆ os_msys_num_free()

int os_msys_num_free ( void  )

Return the number of free blocks in Msys

Returns
Number of free blocks available in Msys

◆ os_msys_register()

int os_msys_register ( struct os_mbuf_pool new_pool)

MSYS is a system level mbuf registry. Allows the system to share packet buffers amongst the various networking stacks that can be running simultaeneously.

Mbuf pools are created in the system initialization code, and then when a mbuf is allocated out of msys, it will try and find the best fit based upon estimated mbuf size.

os_msys_register() registers a mbuf pool with MSYS, and allows MSYS to allocate mbufs out of it.

Parameters
new_poolThe pool to register with MSYS
Returns
0 on success, non-zero on failure

◆ os_msys_reset()

void os_msys_reset ( void  )

De-registers all mbuf pools from msys.