ESP8266
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 "lwip/opt.h"
37 #include "lwip/err.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
45 #define LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF)
46 
47 #define PBUF_TRANSPORT_HLEN 20
48 #define PBUF_IP_HLEN 20
49 
50 typedef enum {
51  PBUF_TRANSPORT,
52  PBUF_IP,
53  PBUF_LINK,
54  PBUF_RAW
55 } pbuf_layer;
56 
57 typedef enum {
58  PBUF_RAM, /* pbuf data is stored in RAM */
59  PBUF_ROM, /* pbuf data is stored in ROM */
60  PBUF_REF, /* pbuf comes from the pbuf pool */
61  PBUF_POOL, /* pbuf payload refers to RAM */
62 #ifdef EBUF_LWIP
63  PBUF_ESF_RX /* pbuf payload is from WLAN */
64 #endif /* ESF_LWIP */
65 } pbuf_type;
66 
67 
69 #define PBUF_FLAG_PUSH 0x01U
70 
72 #define PBUF_FLAG_IS_CUSTOM 0x02U
73 
74 #define PBUF_FLAG_MCASTLOOP 0x04U
75 
76 struct pbuf {
78  struct pbuf *next;
79 
81  void *payload;
82 
90  u16_t tot_len;
91 
93  u16_t len;
94 
96  u8_t /*pbuf_type*/ type;
97 
99  u8_t flags;
100 
106  u16_t ref;
107 
108  /* add a pointer for esf_buf */
109  void * eb;
110 };
111 
112 #if LWIP_SUPPORT_CUSTOM_PBUF
113 
114 typedef void (*pbuf_free_custom_fn)(struct pbuf *p);
115 
117 struct pbuf_custom {
119  struct pbuf pbuf;
121  pbuf_free_custom_fn custom_free_function;
122 };
123 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
124 
125 /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
126 #define pbuf_init()
127 
128 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)ICACHE_FLASH_ATTR;
129 #if LWIP_SUPPORT_CUSTOM_PBUF
130 struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
131  struct pbuf_custom *p, void *payload_mem,
132  u16_t payload_mem_len)ICACHE_FLASH_ATTR;
133 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
134 void pbuf_realloc(struct pbuf *p, u16_t size)ICACHE_FLASH_ATTR;
135 u8_t pbuf_header(struct pbuf *p, s16_t header_size)ICACHE_FLASH_ATTR;
136 void pbuf_ref(struct pbuf *p)ICACHE_FLASH_ATTR;
137 u8_t pbuf_free(struct pbuf *p)ICACHE_FLASH_ATTR;
138 u8_t pbuf_clen(struct pbuf *p)ICACHE_FLASH_ATTR;
139 void pbuf_cat(struct pbuf *head, struct pbuf *tail)ICACHE_FLASH_ATTR;
140 void pbuf_chain(struct pbuf *head, struct pbuf *tail)ICACHE_FLASH_ATTR;
141 struct pbuf *pbuf_dechain(struct pbuf *p)ICACHE_FLASH_ATTR;
142 err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)ICACHE_FLASH_ATTR;
143 u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset)ICACHE_FLASH_ATTR;
144 err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)ICACHE_FLASH_ATTR;
145 struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer)ICACHE_FLASH_ATTR;
146 #if LWIP_CHECKSUM_ON_COPY
147 err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
148  u16_t len, u16_t *chksum)ICACHE_FLASH_ATTR;
149 #endif /* LWIP_CHECKSUM_ON_COPY */
150 
151 u8_t pbuf_get_at(struct pbuf* p, u16_t offset)ICACHE_FLASH_ATTR;
152 u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n)ICACHE_FLASH_ATTR;
153 u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset)ICACHE_FLASH_ATTR;
154 u16_t pbuf_strstr(struct pbuf* p, const char* substr)ICACHE_FLASH_ATTR;
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* __LWIP_PBUF_H__ */
u16_t tot_len
Definition: pbuf.h:90
void * eb
Definition: pbuf.h:109
struct pbuf * next
Definition: pbuf.h:78
u16_t len
Definition: pbuf.h:93
u8_t flags
Definition: pbuf.h:99
Definition: pbuf.h:76
void * payload
Definition: pbuf.h:81
u8_t type
Definition: pbuf.h:96
u16_t ref
Definition: pbuf.h:106