TuyaOS
结构体 | 宏定义 | 枚举 | 函数
pbuf.h 文件参考
#include "lwip/opt.h"
#include "lwip/err.h"
pbuf.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

结构体

struct  pbuf_rom
 

宏定义

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
 
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS   0x0200
 
#define PBUF_ALLOC_FLAG_RX   0x0100
 
#define PBUF_CHECK_FREE_OOSEQ()
 
#define PBUF_FLAG_IS_CUSTOM   0x02U
 
#define PBUF_FLAG_LLBCAST   0x08U
 
#define PBUF_FLAG_LLMCAST   0x10U
 
#define PBUF_FLAG_MCASTLOOP   0x04U
 
#define PBUF_FLAG_PUSH   0x01U
 
#define PBUF_FLAG_TCP_FIN   0x20U
 
#define pbuf_get_allocsrc(p)   ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK)
 
#define pbuf_init()
 
#define PBUF_IP_HLEN   20
 
#define pbuf_match_allocsrc(p, type)   (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK))
 
#define pbuf_match_type(p, type)   pbuf_match_allocsrc(p, type)
 
#define PBUF_NEEDS_COPY(p)   ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)
 
#define PBUF_POOL_FREE_OOSEQ   1
 
#define PBUF_TRANSPORT_HLEN   20
 
#define PBUF_TYPE_ALLOC_SRC_MASK   0x0F
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX   PBUF_TYPE_ALLOC_SRC_MASK
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP   0x00
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF   0x01
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL   0x02
 
#define PBUF_TYPE_FLAG_DATA_VOLATILE   0x40
 
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS   0x80
 

枚举

enum  pbuf_layer {
  PBUF_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + 20 + 20 , PBUF_IP = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + 20 , PBUF_LINK = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN , PBUF_RAW_TX = PBUF_LINK_ENCAPSULATION_HLEN ,
  PBUF_RAW = 0
}
 
enum  pbuf_type { PBUF_RAM = ( 0x0200 | 0x80 | 0x00 ) , PBUF_ROM = 0x01 , PBUF_REF = ( 0x40 | 0x01 ) , PBUF_POOL = ( 0x0100 | 0x80 | 0x02 ) }
 

函数

u8_t pbuf_add_header (struct pbuf *p, size_t header_size_increment)
 
u8_t pbuf_add_header_force (struct pbuf *p, size_t header_size_increment)
 
struct pbufpbuf_alloc (pbuf_layer l, u16_t length, pbuf_type type)
 
struct pbufpbuf_alloc_reference (void *payload, u16_t length, pbuf_type type)
 
void pbuf_cat (struct pbuf *head, struct pbuf *tail)
 
void pbuf_chain (struct pbuf *head, struct pbuf *tail)
 
u16_t pbuf_clen (const struct pbuf *p)
 
struct pbufpbuf_clone (pbuf_layer l, pbuf_type type, struct pbuf *p)
 
struct pbufpbuf_coalesce (struct pbuf *p, pbuf_layer layer)
 
err_t pbuf_copy (struct pbuf *p_to, const struct pbuf *p_from)
 
