Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

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