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