WE310F5  39.00.000
M2MB NETBUF

This section describes the M2MB APIs to perform network buffer allocation and deallocation operations. More...

#define M2MB_NETBUF_MAX_QUEUE_NAME   6
 
#define M2MB_NETBUF_MAX_QUEUES   3
 
#define M2MB_NETBUF_UDP_HEADROOM   (52)
 
#define M2MB_NETBUF_TCP_HEADROOM   (64)
 
#define M2MB_NETBUF_UDP6_HEADROOM   (72)
 
#define M2MB_NETBUF_TCP6_HEADROOM   (88)
 
#define M2MB_NET_BUF_UPDATE_START(pkt, p)   (p) = ((M2MB_NET_BUF_T *)(pkt))->nb_Prot
 
#define M2MB_NET_BUF_UPDATE_INT32(p, val)   *(UINT32 *)(p) = (UINT32)(val); (p) += sizeof(UINT32)
 
#define M2MB_NET_BUF_UPDATE_INT16(p, val)   *(uint16_t *)(p) = (uint16_t)(val); (p) += sizeof(uint16_t)
 
#define M2MB_NET_BUF_UPDATE_INT8(p, val)   *(uint8_t *)(p) = (uint8_t)(val); (p) += sizeof(uint8_t)
 
#define M2MB_NET_BUF_UPDATE_DATA(p, data, len)   memcpy((p), (data), (len)); (p) += (len)
 
#define M2MB_NET_BUF_UPDATE_END(pkt, len)
 
#define M2MB_NETBUF_APP   0x0
 
#define M2MB_NETBUF_SYS   0x1
 
#define M2MB_NETBUF_SYS_CONTIG   (0x4 | M2MB_NETBUF_SYS)
 
#define M2MB_NETBUF_SSL   0x2
 
typedef struct M2MB_NET_BUF M2MB_NET_BUF_T
 Structure to hold network buffer information. More...
 
typedef M2MB_NET_BUF_TPACKET
 
typedef struct m2mb_Net_Buf_Queue_s m2mb_Net_Buf_Queue_t
 Structure that contains information about a free queue. More...
 
typedef struct m2mb_Net_Buf_Queue_Status_s m2mb_Net_Buf_Queue_Status_t
 Structure that contains information about all free queues. More...
 
void * m2mb_Net_Buf_Alloc (UINT32 size, UINT32 id)
 Allocates a network buffer. More...
 
INT32 m2mb_Net_Buf_Free (void *buf, UINT32 id)
 Frees a network buffer. More...
 
INT32 m2mb_Net_Buf_Update (void *netbuf, UINT32 offset, void *srcbuf, UINT32 len, UINT32 id)
 Updates data in a network buffer. More...
 
M2MB_STATUS_T m2mb_Net_Buf_Free_Queue_Status (m2mb_Net_Buf_Queue_Status_t *arg)
 

Detailed Description

This section describes the M2MB APIs to perform network buffer allocation and deallocation operations.

Macro Definition Documentation

◆ M2MB_NET_BUF_UPDATE_DATA

#define M2MB_NET_BUF_UPDATE_DATA (   p,
  data,
  len 
)    memcpy((p), (data), (len)); (p) += (len)

Copy application data into a non-chained buffer.

Definition at line 183 of file m2mb_netbuf.h.

◆ M2MB_NET_BUF_UPDATE_END

#define M2MB_NET_BUF_UPDATE_END (   pkt,
  len 
)
Value:
((M2MB_NET_BUF_T *)(pkt))->nb_Plen = \
((M2MB_NET_BUF_T *)(pkt))->nb_Tlen = (len)
Structure to hold network buffer information.
Definition: m2mb_netbuf.h:93

Update the buffer size on a system buffer.

Definition at line 189 of file m2mb_netbuf.h.

◆ M2MB_NET_BUF_UPDATE_INT16

#define M2MB_NET_BUF_UPDATE_INT16 (   p,
  val 
)    *(uint16_t *)(p) = (uint16_t)(val); (p) += sizeof(uint16_t)

Update 2 bytes of data in the buffer.

Definition at line 171 of file m2mb_netbuf.h.

◆ M2MB_NET_BUF_UPDATE_INT32

#define M2MB_NET_BUF_UPDATE_INT32 (   p,
  val 
)    *(UINT32 *)(p) = (UINT32)(val); (p) += sizeof(UINT32)

Update 4 bytes of data in the buffer.

Definition at line 165 of file m2mb_netbuf.h.

◆ M2MB_NET_BUF_UPDATE_INT8

#define M2MB_NET_BUF_UPDATE_INT8 (   p,
  val 
)    *(uint8_t *)(p) = (uint8_t)(val); (p) += sizeof(uint8_t)

Update 1 byte of data in the buffer.

Definition at line 177 of file m2mb_netbuf.h.

◆ M2MB_NET_BUF_UPDATE_START

#define M2MB_NET_BUF_UPDATE_START (   pkt,
 
)    (p) = ((M2MB_NET_BUF_T *)(pkt))->nb_Prot

Update the data start pointer on a system buffer.

Definition at line 159 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_APP

#define M2MB_NETBUF_APP   0x0

Allocate a contiguous network buffer from the application heap. If the application does not enable the Zero-copy option for a socket, it should allocate memory using M2MB_NETBUF_APP for sending packets. The memory will be allocated from the heap.

Definition at line 201 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_MAX_QUEUE_NAME

#define M2MB_NETBUF_MAX_QUEUE_NAME   6

Maximum size of the queue name.

Definition at line 80 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_MAX_QUEUES

#define M2MB_NETBUF_MAX_QUEUES   3

