]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/lwip/pbuf.h
Updated lwIP module copyright years to include 2003. Committers must check theirs.
[pes-rpp/rpp-lwip.git] / src / include / lwip / pbuf.h
1 /*
2  * Copyright (c) 2001-2003 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_PBUF_H__
34 #define __LWIP_PBUF_H__
35
36 #include "lwip/debug.h"
37 #include "lwip/arch.h"
38
39
40 #define PBUF_TRANSPORT_HLEN 20
41 #define PBUF_IP_HLEN        20
42
43 typedef enum {
44   PBUF_TRANSPORT,
45   PBUF_IP,
46   PBUF_LINK,
47   PBUF_RAW
48 } pbuf_layer;
49
50 typedef enum {
51   PBUF_RAM,
52   PBUF_ROM,
53   PBUF_REF,
54   PBUF_POOL
55 } pbuf_flag;
56
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
62                                    pbuf pool. */
63 #define PBUF_FLAG_REF   0x03
64
65 struct pbuf {
66   struct pbuf *next;
67
68   /* Pointer to the actual data in the buffer. */
69   void *payload;
70   
71   /* Total length of buffer + additionally chained buffers. */
72   u16_t tot_len;
73   
74   /* Length of this buffer. */
75   u16_t len;  
76
77   /* Flags and reference count. */
78   u16_t flags, ref;
79   
80 };
81
82 /* pbuf_init():
83
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.  */
87 void pbuf_init(void);
88
89 /* pbuf_alloc():
90    
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
95    as follows:
96  
97    * PBUF_RAM: buffer memory for pbuf is allocated as one large
98                chunk. This includesprotocol headers as well.
99    
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.
104
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);
108
109 /* pbuf_realloc():
110
111    Shrinks the pbuf to the size given by the size parameter. 
112  */
113 void pbuf_realloc(struct pbuf *p, u16_t size); 
114
115 /* pbuf_header():
116
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);
122
123 /* pbuf_ref():
124
125    Increments the reference count of the pbuf p.
126  */
127 void pbuf_ref(struct pbuf *p);
128 void pbuf_ref_chain(struct pbuf *p);
129 /* pbuf_free():
130
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);
135
136 /* pbuf_clen():
137
138    Returns the length of the pbuf chain. */
139 u8_t pbuf_clen(struct pbuf *p);  
140
141 /* pbuf_chain():
142
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);
147
148 /* pbuf_dechain():
149
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);
153
154 struct pbuf *pbuf_unref(struct pbuf *f);
155
156
157 #endif /* __LWIP_PBUF_H__ */