2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
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.
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
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
32 /*-----------------------------------------------------------------------------------*/
33 #ifndef __LWIP_PBUF_H__
34 #define __LWIP_PBUF_H__
36 #include "lwip/debug.h"
37 #include "lwip/arch.h"
40 #define PBUF_TRANSPORT_HLEN 20
41 #define PBUF_IP_HLEN 20
57 /* Definitions for the pbuf flag field (these are not the flags that
58 are passed to pbuf_alloc()). */
59 #define PBUF_FLAG_RAM 0x00 /* Flags that pbuf data is stored in RAM. */
60 #define PBUF_FLAG_ROM 0x01 /* Flags that pbuf data is stored in ROM. */
61 #define PBUF_FLAG_POOL 0x02 /* Flags that the pbuf comes from the
63 #define PBUF_FLAG_REF 0x03
68 /* Pointer to the actual data in the buffer. */
71 /* Total length of buffer + additionally chained buffers. */
74 /* Length of this buffer. */
77 /* Flags and reference count. */
84 Initializes the pbuf module. The num parameter determines how many
85 pbufs that should be allocated to the pbuf pool, and the size
86 parameter specifies the size of the data allocated to those. */
91 Allocates a pbuf at protocol layer l. The actual memory allocated
92 for the pbuf is determined by the layer at which the pbuf is
93 allocated and the requested size (from the size parameter). The
94 flag parameter decides how and where the pbuf should be allocated
97 * PBUF_RAM: buffer memory for pbuf is allocated as one large
98 chunk. This includesprotocol headers as well.
100 * RBUF_ROM: no buffer memory is allocated for the pbuf, even for
101 protocol headers. Additional headers must be
102 prepended by allocating another pbuf and chain in to
103 the front of the ROM pbuf.
105 * PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from
106 the pbuf pool that is allocated during pbuf_init(). */
107 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
111 Shrinks the pbuf to the size given by the size parameter.
113 void pbuf_realloc(struct pbuf *p, u16_t size);
117 Tries to move the p->payload pointer header_size number of bytes
118 upward within the pbuf. The return value is non-zero if it
119 fails. If so, an additional pbuf should be allocated for the header
120 and it should be chained to the front. */
121 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
125 Increments the reference count of the pbuf p.
127 void pbuf_ref(struct pbuf *p);
128 void pbuf_ref_chain(struct pbuf *p);
131 Decrements the reference count and deallocates the pbuf if the
132 reference count is zero. If the pbuf is a chain all pbufs in the
133 chain are deallocated. */
134 u8_t pbuf_free(struct pbuf *p);
138 Returns the length of the pbuf chain. */
139 u8_t pbuf_clen(struct pbuf *p);
143 Chains pbuf t on the end of pbuf h. Pbuf h will have it's tot_len
144 field adjusted accordingly. Pbuf t should no be used any more after
145 a call to this function, since pbuf t is now a part of pbuf h. */
146 void pbuf_chain(struct pbuf *h, struct pbuf *t);
150 Picks off the first pbuf from the pbuf chain p. Returns the tail of
151 the pbuf chain or NULL if the pbuf p was not chained. */
152 struct pbuf *pbuf_dechain(struct pbuf *p);
154 struct pbuf *pbuf_unref(struct pbuf *f);
157 #endif /* __LWIP_PBUF_H__ */