Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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