Maximum number of free queues.

Definition at line 85 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_SSL

#define M2MB_NETBUF_SSL   0x2

Allocate a network buffer for a secure connection. If the application enables the Zero-copy option for a socket and uses a secure connection over it, it must allocate memory using one of these two combinations of flags:

  • (M2MB_NETBUF_APP | M2MB_NETBUF_SSL)
  • (M2MB_NETBUF_SYS | M2MB_NETBUF_SSL)

Definition at line 227 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_SYS

#define M2MB_NETBUF_SYS   0x1

Allocate a network buffer from the system stack. If the application enables the Zero-copy option for a socket, it must allocate memory using M2MB_NETBUF_SYS for sending packets. The memory will be allocated from the packet buffer pool and might be made of a chain of smaller buffers.

Definition at line 210 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_SYS_CONTIG

#define M2MB_NETBUF_SYS_CONTIG   (0x4 | M2MB_NETBUF_SYS)

Allocate a contiguous network buffer from the system stack. If the application enables the Zero-copy option for a socket, it must allocate memory using M2MB_NETBUF_SYS for sending packets. The memory will be allocated from the packet buffer pool.

Definition at line 218 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_TCP6_HEADROOM

#define M2MB_NETBUF_TCP6_HEADROOM   (88)

TCP6 head room. 24+40+24(TCP with option) = 88

Definition at line 152 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_TCP_HEADROOM

#define M2MB_NETBUF_TCP_HEADROOM   (64)

TCP head room. MAC+IP+TCP = 24+20+20 = 64.

Definition at line 142 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_UDP6_HEADROOM

#define M2MB_NETBUF_UDP6_HEADROOM   (72)

UDP6 head room. 24+40+8 = 72.

Definition at line 147 of file m2mb_netbuf.h.

◆ M2MB_NETBUF_UDP_HEADROOM

#define M2MB_NETBUF_UDP_HEADROOM   (52)

UDP head room. MAC+IP+UDP = 24+20+8 = 52.

Definition at line 137 of file m2mb_netbuf.h.

Typedef Documentation

◆ m2mb_Net_Buf_Queue_Status_t

Structure that contains information about all free queues.

This structure contains the number of free packet buffers total numbers in each queue and the total number of free packet buffers in the system.

◆ m2mb_Net_Buf_Queue_t

Structure that contains information about a free queue.

This structure contains the number of free packet buffers and the total number of buffers in a given queue.

◆ M2MB_NET_BUF_T

typedef struct M2MB_NET_BUF M2MB_NET_BUF_T

Structure to hold network buffer information.

This structure is used when allocating a system buffer. The network buffer can be chained and accessed via pk_prev and pk_next.

◆ PACKET

Definition at line 105 of file m2mb_netbuf.h.

Function Documentation

◆ m2mb_Net_Buf_Alloc()

void* m2mb_Net_Buf_Alloc ( UINT32  size,
UINT32  id 
)

Allocates a network buffer.

Call this function to allocate a network buffer. For M2MB_NETBUF_APP requests, the buffer is allocated from the application heap (4-byte aligned plain buffer), and the application owns it (the system will have its own copy).

For M2MB_NETBUF_SYS requests, the buffer is allocated from the system network buffer pool and is shared with the networking stack. The buffer is of the type M2MB_NET_BUF_T, and macros and helper functions must be used in order to read or write data. These buffers can be chained and non-contiguous. Additionally, after a successful send, the application cannot use the same buffer and must allocate a new one for additional sends. On receive, once the receive handler is called, the application must free the network buffer before returning.

Parameters
[in]sizeSize, in bytes, of the buffer.
[in]idSee M2MB_NETBUF_APP, M2MB_NETBUF_SYS, and M2MB_NETBUF_SSL.
Returns
A pointer to the network buffer, or NULL in case no memory is available.
For M2MB_NETBUF_SYS requests, a NULL result is usually not a fatal error; the application can sleep and retry. However, for M2MB_NETBUF_APP requests, this means that there is not enough free heap memory.

◆ m2mb_Net_Buf_Free()

INT32 m2mb_Net_Buf_Free ( void *  buf,
UINT32  id 
)

Frees a network buffer.

Call this function to free a network buffer.

Parameters
[in]bufPointer to the buffer to be freed.
[in]idID; see M2MB_NETBUF_APP, M2MB_NETBUF_SYS, and M2MB_NETBUF_SSL. The same flag that was used to allocate it must be applied.
Returns
0 if operation succeeded, -1 otherwise.

◆ m2mb_Net_Buf_Free_Queue_Status()

M2MB_STATUS_T m2mb_Net_Buf_Free_Queue_Status ( m2mb_Net_Buf_Queue_Status_t arg)

Gets the number of free packet buffers in all queues.

Parameters
[in]argPointer to the m2mb_Net_Buf_Queue_Status_t data structure.
Returns
M2MB_OK – On success.
M2MB_ERR_INVALID_PARAM – Invalid input parameter.

◆ m2mb_Net_Buf_Update()

INT32 m2mb_Net_Buf_Update ( void *  netbuf,
UINT32  offset,
void *  srcbuf,
UINT32  len,
UINT32  id 
)

Updates data in a network buffer.

Call this function to seamlessly update data in a network buffer, even in chained ones.

Parameters
[in]netbufPointer to the buffer to be updated.
[in]offsetData offset.
[in]srcbufPointer to the data source.
[in]lenData length.
[in]idID; ee M2MB_NETBUF_APP, M2MB_NETBUF_SYS and M2MB_NETBUF_SSL.
Returns
0 if operation succeeded, -1 otherwise. *