STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
pbuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 
33 #ifndef LWIP_HDR_PBUF_H
34 #define LWIP_HDR_PBUF_H
35 
36 #include "lwip/opt.h"
37 #include "lwip/err.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
49 #ifndef LWIP_SUPPORT_CUSTOM_PBUF
50 #define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
51 #endif
52 
53 /* @todo: We need a mechanism to prevent wasting memory in every pbuf
54  (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) */
55 
56 #define PBUF_TRANSPORT_HLEN 20
57 #if LWIP_IPV6
58 #define PBUF_IP_HLEN 40
59 #else
60 #define PBUF_IP_HLEN 20
61 #endif
62 
63 typedef enum {
69 } pbuf_layer;
70 
71 typedef enum {
91 } pbuf_type;
92 
93 
95 #define PBUF_FLAG_PUSH 0x01U
96 
98 #define PBUF_FLAG_IS_CUSTOM 0x02U
99 
100 #define PBUF_FLAG_MCASTLOOP 0x04U
101 
102 #define PBUF_FLAG_LLBCAST 0x08U
103 
104 #define PBUF_FLAG_LLMCAST 0x10U
105 
106 #define PBUF_FLAG_TCP_FIN 0x20U
107 
108 struct pbuf {
110  struct pbuf *next;
111 
113  void *payload;
114 
123 
126 
128  u8_t /*pbuf_type*/ type;
129 
132 
139 };
140 
141 
146 struct pbuf_rom {
148  struct pbuf *next;
149 
151  const void *payload;
152 };
153 
154 #if LWIP_SUPPORT_CUSTOM_PBUF
155 
156 typedef void (*pbuf_free_custom_fn)(struct pbuf *p);
157 
159 struct pbuf_custom {
161  struct pbuf pbuf;
163  pbuf_free_custom_fn custom_free_function;
164 };
165 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
166 
167 #if LWIP_TCP && TCP_QUEUE_OOSEQ
168 
169 #ifndef PBUF_POOL_FREE_OOSEQ
170 #define PBUF_POOL_FREE_OOSEQ 1
171 #endif /* PBUF_POOL_FREE_OOSEQ */
172 #if NO_SYS && PBUF_POOL_FREE_OOSEQ
173 extern volatile u8_t pbuf_free_ooseq_pending;
174 void pbuf_free_ooseq(void);
178 #define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \
179  /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \
180  ooseq queued pbufs now */ \
181  pbuf_free_ooseq(); }}while(0)
182 #endif /* NO_SYS && PBUF_POOL_FREE_OOSEQ*/
183 #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ */
184 
185 /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
186 #define pbuf_init()
187 
188 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type);
189 #if LWIP_SUPPORT_CUSTOM_PBUF
190 struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
191  struct pbuf_custom *p, void *payload_mem,
192  u16_t payload_mem_len);
193 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
194 void pbuf_realloc(struct pbuf *p, u16_t size);
195 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
196 u8_t pbuf_header_force(struct pbuf *p, s16_t header_size);
197 void pbuf_ref(struct pbuf *p);
198 u8_t pbuf_free(struct pbuf *p);
199 u8_t pbuf_clen(struct pbuf *p);
200 void pbuf_cat(struct pbuf *head, struct pbuf *tail);
201 void pbuf_chain(struct pbuf *head, struct pbuf *tail);
202 struct pbuf *pbuf_dechain(struct pbuf *p);
203 err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from);
204 u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
205 err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len);
206 err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset);
207 struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset);
208 struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer);
209 #if LWIP_CHECKSUM_ON_COPY
210 err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
211  u16_t len, u16_t *chksum);
212 #endif /* LWIP_CHECKSUM_ON_COPY */
213 #if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
214 void pbuf_split_64k(struct pbuf *p, struct pbuf **rest);
215 #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
216 
217 u8_t pbuf_get_at(struct pbuf* p, u16_t offset);
218 void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data);
219 u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n);
220 u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset);
221 u16_t pbuf_strstr(struct pbuf* p, const char* substr);
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* LWIP_HDR_PBUF_H */
228 
u16_t pbuf_memcmp(struct pbuf *p, u16_t offset, const void *s2, u16_t n)
Definition: pbuf.c:1260
void pbuf_chain(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:820
u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:952
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:613
u8_t pbuf_clen(struct pbuf *p)
Definition: pbuf.c:738
signed short s16_t
Definition: cc.h:41
const void * payload
Definition: pbuf.h:151
struct pbuf * pbuf_dechain(struct pbuf *p)
Definition: pbuf.c:837
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:652
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:757
u16_t ref
Definition: pbuf.h:138
u8_t pbuf_header(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:603
struct pbuf * next
Definition: pbuf.h:148
u16_t len
Definition: pbuf.h:125
Definition: pbuf.h:77
Definition: pbuf.h:66
u8_t flags
Definition: pbuf.h:131
u8_t pbuf_get_at(struct pbuf *p, u16_t offset)
Definition: pbuf.c:1219
Definition: pbuf.h:146
Definition: pbuf.h:68
u16_t pbuf_strstr(struct pbuf *p, const char *substr)
Definition: pbuf.c:1322
u16_t tot_len
Definition: pbuf.h:122
Definition: pbuf.h:108
void pbuf_cat(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:779
s8_t err_t
Definition: err.h:47
Definition: pbuf.h:90
Definition: pbuf.h:81
struct pbuf * next
Definition: pbuf.h:110
pbuf_type
Definition: pbuf.h:71
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1117
u8_t type
Definition: pbuf.h:128
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
Definition: pbuf.c:1152
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
Definition: pbuf.c:1239
Definition: pbuf.h:85
unsigned char u8_t
Definition: cc.h:38
Definition: mem.c:179
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
Definition: pbuf.c:886
void pbuf_realloc(struct pbuf *p, u16_t size)
Definition: pbuf.c:431
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
Definition: pbuf.c:1048
Definition: pbuf.h:65
u16_t pbuf_memfind(struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
Definition: pbuf.c:1296
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Definition: pbuf.c:1075
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
Definition: pbuf.c:199
pbuf_layer
Definition: pbuf.h:63
unsigned short u16_t
Definition: cc.h:40
void * payload
Definition: pbuf.h:113