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 #ifndef __LWIP_NETBUF_H__
GordonSin 0:0ed2a7c7190c 33 #define __LWIP_NETBUF_H__
GordonSin 0:0ed2a7c7190c 34
GordonSin 0:0ed2a7c7190c 35 #include "lwip/opt.h"
GordonSin 0:0ed2a7c7190c 36 #include "lwip/pbuf.h"
GordonSin 0:0ed2a7c7190c 37 #include "lwip/ip_addr.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 /** This netbuf has dest-addr/port set */
GordonSin 0:0ed2a7c7190c 44 #define NETBUF_FLAG_DESTADDR 0x01
GordonSin 0:0ed2a7c7190c 45 /** This netbuf includes a checksum */
GordonSin 0:0ed2a7c7190c 46 #define NETBUF_FLAG_CHKSUM 0x02
GordonSin 0:0ed2a7c7190c 47
GordonSin 0:0ed2a7c7190c 48 struct netbuf {
GordonSin 0:0ed2a7c7190c 49 struct pbuf *p, *ptr;
GordonSin 0:0ed2a7c7190c 50 ip_addr_t addr;
GordonSin 0:0ed2a7c7190c 51 u16_t port;
GordonSin 0:0ed2a7c7190c 52 #if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
GordonSin 0:0ed2a7c7190c 53 #if LWIP_CHECKSUM_ON_COPY
GordonSin 0:0ed2a7c7190c 54 u8_t flags;
GordonSin 0:0ed2a7c7190c 55 #endif /* LWIP_CHECKSUM_ON_COPY */
GordonSin 0:0ed2a7c7190c 56 u16_t toport_chksum;
GordonSin 0:0ed2a7c7190c 57 #if LWIP_NETBUF_RECVINFO
GordonSin 0:0ed2a7c7190c 58 ip_addr_t toaddr;
GordonSin 0:0ed2a7c7190c 59 #endif /* LWIP_NETBUF_RECVINFO */
GordonSin 0:0ed2a7c7190c 60 #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
GordonSin 0:0ed2a7c7190c 61 };
GordonSin 0:0ed2a7c7190c 62
GordonSin 0:0ed2a7c7190c 63 /* Network buffer functions: */
GordonSin 0:0ed2a7c7190c 64 struct netbuf * netbuf_new (void);
GordonSin 0:0ed2a7c7190c 65 void netbuf_delete (struct netbuf *buf);
GordonSin 0:0ed2a7c7190c 66 void * netbuf_alloc (struct netbuf *buf, u16_t size);
GordonSin 0:0ed2a7c7190c 67 void netbuf_free (struct netbuf *buf);
GordonSin 0:0ed2a7c7190c 68 err_t netbuf_ref (struct netbuf *buf,
GordonSin 0:0ed2a7c7190c 69 const void *dataptr, u16_t size);
GordonSin 0:0ed2a7c7190c 70 void netbuf_chain (struct netbuf *head,
GordonSin 0:0ed2a7c7190c 71 struct netbuf *tail);
GordonSin 0:0ed2a7c7190c 72
GordonSin 0:0ed2a7c7190c 73 err_t netbuf_data (struct netbuf *buf,
GordonSin 0:0ed2a7c7190c 74 void **dataptr, u16_t *len);
GordonSin 0:0ed2a7c7190c 75 s8_t netbuf_next (struct netbuf *buf);
GordonSin 0:0ed2a7c7190c 76 void netbuf_first (struct netbuf *buf);
GordonSin 0:0ed2a7c7190c 77
GordonSin 0:0ed2a7c7190c 78
GordonSin 0:0ed2a7c7190c 79 #define netbuf_copy_partial(buf, dataptr, len, offset) \
GordonSin 0:0ed2a7c7190c 80 pbuf_copy_partial((buf)->p, (dataptr), (len), (offset))
GordonSin 0:0ed2a7c7190c 81 #define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0)
GordonSin 0:0ed2a7c7190c 82 #define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len)
GordonSin 0:0ed2a7c7190c 83 #define netbuf_len(buf) ((buf)->p->tot_len)
GordonSin 0:0ed2a7c7190c 84 #define netbuf_fromaddr(buf) (&((buf)->addr))
GordonSin 0:0ed2a7c7190c 85 #define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set((&(buf)->addr), fromaddr)
GordonSin 0:0ed2a7c7190c 86 #define netbuf_fromport(buf) ((buf)->port)
GordonSin 0:0ed2a7c7190c 87 #if LWIP_NETBUF_RECVINFO
GordonSin 0:0ed2a7c7190c 88 #define netbuf_destaddr(buf) (&((buf)->toaddr))
GordonSin 0:0ed2a7c7190c 89 #define netbuf_set_destaddr(buf, destaddr) ip_addr_set((&(buf)->addr), destaddr)
GordonSin 0:0ed2a7c7190c 90 #define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0)
GordonSin 0:0ed2a7c7190c 91 #endif /* LWIP_NETBUF_RECVINFO */
GordonSin 0:0ed2a7c7190c 92 #if LWIP_CHECKSUM_ON_COPY
GordonSin 0:0ed2a7c7190c 93 #define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \
GordonSin 0:0ed2a7c7190c 94 (buf)->toport_chksum = chksum; } while(0)
GordonSin 0:0ed2a7c7190c 95 #endif /* LWIP_CHECKSUM_ON_COPY */
GordonSin 0:0ed2a7c7190c 96
GordonSin 0:0ed2a7c7190c 97 #ifdef __cplusplus
GordonSin 0:0ed2a7c7190c 98 }
GordonSin 0:0ed2a7c7190c 99 #endif
GordonSin 0:0ed2a7c7190c 100
GordonSin 0:0ed2a7c7190c 101 #endif /* __LWIP_NETBUF_H__ */