ProjetoBB
Dependencies: F7_Ethernet WebSocketClient mbed mcp3008
Fork of Nucleo_F746ZG_Ethernet by
F7_Ethernet/lwip/include/lwip/pbuf.h@0:f9b6112278fe, 2016-06-18 (annotated)
- Committer:
- DieterGraef
- Date:
- Sat Jun 18 10:49:12 2016 +0000
- Revision:
- 0:f9b6112278fe
Ethernet for the NUCLEO STM32F746 Board Testprogram uses DHCP and NTP to set the clock
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 0:f9b6112278fe | 1 | /* |
DieterGraef | 0:f9b6112278fe | 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
DieterGraef | 0:f9b6112278fe | 3 | * All rights reserved. |
DieterGraef | 0:f9b6112278fe | 4 | * |
DieterGraef | 0:f9b6112278fe | 5 | * Redistribution and use in source and binary forms, with or without modification, |
DieterGraef | 0:f9b6112278fe | 6 | * are permitted provided that the following conditions are met: |
DieterGraef | 0:f9b6112278fe | 7 | * |
DieterGraef | 0:f9b6112278fe | 8 | * 1. Redistributions of source code must retain the above copyright notice, |
DieterGraef | 0:f9b6112278fe | 9 | * this list of conditions and the following disclaimer. |
DieterGraef | 0:f9b6112278fe | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
DieterGraef | 0:f9b6112278fe | 11 | * this list of conditions and the following disclaimer in the documentation |
DieterGraef | 0:f9b6112278fe | 12 | * and/or other materials provided with the distribution. |
DieterGraef | 0:f9b6112278fe | 13 | * 3. The name of the author may not be used to endorse or promote products |
DieterGraef | 0:f9b6112278fe | 14 | * derived from this software without specific prior written permission. |
DieterGraef | 0:f9b6112278fe | 15 | * |
DieterGraef | 0:f9b6112278fe | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
DieterGraef | 0:f9b6112278fe | 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
DieterGraef | 0:f9b6112278fe | 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
DieterGraef | 0:f9b6112278fe | 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
DieterGraef | 0:f9b6112278fe | 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
DieterGraef | 0:f9b6112278fe | 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
DieterGraef | 0:f9b6112278fe | 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
DieterGraef | 0:f9b6112278fe | 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
DieterGraef | 0:f9b6112278fe | 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
DieterGraef | 0:f9b6112278fe | 25 | * OF SUCH DAMAGE. |
DieterGraef | 0:f9b6112278fe | 26 | * |
DieterGraef | 0:f9b6112278fe | 27 | * This file is part of the lwIP TCP/IP stack. |
DieterGraef | 0:f9b6112278fe | 28 | * |
DieterGraef | 0:f9b6112278fe | 29 | * Author: Adam Dunkels <adam@sics.se> |
DieterGraef | 0:f9b6112278fe | 30 | * |
DieterGraef | 0:f9b6112278fe | 31 | */ |
DieterGraef | 0:f9b6112278fe | 32 | |
DieterGraef | 0:f9b6112278fe | 33 | #ifndef __LWIP_PBUF_H__ |
DieterGraef | 0:f9b6112278fe | 34 | #define __LWIP_PBUF_H__ |
DieterGraef | 0:f9b6112278fe | 35 | |
DieterGraef | 0:f9b6112278fe | 36 | #include "lwip/opt.h" |
DieterGraef | 0:f9b6112278fe | 37 | #include "lwip/err.h" |
DieterGraef | 0:f9b6112278fe | 38 | |
DieterGraef | 0:f9b6112278fe | 39 | #ifdef __cplusplus |
DieterGraef | 0:f9b6112278fe | 40 | extern "C" { |
DieterGraef | 0:f9b6112278fe | 41 | #endif |
DieterGraef | 0:f9b6112278fe | 42 | |
DieterGraef | 0:f9b6112278fe | 43 | /** Currently, the pbuf_custom code is only needed for one specific configuration |
DieterGraef | 0:f9b6112278fe | 44 | * of IP_FRAG */ |
DieterGraef | 0:f9b6112278fe | 45 | #define LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) |
DieterGraef | 0:f9b6112278fe | 46 | |
DieterGraef | 0:f9b6112278fe | 47 | #define PBUF_TRANSPORT_HLEN 20 |
DieterGraef | 0:f9b6112278fe | 48 | #define PBUF_IP_HLEN 20 |
DieterGraef | 0:f9b6112278fe | 49 | |
DieterGraef | 0:f9b6112278fe | 50 | typedef enum { |
DieterGraef | 0:f9b6112278fe | 51 | PBUF_TRANSPORT, |
DieterGraef | 0:f9b6112278fe | 52 | PBUF_IP, |
DieterGraef | 0:f9b6112278fe | 53 | PBUF_LINK, |
DieterGraef | 0:f9b6112278fe | 54 | PBUF_RAW |
DieterGraef | 0:f9b6112278fe | 55 | } pbuf_layer; |
DieterGraef | 0:f9b6112278fe | 56 | |
DieterGraef | 0:f9b6112278fe | 57 | typedef enum { |
DieterGraef | 0:f9b6112278fe | 58 | PBUF_RAM, /* pbuf data is stored in RAM */ |
DieterGraef | 0:f9b6112278fe | 59 | PBUF_ROM, /* pbuf data is stored in ROM */ |
DieterGraef | 0:f9b6112278fe | 60 | PBUF_REF, /* pbuf comes from the pbuf pool */ |
DieterGraef | 0:f9b6112278fe | 61 | PBUF_POOL /* pbuf payload refers to RAM */ |
DieterGraef | 0:f9b6112278fe | 62 | } pbuf_type; |
DieterGraef | 0:f9b6112278fe | 63 | |
DieterGraef | 0:f9b6112278fe | 64 | |
DieterGraef | 0:f9b6112278fe | 65 | /** indicates this packet's data should be immediately passed to the application */ |
DieterGraef | 0:f9b6112278fe | 66 | #define PBUF_FLAG_PUSH 0x01U |
DieterGraef | 0:f9b6112278fe | 67 | /** indicates this is a custom pbuf: pbuf_free and pbuf_header handle such a |
DieterGraef | 0:f9b6112278fe | 68 | a pbuf differently */ |
DieterGraef | 0:f9b6112278fe | 69 | #define PBUF_FLAG_IS_CUSTOM 0x02U |
DieterGraef | 0:f9b6112278fe | 70 | /** indicates this pbuf is UDP multicast to be looped back */ |
DieterGraef | 0:f9b6112278fe | 71 | #define PBUF_FLAG_MCASTLOOP 0x04U |
DieterGraef | 0:f9b6112278fe | 72 | /** indicates this pbuf was received as link-level broadcast */ |
DieterGraef | 0:f9b6112278fe | 73 | #define PBUF_FLAG_LLBCAST 0x08U |
DieterGraef | 0:f9b6112278fe | 74 | /** indicates this pbuf was received as link-level multicast */ |
DieterGraef | 0:f9b6112278fe | 75 | #define PBUF_FLAG_LLMCAST 0x10U |
DieterGraef | 0:f9b6112278fe | 76 | /** indicates this pbuf includes a TCP FIN flag */ |
DieterGraef | 0:f9b6112278fe | 77 | #define PBUF_FLAG_TCP_FIN 0x20U |
DieterGraef | 0:f9b6112278fe | 78 | |
DieterGraef | 0:f9b6112278fe | 79 | struct pbuf { |
DieterGraef | 0:f9b6112278fe | 80 | /** next pbuf in singly linked pbuf chain */ |
DieterGraef | 0:f9b6112278fe | 81 | struct pbuf *next; |
DieterGraef | 0:f9b6112278fe | 82 | |
DieterGraef | 0:f9b6112278fe | 83 | /** pointer to the actual data in the buffer */ |
DieterGraef | 0:f9b6112278fe | 84 | void *payload; |
DieterGraef | 0:f9b6112278fe | 85 | |
DieterGraef | 0:f9b6112278fe | 86 | /** |
DieterGraef | 0:f9b6112278fe | 87 | * total length of this buffer and all next buffers in chain |
DieterGraef | 0:f9b6112278fe | 88 | * belonging to the same packet. |
DieterGraef | 0:f9b6112278fe | 89 | * |
DieterGraef | 0:f9b6112278fe | 90 | * For non-queue packet chains this is the invariant: |
DieterGraef | 0:f9b6112278fe | 91 | * p->tot_len == p->len + (p->next? p->next->tot_len: 0) |
DieterGraef | 0:f9b6112278fe | 92 | */ |
DieterGraef | 0:f9b6112278fe | 93 | u16_t tot_len; |
DieterGraef | 0:f9b6112278fe | 94 | |
DieterGraef | 0:f9b6112278fe | 95 | /** length of this buffer */ |
DieterGraef | 0:f9b6112278fe | 96 | u16_t len; |
DieterGraef | 0:f9b6112278fe | 97 | |
DieterGraef | 0:f9b6112278fe | 98 | /** pbuf_type as u8_t instead of enum to save space */ |
DieterGraef | 0:f9b6112278fe | 99 | u8_t /*pbuf_type*/ type; |
DieterGraef | 0:f9b6112278fe | 100 | |
DieterGraef | 0:f9b6112278fe | 101 | /** misc flags */ |
DieterGraef | 0:f9b6112278fe | 102 | u8_t flags; |
DieterGraef | 0:f9b6112278fe | 103 | |
DieterGraef | 0:f9b6112278fe | 104 | /** |
DieterGraef | 0:f9b6112278fe | 105 | * the reference count always equals the number of pointers |
DieterGraef | 0:f9b6112278fe | 106 | * that refer to this pbuf. This can be pointers from an application, |
DieterGraef | 0:f9b6112278fe | 107 | * the stack itself, or pbuf->next pointers from a chain. |
DieterGraef | 0:f9b6112278fe | 108 | */ |
DieterGraef | 0:f9b6112278fe | 109 | u16_t ref; |
DieterGraef | 0:f9b6112278fe | 110 | }; |
DieterGraef | 0:f9b6112278fe | 111 | |
DieterGraef | 0:f9b6112278fe | 112 | #if LWIP_SUPPORT_CUSTOM_PBUF |
DieterGraef | 0:f9b6112278fe | 113 | /** Prototype for a function to free a custom pbuf */ |
DieterGraef | 0:f9b6112278fe | 114 | typedef void (*pbuf_free_custom_fn)(struct pbuf *p); |
DieterGraef | 0:f9b6112278fe | 115 | |
DieterGraef | 0:f9b6112278fe | 116 | /** A custom pbuf: like a pbuf, but following a function pointer to free it. */ |
DieterGraef | 0:f9b6112278fe | 117 | struct pbuf_custom { |
DieterGraef | 0:f9b6112278fe | 118 | /** The actual pbuf */ |
DieterGraef | 0:f9b6112278fe | 119 | struct pbuf pbuf; |
DieterGraef | 0:f9b6112278fe | 120 | /** This function is called when pbuf_free deallocates this pbuf(_custom) */ |
DieterGraef | 0:f9b6112278fe | 121 | pbuf_free_custom_fn custom_free_function; |
DieterGraef | 0:f9b6112278fe | 122 | }; |
DieterGraef | 0:f9b6112278fe | 123 | #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ |
DieterGraef | 0:f9b6112278fe | 124 | |
DieterGraef | 0:f9b6112278fe | 125 | #if LWIP_TCP && TCP_QUEUE_OOSEQ |
DieterGraef | 0:f9b6112278fe | 126 | /** Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty */ |
DieterGraef | 0:f9b6112278fe | 127 | #ifndef PBUF_POOL_FREE_OOSEQ |
DieterGraef | 0:f9b6112278fe | 128 | #define PBUF_POOL_FREE_OOSEQ 1 |
DieterGraef | 0:f9b6112278fe | 129 | #endif /* PBUF_POOL_FREE_OOSEQ */ |
DieterGraef | 0:f9b6112278fe | 130 | #if NO_SYS && PBUF_POOL_FREE_OOSEQ |
DieterGraef | 0:f9b6112278fe | 131 | extern volatile u8_t pbuf_free_ooseq_pending; |
DieterGraef | 0:f9b6112278fe | 132 | void pbuf_free_ooseq(); |
DieterGraef | 0:f9b6112278fe | 133 | /** When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ() |
DieterGraef | 0:f9b6112278fe | 134 | at regular intervals from main level to check if ooseq pbufs need to be |
DieterGraef | 0:f9b6112278fe | 135 | freed! */ |
DieterGraef | 0:f9b6112278fe | 136 | #define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \ |
DieterGraef | 0:f9b6112278fe | 137 | /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \ |
DieterGraef | 0:f9b6112278fe | 138 | ooseq queued pbufs now */ \ |
DieterGraef | 0:f9b6112278fe | 139 | pbuf_free_ooseq(); }}while(0) |
DieterGraef | 0:f9b6112278fe | 140 | #endif /* NO_SYS && PBUF_POOL_FREE_OOSEQ*/ |
DieterGraef | 0:f9b6112278fe | 141 | #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ */ |
DieterGraef | 0:f9b6112278fe | 142 | |
DieterGraef | 0:f9b6112278fe | 143 | /* Initializes the pbuf module. This call is empty for now, but may not be in future. */ |
DieterGraef | 0:f9b6112278fe | 144 | #define pbuf_init() |
DieterGraef | 0:f9b6112278fe | 145 | |
DieterGraef | 0:f9b6112278fe | 146 | struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type); |
DieterGraef | 0:f9b6112278fe | 147 | #if LWIP_SUPPORT_CUSTOM_PBUF |
DieterGraef | 0:f9b6112278fe | 148 | struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, |
DieterGraef | 0:f9b6112278fe | 149 | struct pbuf_custom *p, void *payload_mem, |
DieterGraef | 0:f9b6112278fe | 150 | u16_t payload_mem_len); |
DieterGraef | 0:f9b6112278fe | 151 | #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ |
DieterGraef | 0:f9b6112278fe | 152 | void pbuf_realloc(struct pbuf *p, u16_t size); |
DieterGraef | 0:f9b6112278fe | 153 | u8_t pbuf_header(struct pbuf *p, s16_t header_size); |
DieterGraef | 0:f9b6112278fe | 154 | void pbuf_ref(struct pbuf *p); |
DieterGraef | 0:f9b6112278fe | 155 | u8_t pbuf_free(struct pbuf *p); |
DieterGraef | 0:f9b6112278fe | 156 | u8_t pbuf_clen(struct pbuf *p); |
DieterGraef | 0:f9b6112278fe | 157 | void pbuf_cat(struct pbuf *head, struct pbuf *tail); |
DieterGraef | 0:f9b6112278fe | 158 | void pbuf_chain(struct pbuf *head, struct pbuf *tail); |
DieterGraef | 0:f9b6112278fe | 159 | struct pbuf *pbuf_dechain(struct pbuf *p); |
DieterGraef | 0:f9b6112278fe | 160 | err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from); |
DieterGraef | 0:f9b6112278fe | 161 | u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset); |
DieterGraef | 0:f9b6112278fe | 162 | err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len); |
DieterGraef | 0:f9b6112278fe | 163 | struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer); |
DieterGraef | 0:f9b6112278fe | 164 | #if LWIP_CHECKSUM_ON_COPY |
DieterGraef | 0:f9b6112278fe | 165 | err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, |
DieterGraef | 0:f9b6112278fe | 166 | u16_t len, u16_t *chksum); |
DieterGraef | 0:f9b6112278fe | 167 | #endif /* LWIP_CHECKSUM_ON_COPY */ |
DieterGraef | 0:f9b6112278fe | 168 | |
DieterGraef | 0:f9b6112278fe | 169 | u8_t pbuf_get_at(struct pbuf* p, u16_t offset); |
DieterGraef | 0:f9b6112278fe | 170 | u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n); |
DieterGraef | 0:f9b6112278fe | 171 | u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset); |
DieterGraef | 0:f9b6112278fe | 172 | u16_t pbuf_strstr(struct pbuf* p, const char* substr); |
DieterGraef | 0:f9b6112278fe | 173 | |
DieterGraef | 0:f9b6112278fe | 174 | #ifdef __cplusplus |
DieterGraef | 0:f9b6112278fe | 175 | } |
DieterGraef | 0:f9b6112278fe | 176 | #endif |
DieterGraef | 0:f9b6112278fe | 177 | |
DieterGraef | 0:f9b6112278fe | 178 | #endif /* __LWIP_PBUF_H__ */ |