Select one of the symbols to view example projects that use it.
 
Outline
#define LWIP_HDR_PBUF_H
#include "lwip/opt.h"
#include "lwip/err.h"
#define LWIP_SUPPORT_CUSTOM_PBUF
#define PBUF_NEEDS_COPY
#define PBUF_TRANSPORT_HLEN
#define PBUF_IP_HLEN
#define PBUF_IP_HLEN
pbuf_layer
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS
#define PBUF_TYPE_FLAG_DATA_VOLATILE
#define PBUF_TYPE_ALLOC_SRC_MASK
#define PBUF_ALLOC_FLAG_RX
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX
pbuf_type
#define PBUF_FLAG_PUSH
#define PBUF_FLAG_IS_CUSTOM
#define PBUF_FLAG_MCASTLOOP
#define PBUF_FLAG_LLBCAST
#define PBUF_FLAG_LLMCAST
#define PBUF_FLAG_TCP_FIN
pbuf
pbuf_rom
pbuf_custom
#define PBUF_POOL_FREE_OOSEQ
#define PBUF_CHECK_FREE_OOSEQ
#define pbuf_init
pbuf_alloc(pbuf_layer, u16_t, pbuf_type);
pbuf_alloc_reference(void *, u16_t, pbuf_type);
pbuf_alloced_custom(pbuf_layer, u16_t, pbuf_type, struct pbuf_custom *, void *, u16_t);
pbuf_realloc(struct pbuf *, u16_t);
#define pbuf_get_allocsrc
#define pbuf_match_allocsrc
#define pbuf_match_type
pbuf_header(struct pbuf *, s16_t);
pbuf_header_force(struct pbuf *, s16_t);
pbuf_add_header(struct pbuf *, size_t);
pbuf_add_header_force(struct pbuf *, size_t);
pbuf_remove_header(struct pbuf *, size_t);
pbuf_free_header(struct pbuf *, u16_t);
pbuf_ref(struct pbuf *);
pbuf_free(struct pbuf *);
pbuf_clen(const struct pbuf *);
pbuf_cat(struct pbuf *, struct pbuf *);
pbuf_chain(struct pbuf *, struct pbuf *);
pbuf_dechain(struct pbuf *);
pbuf_copy(struct pbuf *, const struct pbuf *);
pbuf_copy_partial(const struct pbuf *, void *, u16_t, u16_t);
pbuf_get_contiguous(const struct pbuf *, void *, size_t, u16_t, u16_t);
pbuf_take(struct pbuf *, const void *, u16_t);
pbuf_take_at(struct pbuf *, const void *, u16_t, u16_t);
pbuf_skip(struct pbuf *, u16_t, u16_t *);
pbuf_coalesce(struct pbuf *, pbuf_layer);
pbuf_clone(pbuf_layer, pbuf_type, struct pbuf *);
pbuf_get_at(const struct pbuf *, u16_t);
pbuf_try_get_at(const struct pbuf *, u16_t);
pbuf_put_at(struct pbuf *, u16_t, u8_t);
pbuf_memcmp(const struct pbuf *, u16_t, const void *, u16_t);
pbuf_memfind(const struct pbuf *, const void *, u16_t, u16_t);
pbuf_strstr(const struct pbuf *, const char *);
Files
loading...
SourceVuSTM32 Libraries and SamplesLwIPsrc/include/lwip/pbuf.h
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** * @file * pbuf API *//* ... */ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. * * Author: Adam Dunkels <adam@sics.se> * *//* ... */ #ifndef LWIP_HDR_PBUF_H #define LWIP_HDR_PBUF_H #include "lwip/opt.h" #include "lwip/err.h" #ifdef __cplusplus extern "C" { #endif /** 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. *//* ... */ #ifndef LWIP_SUPPORT_CUSTOM_PBUF #define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)) #endif /** @ingroup pbuf * 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. *//* ... */ #ifndef PBUF_NEEDS_COPY #define PBUF_NEEDS_COPY(p) ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE) #endif /* PBUF_NEEDS_COPY */ /* @todo: We need a mechanism to prevent wasting memory in every pbuf (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) *//* ... */ #define PBUF_TRANSPORT_HLEN 20 #if LWIP_IPV6 #define PBUF_IP_HLEN 40 #else #define PBUF_IP_HLEN 20 #endif /** * @ingroup pbuf * Enumeration of pbuf layers *//* ... */ typedef enum { /** 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_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN, /** Includes spare room for IP header. * Use this if you intend to pass the pbuf to functions like raw_send(). *//* ... */ PBUF_IP = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN, /** Includes spare room for link layer header (ethernet header). * Use this if you intend to pass the pbuf to functions like ethernet_output(). * @see PBUF_LINK_HLEN *//* ... */ PBUF_LINK = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN, /** 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(). * @see PBUF_LINK_ENCAPSULATION_HLEN *//* ... */ PBUF_RAW_TX = PBUF_LINK_ENCAPSULATION_HLEN, /** Use this for input packets in a netif driver when calling netif->input() * in the most common case - ethernet-layer netif driver. *//* ... */ PBUF_RAW = 0 ...} pbuf_layer; /* Base flags for pbuf_type definitions: */ /** Indicates that the payload directly follows the struct pbuf. * This makes @ref pbuf_header work in both directions. *//* ... */ #define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS 0x80 /** Indicates the data stored in this pbuf can change. If this pbuf needs * to be queued, it must be copied/duplicated. *//* ... */ #define PBUF_TYPE_FLAG_DATA_VOLATILE 0x40 /** 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*//* ... */ #define PBUF_TYPE_ALLOC_SRC_MASK 0x0F /** 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) *//* ... */ #define PBUF_ALLOC_FLAG_RX 0x0100 /** Indicates the application needs the pbuf payload to be in one piece */ #define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS 0x0200 #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 /** First pbuf allocation type for applications */ #define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN 0x03 /** Last pbuf allocation type for applications */ #define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX PBUF_TYPE_ALLOC_SRC_MASK 10 defines /** * @ingroup pbuf * Enumeration of pbuf types *//* ... */ typedef enum { /** 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_RAM = (PBUF_ALLOC_FLAG_DATA_CONTIGUOUS | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP), /** 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_ROM = PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF, /** 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_REF = (PBUF_TYPE_FLAG_DATA_VOLATILE | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF), /** 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! *//* ... */ PBUF_POOL = (PBUF_ALLOC_FLAG_RX | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL) ...} pbuf_type; /** indicates this packet's data should be immediately passed to the application */ #define PBUF_FLAG_PUSH 0x01U /** 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) *//* ... */ #define PBUF_FLAG_IS_CUSTOM 0x02U /** indicates this pbuf is UDP multicast to be looped back */ #define PBUF_FLAG_MCASTLOOP 0x04U /** indicates this pbuf was received as link-level broadcast */ #define PBUF_FLAG_LLBCAST 0x08U /** indicates this pbuf was received as link-level multicast */ #define PBUF_FLAG_LLMCAST 0x10U /** indicates this pbuf includes a TCP FIN flag */ #define PBUF_FLAG_TCP_FIN 0x20U 6 defines /** Main packet buffer struct */ struct pbuf { /** next pbuf in singly linked pbuf chain */ struct pbuf *next; /** pointer to the actual data in the buffer */ void *payload; /** * total length of this buffer and all next buffers in chain * belonging to the same packet. * * For non-queue packet chains this is the invariant: * p->tot_len == p->len + (p->next? p->next->tot_len: 0) *//* ... */ u16_t tot_len; /** length of this buffer */ u16_t len; /** a bit field indicating pbuf type and allocation sources (see PBUF_TYPE_FLAG_*, PBUF_ALLOC_FLAG_* and PBUF_TYPE_ALLOC_SRC_MASK) *//* ... */ u8_t type_internal; /** misc flags */ u8_t flags; /** * the reference count always equals the number of pointers * that refer to this pbuf. This can be pointers from an application, * the stack itself, or pbuf->next pointers from a chain. *//* ... */ LWIP_PBUF_REF_T ref; /** For incoming packets, this contains the input netif's index */ u8_t if_idx; ...}; /** Helper struct for const-correctness only. * The only meaning of this one is to provide a const payload pointer * for PBUF_ROM type. *//* ... */ struct pbuf_rom { /** next pbuf in singly linked pbuf chain */ struct pbuf *next; /** pointer to the actual data in the buffer */ const void *payload; ...}; #if LWIP_SUPPORT_CUSTOM_PBUF /** Prototype for a function to free a custom pbuf */ typedef void (*pbuf_free_custom_fn)(struct pbuf *p); /** A custom pbuf: like a pbuf, but following a function pointer to free it. */ struct pbuf_custom { /** The actual pbuf */ struct pbuf pbuf; /** This function is called when pbuf_free deallocates this pbuf(_custom) */ pbuf_free_custom_fn custom_free_function; ...};/* ... */ #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ /** Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty */ #ifndef PBUF_POOL_FREE_OOSEQ #define PBUF_POOL_FREE_OOSEQ 1 #endif /* PBUF_POOL_FREE_OOSEQ */ #if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ extern volatile u8_t pbuf_free_ooseq_pending; void pbuf_free_ooseq(void); /** When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ() at regular intervals from main level to check if ooseq pbufs need to be freed! *//* ... */ #define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \ /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \ ooseq queued pbufs now *//* ... */ \ pbuf_free_ooseq(); }if (pbuf_free_ooseq_pending) { ... }}...while(0)... /* ... */#else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */ /* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */ #define PBUF_CHECK_FREE_OOSEQ() /* ... */#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/ /* Initializes the pbuf module. This call is empty for now, but may not be in future. */ #define pbuf_init() struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type); struct pbuf *pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type); #if LWIP_SUPPORT_CUSTOM_PBUF struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p, void *payload_mem, u16_t payload_mem_len);/* ... */ #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ void pbuf_realloc(struct pbuf *p, u16_t size); #define pbuf_get_allocsrc(p) ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK) #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) u8_t pbuf_header(struct pbuf *p, s16_t header_size); u8_t pbuf_header_force(struct pbuf *p, s16_t header_size); 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); u8_t pbuf_remove_header(struct pbuf *p, size_t header_size); struct pbuf *pbuf_free_header(struct pbuf *q, u16_t size); void pbuf_ref(struct pbuf *p); u8_t pbuf_free(struct pbuf *p); u16_t pbuf_clen(const struct pbuf *p); void pbuf_cat(struct pbuf *head, struct pbuf *tail); void pbuf_chain(struct pbuf *head, struct pbuf *tail); struct pbuf *pbuf_dechain(struct pbuf *p); 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); void *pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset); 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); struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset); struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer); struct pbuf *pbuf_clone(pbuf_layer l, pbuf_type type, struct pbuf *p); #if LWIP_CHECKSUM_ON_COPY err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, u16_t len, u16_t *chksum);/* ... */ #endif /* LWIP_CHECKSUM_ON_COPY */ #if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE void pbuf_split_64k(struct pbuf *p, struct pbuf **rest); #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ u8_t pbuf_get_at(const struct pbuf* p, u16_t offset); int pbuf_try_get_at(const struct pbuf* p, u16_t offset); void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data); 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); u16_t pbuf_strstr(const struct pbuf* p, const char* substr); #ifdef __cplusplus }extern "C" { ... } #endif /* ... */ #endif /* LWIP_HDR_PBUF_H */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.