Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

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