UbixOS V2 2.0

pbuf.h
Go to the documentation of this file.
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 <net/opt.h>
42 #include <net/err.h>
43
44 #ifdef __cplusplus
45 extern "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
58 /* @todo: We need a mechanism to prevent wasting memory in every pbuf
59 (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) */
60
61 #define PBUF_TRANSPORT_HLEN 20
62 #if LWIP_IPV6
63 #define PBUF_IP_HLEN 40
64 #else
65 #define PBUF_IP_HLEN 20
66 #endif
67
72 typedef enum {
76 PBUF_TRANSPORT,
80 PBUF_IP,
85 PBUF_LINK,
91 PBUF_RAW_TX,
94 PBUF_RAW
95 } pbuf_layer;
96
101 typedef enum {
108 PBUF_RAM,
112 PBUF_ROM,
116 PBUF_REF,
123 PBUF_POOL
124 } pbuf_type;
125
126
128 #define PBUF_FLAG_PUSH 0x01U
129
131 #define PBUF_FLAG_IS_CUSTOM 0x02U
132
133 #define PBUF_FLAG_MCASTLOOP 0x04U
134
135 #define PBUF_FLAG_LLBCAST 0x08U
136
137 #define PBUF_FLAG_LLMCAST 0x10U
138
139 #define PBUF_FLAG_TCP_FIN 0x20U
140
142 struct pbuf {
144 struct pbuf *next;
145
147 void *payload;
148
156 u16_t tot_len;
157
159 u16_t len;
160
162 u8_t /*pbuf_type*/ type;
163
165 u8_t flags;
166
172 u16_t ref;
173 };
174
175
180 struct pbuf_rom {
182 struct pbuf *next;
183
185 const void *payload;
186 };
187
188 #if LWIP_SUPPORT_CUSTOM_PBUF
189
190 typedef void (*pbuf_free_custom_fn)(struct pbuf *p);
191
193 struct pbuf_custom {
195 struct pbuf pbuf;
197 pbuf_free_custom_fn custom_free_function;
198 };
199 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
200
202 #ifndef PBUF_POOL_FREE_OOSEQ
203 #define PBUF_POOL_FREE_OOSEQ 1
204 #endif /* PBUF_POOL_FREE_OOSEQ */
205 #if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ
206 extern volatile u8_t pbuf_free_ooseq_pending;
207 void pbuf_free_ooseq(void);
211 #define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \
212 /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \
213 ooseq queued pbufs now */ \
214 pbuf_free_ooseq(); }}while(0)
215 #else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */
216 /* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */
217 #define PBUF_CHECK_FREE_OOSEQ()
218 #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/
219
220 /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
221 #define pbuf_init()
222
223 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type);
224 #if LWIP_SUPPORT_CUSTOM_PBUF
225 struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
226 struct pbuf_custom *p, void *payload_mem,
227 u16_t payload_mem_len);
228 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
229 void pbuf_realloc(struct pbuf *p, u16_t size);
230 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
231 u8_t pbuf_header_force(struct pbuf *p, s16_t header_size);
232 void pbuf_ref(struct pbuf *p);
233 u8_t pbuf_free(struct pbuf *p);
234 u16_t pbuf_clen(const struct pbuf *p);
235 void pbuf_cat(struct pbuf *head, struct pbuf *tail);
236 void pbuf_chain(struct pbuf *head, struct pbuf *tail);
237 struct pbuf *pbuf_dechain(struct pbuf *p);
238 err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from);
239 u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
240 err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len);
241 err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset);
242 struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset);
243 struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer);
244 #if LWIP_CHECKSUM_ON_COPY
245 err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
246 u16_t len, u16_t *chksum);
247 #endif /* LWIP_CHECKSUM_ON_COPY */
248 #if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
249 void pbuf_split_64k(struct pbuf *p, struct pbuf **rest);
250 #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
251
252 u8_t pbuf_get_at(const struct pbuf* p, u16_t offset);
253 int pbuf_try_get_at(const struct pbuf* p, u16_t offset);
254 void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data);
255 u16_t pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n);
256 u16_t pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset);
257 u16_t pbuf_strstr(const struct pbuf* p, const char* substr);
258
259 #ifdef __cplusplus
260 }
261 #endif
262
263 #endif /* LWIP_HDR_PBUF_H */
pbuf_memfind
u16_t pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
Definition: pbuf.c:1405
PBUF_POOL
Definition: pbuf.h:123
pbuf_skip
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
Definition: pbuf.c:1132
pbuf_try_get_at
int pbuf_try_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1318
opt.h
pbuf::len
u16_t len
Definition: pbuf.h:159
PBUF_LINK
Definition: pbuf.h:85
s16_t
int16_t s16_t
Definition: arch.h:125
pbuf::ref
u16_t ref
Definition: pbuf.h:172
PBUF_ROM
Definition: pbuf.h:112
PBUF_RAW
Definition: pbuf.h:94
mem
Definition: mem.c:264
u16_t
uint16_t u16_t
Definition: arch.h:124
PBUF_IP
Definition: pbuf.h:80
pbuf::tot_len
u16_t tot_len
Definition: pbuf.h:156
pbuf_rom::payload
const void * payload
Definition: pbuf.h:185
pbuf_rom
Definition: pbuf.h:180
pbuf_take
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Definition: pbuf.c:1150
pbuf_clen
u16_t pbuf_clen(const struct pbuf *p)
Definition: pbuf.c:801
pbuf::next
struct pbuf * next
Definition: pbuf.h:144
PBUF_TRANSPORT
Definition: pbuf.h:76
pbuf_free
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:715
pbuf_dechain
struct pbuf * pbuf_dechain(struct pbuf *p)
Definition: pbuf.c:900
pbuf_strstr
u16_t pbuf_strstr(const struct pbuf *p, const char *substr)
Definition: pbuf.c:1432
pbuf::flags
u8_t flags
Definition: pbuf.h:165
pbuf_copy_partial
u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1016
pbuf_alloc
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
Definition: pbuf.c:248
u8_t
uint8_t u8_t
Definition: arch.h:122
err.h
pbuf_coalesce
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
Definition: pbuf.c:1230
buf
Definition: buf.h:35
pbuf_layer
pbuf_layer
Definition: pbuf.h:72
pbuf_get_at
u8_t pbuf_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1300
pbuf_type
pbuf_type
Definition: pbuf.h:101
pbuf_realloc
void pbuf_realloc(struct pbuf *p, u16_t size)
Definition: pbuf.c:493
pbuf_copy
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition: pbuf.c:949
pbuf_take_at
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1194
pbuf_chain
void pbuf_chain(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:883
pbuf_ref
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:821
pbuf_cat
void pbuf_cat(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:841
PBUF_RAM
Definition: pbuf.h:108
pbuf_memcmp
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
Definition: pbuf.c:1363
PBUF_RAW_TX
Definition: pbuf.h:91
err_t
s8_t err_t
Definition: err.h:57
pbuf_rom::next
struct pbuf * next
Definition: pbuf.h:182
pbuf::type
u8_t type
Definition: pbuf.h:162
pbuf_header_force
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:675
pbuf_put_at
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
Definition: pbuf.c:1340
pbuf
Definition: pbuf.h:142
pbuf_header
u8_t pbuf_header(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:665
PBUF_REF
Definition: pbuf.h:116
pbuf::payload
void * payload
Definition: pbuf.h:147