Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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