Dependencies:   mbed

Committer:
slowness
Date:
Tue Sep 06 18:10:36 2011 +0000
Revision:
0:cd4c47744fa1

        

Who changed what in which revision?

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