2 * Copyright (c) 2001-2004 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>
33 #ifndef __LWIP_PBUF_H__
34 #define __LWIP_PBUF_H__
39 #define PBUF_TRANSPORT_HLEN 20
40 #define PBUF_IP_HLEN 20
56 /* Definitions for the pbuf flag field (these are not the flags that
57 are passed to pbuf_alloc()). */
58 #define PBUF_FLAG_RAM 0x00U /* Flags that pbuf data is stored in RAM */
59 #define PBUF_FLAG_ROM 0x01U /* Flags that pbuf data is stored in ROM */
60 #define PBUF_FLAG_POOL 0x02U /* Flags that the pbuf comes from the pbuf pool */
61 #define PBUF_FLAG_REF 0x04U /* Flags thet the pbuf payload refers to RAM */
63 /** indicates this packet was broadcast on the link */
64 #define PBUF_FLAG_LINK_BROADCAST 0x80U
67 /** next pbuf in singly linked pbuf chain */
70 /** pointer to the actual data in the buffer */
74 * total length of this buffer and all next buffers in chain
75 * belonging to the same packet.
77 * For non-queue packet chains this is the invariant:
78 * p->tot_len == p->len + (p->next? p->next->tot_len: 0)
82 /* length of this buffer */
85 /* flags telling the type of pbuf */
89 * the reference count always equals the number of pointers
90 * that refer to this pbuf. This can be pointers from an application,
91 * the stack itself, or pbuf->next pointers from a chain.
99 Initializes the pbuf module. The num parameter determines how many
100 pbufs that should be allocated to the pbuf pool, and the size
101 parameter specifies the size of the data allocated to those. */
102 void pbuf_init(void);
104 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
105 void pbuf_realloc(struct pbuf *p, u16_t size);
106 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
107 void pbuf_ref(struct pbuf *p);
108 void pbuf_ref_chain(struct pbuf *p);
109 u8_t pbuf_free(struct pbuf *p);
110 u8_t pbuf_clen(struct pbuf *p);
111 void pbuf_cat(struct pbuf *h, struct pbuf *t);
112 void pbuf_chain(struct pbuf *h, struct pbuf *t);
113 struct pbuf *pbuf_take(struct pbuf *f);
114 struct pbuf *pbuf_dechain(struct pbuf *p);
115 void pbuf_queue(struct pbuf *p, struct pbuf *n);
116 struct pbuf * pbuf_dequeue(struct pbuf *p);
118 #endif /* __LWIP_PBUF_H__ */