]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/lwip/pbuf.h
Split pbuf flags in pbuf type and flgs.
[pes-rpp/rpp-lwip.git] / src / include / lwip / pbuf.h
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_PBUF_H__
34 #define __LWIP_PBUF_H__
35
36 #include "arch/cc.h"
37 #include "lwip/err.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #define PBUF_TRANSPORT_HLEN 20
44 #define PBUF_IP_HLEN        20
45
46 typedef enum {
47   PBUF_TRANSPORT,
48   PBUF_IP,
49   PBUF_LINK,
50   PBUF_RAW
51 } pbuf_layer;
52
53 typedef enum {
54   PBUF_RAM,
55   PBUF_ROM,
56   PBUF_REF,
57   PBUF_POOL
58 } pbuf_flag;
59
60 /* Definitions for the pbuf flag field. These are NOT the flags that
61  * are passed to pbuf_alloc(). */
62 #define PBUF_TYPE_RAM   0x00U    /* pbuf data is stored in RAM */
63 #define PBUF_TYPE_ROM   0x01U    /* pbuf data is stored in ROM */
64 #define PBUF_TYPE_POOL  0x02U    /* pbuf comes from the pbuf pool */
65 #define PBUF_TYPE_REF   0x04U    /* pbuf payload refers to RAM */
66
67 /** indicates this packet's data should be immediately passed to the application */
68 #define PBUF_FLAG_PUSH 0x40U
69 /** indicates this packet was broadcast on the link */
70 #define PBUF_FLAG_LINK_BROADCAST 0x80U
71
72 struct pbuf {
73   /** next pbuf in singly linked pbuf chain */
74   struct pbuf *next;
75
76   /** pointer to the actual data in the buffer */
77   void *payload;
78   
79   /**
80    * total length of this buffer and all next buffers in chain
81    * belonging to the same packet.
82    *
83    * For non-queue packet chains this is the invariant:
84    * p->tot_len == p->len + (p->next? p->next->tot_len: 0)
85    */
86   u16_t tot_len;
87   
88   /** length of this buffer */
89   u16_t len;  
90
91   /** type of pbuf, see PBUF_TYPE_ */
92   u8_t type;
93
94   /** misc flags */
95   u8_t flgs;
96   
97   /**
98    * the reference count always equals the number of pointers
99    * that refer to this pbuf. This can be pointers from an application,
100    * the stack itself, or pbuf->next pointers from a chain.
101    */
102   u16_t ref;
103   
104 };
105
106 /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
107 #define pbuf_init()
108
109 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
110 void pbuf_realloc(struct pbuf *p, u16_t size); 
111 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
112 void pbuf_ref(struct pbuf *p);
113 void pbuf_ref_chain(struct pbuf *p);
114 u8_t pbuf_free(struct pbuf *p);
115 u8_t pbuf_clen(struct pbuf *p);  
116 void pbuf_cat(struct pbuf *h, struct pbuf *t);
117 void pbuf_chain(struct pbuf *h, struct pbuf *t);
118 struct pbuf *pbuf_dechain(struct pbuf *p);
119 err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from);
120 u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif /* __LWIP_PBUF_H__ */