Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

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