V1

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
lemniskata
Date:
Thu Jun 13 20:00:31 2013 +0000
Revision:
11:c9233fe7de67
Parent:
0:51ac1d130fd4
V1

Who changed what in which revision?

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