TuyaOS
pbuf.h
浏览该文件的文档.
1
6/*
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * This file is part of the lwIP TCP/IP stack.
33 *
34 * Author: Adam Dunkels <adam@sics.se>
35 *
36 */
37
38#ifndef LWIP_HDR_PBUF_H
39#define LWIP_HDR_PBUF_H
40
41#include "lwip/opt.h"
42#include "lwip/err.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
54#ifndef LWIP_SUPPORT_CUSTOM_PBUF
55#define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
56#endif
57
71#ifndef PBUF_NEEDS_COPY
72#define PBUF_NEEDS_COPY(p) ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)
73#endif /* PBUF_NEEDS_COPY */
74
75/* @todo: We need a mechanism to prevent wasting memory in every pbuf
76 (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) */
77
78#define PBUF_TRANSPORT_HLEN 20
79#if LWIP_IPV6
80#define PBUF_IP_HLEN 40
81#else
82#define PBUF_IP_HLEN 20
83#endif
84
89typedef enum {
93 PBUF_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN,
111 PBUF_RAW = 0
113
114
115/* Base flags for pbuf_type definitions: */
116
119#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS 0x80
122#define PBUF_TYPE_FLAG_DATA_VOLATILE 0x40
125#define PBUF_TYPE_ALLOC_SRC_MASK 0x0F
129#define PBUF_ALLOC_FLAG_RX 0x0100
131#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS 0x0200
132
133#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP 0x00
134#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF 0x01
135#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL 0x02
137#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN 0x03
139#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX PBUF_TYPE_ALLOC_SRC_MASK
140
145typedef enum {
156 PBUF_ROM = PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF,
160 PBUF_REF = (PBUF_TYPE_FLAG_DATA_VOLATILE | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF),
167 PBUF_POOL = (PBUF_ALLOC_FLAG_RX | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL)
169
170
172#define PBUF_FLAG_PUSH 0x01U
175#define PBUF_FLAG_IS_CUSTOM 0x02U
177#define PBUF_FLAG_MCASTLOOP 0x04U
179#define PBUF_FLAG_LLBCAST 0x08U
181#define PBUF_FLAG_LLMCAST 0x10U
183#define PBUF_FLAG_TCP_FIN 0x20U
184
186struct pbuf {
188 struct pbuf *next;
189
191 void *payload;
192
200 u16_t tot_len;
201
203 u16_t len;
204
209
211 u8_t flags;
212
219
221 u8_t if_idx;
222};
223
224
229struct pbuf_rom {
231 struct pbuf *next;
232
234 const void *payload;
235};
236
237#if LWIP_SUPPORT_CUSTOM_PBUF
239typedef void (*pbuf_free_custom_fn)(struct pbuf *p);
240
242struct pbuf_custom {
244 struct pbuf pbuf;
246 pbuf_free_custom_fn custom_free_function;
247};
248#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
249
251#ifndef PBUF_POOL_FREE_OOSEQ
252#define PBUF_POOL_FREE_OOSEQ 1
253#endif /* PBUF_POOL_FREE_OOSEQ */
254#if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ
255extern volatile u8_t pbuf_free_ooseq_pending;
256void pbuf_free_ooseq(void);
260#define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \
261 /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \
262 ooseq queued pbufs now */ \
263 pbuf_free_ooseq(); }}while(0)
264#else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */
265 /* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */
266 #define PBUF_CHECK_FREE_OOSEQ()
267#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/
268
269/* Initializes the pbuf module. This call is empty for now, but may not be in future. */
270#define pbuf_init()
271
272struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type);
273struct pbuf *pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type);
274#if LWIP_SUPPORT_CUSTOM_PBUF
275struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
276 struct pbuf_custom *p, void *payload_mem,
277 u16_t payload_mem_len);
278#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
279void pbuf_realloc(struct pbuf *p, u16_t size);
280#define pbuf_get_allocsrc(p) ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK)
281#define pbuf_match_allocsrc(p, type) (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK))
282#define pbuf_match_type(p, type) pbuf_match_allocsrc(p, type)
283u8_t pbuf_header(struct pbuf *p, s16_t header_size);
284u8_t pbuf_header_force(struct pbuf *p, s16_t header_size);
285u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment);
286u8_t pbuf_add_header_force(struct pbuf *p, size_t header_size_increment);
287u8_t pbuf_remove_header(struct pbuf *p, size_t header_size);
288struct pbuf *pbuf_free_header(struct pbuf *q, u16_t size);
289void pbuf_ref(struct pbuf *p);
290u8_t pbuf_free(struct pbuf *p);
291u16_t pbuf_clen(const struct pbuf *p);
292void pbuf_cat(struct pbuf *head, struct pbuf *tail);
293void pbuf_chain(struct pbuf *head, struct pbuf *tail);
294struct pbuf *pbuf_dechain(struct pbuf *p);
295err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from);
296u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
297void *pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset);
298err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len);
299err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset);
300struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset);
301struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer);
302struct pbuf *pbuf_clone(pbuf_layer l, pbuf_type type, struct pbuf *p);
303#if LWIP_CHECKSUM_ON_COPY
304err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
305 u16_t len, u16_t *chksum);
306#endif /* LWIP_CHECKSUM_ON_COPY */
307#if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
308void pbuf_split_64k(struct pbuf *p, struct pbuf **rest);
309#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
310
311u8_t pbuf_get_at(const struct pbuf* p, u16_t offset);
312int pbuf_try_get_at(const struct pbuf* p, u16_t offset);
313void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data);
314u16_t pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n);
315u16_t pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset);
316u16_t pbuf_strstr(const struct pbuf* p, const char* substr);
317
318#ifdef __cplusplus
319}
320#endif
321
322#endif /* LWIP_HDR_PBUF_H */
s8_t err_t
Definition: err.h:96
#define PBUF_LINK_HLEN
Definition: opt.h:1530
#define PBUF_LINK_ENCAPSULATION_HLEN
Definition: opt.h:1539
#define LWIP_PBUF_REF_T
Definition: opt.h:1556
#define PBUF_TYPE_FLAG_DATA_VOLATILE
Definition: pbuf.h:122
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS
Definition: pbuf.h:131
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS
Definition: pbuf.h:119
#define PBUF_ALLOC_FLAG_RX
Definition: pbuf.h:129
pbuf_type
Definition: pbuf.h:145
@ PBUF_ROM
Definition: pbuf.h:156
@ PBUF_RAM
Definition: pbuf.h:152
@ PBUF_REF
Definition: pbuf.h:160
@ PBUF_POOL
Definition: pbuf.h:167
pbuf_layer
Definition: pbuf.h:89
@ PBUF_RAW_TX
Definition: pbuf.h:108
@ PBUF_RAW
Definition: pbuf.h:111
@ PBUF_TRANSPORT
Definition: pbuf.h:93
@ PBUF_LINK
Definition: pbuf.h:102
@ PBUF_IP
Definition: pbuf.h:97
Definition: pbuf.h:229
const void * payload
Definition: pbuf.h:234
struct pbuf * next
Definition: pbuf.h:231
Definition: pbuf.h:186
LWIP_PBUF_REF_T ref
Definition: pbuf.h:218
u16_t tot_len
Definition: pbuf.h:200
struct pbuf * next
Definition: pbuf.h:188
u8_t type_internal
Definition: pbuf.h:208
u8_t if_idx
Definition: pbuf.h:221
u16_t len
Definition: pbuf.h:203
void * payload
Definition: pbuf.h:191
u8_t flags
Definition: pbuf.h:211