u16_t pbuf_copy_partial (const struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
 
struct pbufpbuf_dechain (struct pbuf *p)
 
u8_t pbuf_free (struct pbuf *p)
 
struct pbufpbuf_free_header (struct pbuf *q, u16_t size)
 
u8_t pbuf_get_at (const struct pbuf *p, u16_t offset)
 
void * pbuf_get_contiguous (const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset)
 
u8_t pbuf_header (struct pbuf *p, s16_t header_size)
 
u8_t pbuf_header_force (struct pbuf *p, s16_t header_size)
 
u16_t pbuf_memcmp (const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
 
u16_t pbuf_memfind (const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
 
void pbuf_put_at (struct pbuf *p, u16_t offset, u8_t data)
 
void pbuf_realloc (struct pbuf *p, u16_t size)
 
void pbuf_ref (struct pbuf *p)
 
u8_t pbuf_remove_header (struct pbuf *p, size_t header_size)
 
struct pbufpbuf_skip (struct pbuf *in, u16_t in_offset, u16_t *out_offset)
 
u16_t pbuf_strstr (const struct pbuf *p, const char *substr)
 
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)
 
int pbuf_try_get_at (const struct pbuf *p, u16_t offset)
 

详细描述

pbuf API

宏定义说明

◆ LWIP_SUPPORT_CUSTOM_PBUF

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

◆ PBUF_ALLOC_FLAG_DATA_CONTIGUOUS

#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS   0x0200

Indicates the application needs the pbuf payload to be in one piece

◆ PBUF_ALLOC_FLAG_RX

#define PBUF_ALLOC_FLAG_RX   0x0100

Indicates this pbuf is used for RX (if not set, indicates use for TX). This information can be used to keep some spare RX buffers e.g. for receiving TCP ACKs to unblock a connection)

◆ PBUF_FLAG_IS_CUSTOM

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

◆ PBUF_FLAG_LLBCAST

#define PBUF_FLAG_LLBCAST   0x08U

indicates this pbuf was received as link-level broadcast

◆ PBUF_FLAG_LLMCAST

#define PBUF_FLAG_LLMCAST   0x10U

indicates this pbuf was received as link-level multicast

◆ PBUF_FLAG_MCASTLOOP

#define PBUF_FLAG_MCASTLOOP   0x04U

indicates this pbuf is UDP multicast to be looped back

◆ PBUF_FLAG_PUSH

#define PBUF_FLAG_PUSH   0x01U

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

◆ PBUF_FLAG_TCP_FIN

#define PBUF_FLAG_TCP_FIN   0x20U

indicates this pbuf includes a TCP FIN flag

◆ PBUF_NEEDS_COPY

#define PBUF_NEEDS_COPY (   p)    ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)

PBUF_NEEDS_COPY(p): return a boolean value indicating whether the given pbuf needs to be copied in order to be kept around beyond the current call stack without risking being corrupted. The default setting provides safety: it will make a copy iof any pbuf chain that does not consist entirely of PBUF_ROM type pbufs. For setups with zero-copy support, it may be redefined to evaluate to true in all cases, for example. However, doing so also has an effect on the application side: any buffers that are not copied must also not be reused by the application after passing them to lwIP. For example, when setting PBUF_NEEDS_COPY to (0), after using udp_send() with a PBUF_RAM pbuf, the application must free the pbuf immediately, rather than reusing it for other purposes. For more background information on this, see tasks #6735 and #7896, and bugs #11400 and #49914.

◆ PBUF_POOL_FREE_OOSEQ

#define PBUF_POOL_FREE_OOSEQ   1

Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty

◆ PBUF_TYPE_ALLOC_SRC_MASK

#define PBUF_TYPE_ALLOC_SRC_MASK   0x0F

4 bits are reserved for 16 allocation sources (e.g. heap, pool1, pool2, etc) Internally, we use: 0=heap, 1=MEMP_PBUF, 2=MEMP_PBUF_POOL -> 13 types free

◆ PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX

#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX   PBUF_TYPE_ALLOC_SRC_MASK

Last pbuf allocation type for applications

◆ PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN

#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03

First pbuf allocation type for applications

◆ PBUF_TYPE_FLAG_DATA_VOLATILE

#define PBUF_TYPE_FLAG_DATA_VOLATILE   0x40

Indicates the data stored in this pbuf can change. If this pbuf needs to be queued, it must be copied/duplicated.

◆ PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS

#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS   0x80

Indicates that the payload directly follows the struct pbuf. This makes pbuf_header work in both directions.

枚举类型说明

◆ pbuf_layer

enum pbuf_layer

Enumeration of pbuf layers

枚举值
PBUF_TRANSPORT 

Includes spare room for transport layer header, e.g. UDP header. Use this if you intend to pass the pbuf to functions like udp_send().

PBUF_IP 

Includes spare room for IP header. Use this if you intend to pass the pbuf to functions like raw_send().

PBUF_LINK 

Includes spare room for link layer header (ethernet header). Use this if you intend to pass the pbuf to functions like ethernet_output().

参见
PBUF_LINK_HLEN
PBUF_RAW_TX 

Includes spare room for additional encapsulation header before ethernet headers (e.g. 802.11). Use this if you intend to pass the pbuf to functions like netif->linkoutput().

参见
PBUF_LINK_ENCAPSULATION_HLEN
PBUF_RAW 

Use this for input packets in a netif driver when calling netif->input() in the most common case - ethernet-layer netif driver.

◆ pbuf_type

enum pbuf_type

Enumeration of pbuf types

枚举值
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). This should be used for all OUTGOING packets (TX).

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). Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing, you are unable to receive TCP acks!