Port to C027 (using AppShield and Ethernet)

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samdanbury 6:37b6d0d56190 1 /*
samdanbury 6:37b6d0d56190 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
samdanbury 6:37b6d0d56190 3 * All rights reserved.
samdanbury 6:37b6d0d56190 4 *
samdanbury 6:37b6d0d56190 5 * Redistribution and use in source and binary forms, with or without modification,
samdanbury 6:37b6d0d56190 6 * are permitted provided that the following conditions are met:
samdanbury 6:37b6d0d56190 7 *
samdanbury 6:37b6d0d56190 8 * 1. Redistributions of source code must retain the above copyright notice,
samdanbury 6:37b6d0d56190 9 * this list of conditions and the following disclaimer.
samdanbury 6:37b6d0d56190 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
samdanbury 6:37b6d0d56190 11 * this list of conditions and the following disclaimer in the documentation
samdanbury 6:37b6d0d56190 12 * and/or other materials provided with the distribution.
samdanbury 6:37b6d0d56190 13 * 3. The name of the author may not be used to endorse or promote products
samdanbury 6:37b6d0d56190 14 * derived from this software without specific prior written permission.
samdanbury 6:37b6d0d56190 15 *
samdanbury 6:37b6d0d56190 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
samdanbury 6:37b6d0d56190 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
samdanbury 6:37b6d0d56190 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
samdanbury 6:37b6d0d56190 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
samdanbury 6:37b6d0d56190 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
samdanbury 6:37b6d0d56190 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
samdanbury 6:37b6d0d56190 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
samdanbury 6:37b6d0d56190 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
samdanbury 6:37b6d0d56190 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
samdanbury 6:37b6d0d56190 25 * OF SUCH DAMAGE.
samdanbury 6:37b6d0d56190 26 *
samdanbury 6:37b6d0d56190 27 * This file is part of the lwIP TCP/IP stack.
samdanbury 6:37b6d0d56190 28 *
samdanbury 6:37b6d0d56190 29 * Author: Adam Dunkels <adam@sics.se>
samdanbury 6:37b6d0d56190 30 *
samdanbury 6:37b6d0d56190 31 */
samdanbury 6:37b6d0d56190 32 #ifndef __LWIP_NETBUF_H__
samdanbury 6:37b6d0d56190 33 #define __LWIP_NETBUF_H__
samdanbury 6:37b6d0d56190 34
samdanbury 6:37b6d0d56190 35 #include "lwip/opt.h"
samdanbury 6:37b6d0d56190 36 #include "lwip/pbuf.h"
samdanbury 6:37b6d0d56190 37 #include "lwip/ip_addr.h"
samdanbury 6:37b6d0d56190 38
samdanbury 6:37b6d0d56190 39 #ifdef __cplusplus
samdanbury 6:37b6d0d56190 40 extern "C" {
samdanbury 6:37b6d0d56190 41 #endif
samdanbury 6:37b6d0d56190 42
samdanbury 6:37b6d0d56190 43 /** This netbuf has dest-addr/port set */
samdanbury 6:37b6d0d56190 44 #define NETBUF_FLAG_DESTADDR 0x01
samdanbury 6:37b6d0d56190 45 /** This netbuf includes a checksum */
samdanbury 6:37b6d0d56190 46 #define NETBUF_FLAG_CHKSUM 0x02
samdanbury 6:37b6d0d56190 47
samdanbury 6:37b6d0d56190 48 struct netbuf {
samdanbury 6:37b6d0d56190 49 struct pbuf *p, *ptr;
samdanbury 6:37b6d0d56190 50 ip_addr_t addr;
samdanbury 6:37b6d0d56190 51 u16_t port;
samdanbury 6:37b6d0d56190 52 #if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
samdanbury 6:37b6d0d56190 53 #if LWIP_CHECKSUM_ON_COPY
samdanbury 6:37b6d0d56190 54 u8_t flags;
samdanbury 6:37b6d0d56190 55 #endif /* LWIP_CHECKSUM_ON_COPY */
samdanbury 6:37b6d0d56190 56 u16_t toport_chksum;
samdanbury 6:37b6d0d56190 57 #if LWIP_NETBUF_RECVINFO
samdanbury 6:37b6d0d56190 58 ip_addr_t toaddr;
samdanbury 6:37b6d0d56190 59 #endif /* LWIP_NETBUF_RECVINFO */
samdanbury 6:37b6d0d56190 60 #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
samdanbury 6:37b6d0d56190 61 };
samdanbury 6:37b6d0d56190 62
samdanbury 6:37b6d0d56190 63 /* Network buffer functions: */
samdanbury 6:37b6d0d56190 64 struct netbuf * netbuf_new (void);
samdanbury 6:37b6d0d56190 65 void netbuf_delete (struct netbuf *buf);
samdanbury 6:37b6d0d56190 66 void * netbuf_alloc (struct netbuf *buf, u16_t size);
samdanbury 6:37b6d0d56190 67 void netbuf_free (struct netbuf *buf);
samdanbury 6:37b6d0d56190 68 err_t netbuf_ref (struct netbuf *buf,
samdanbury 6:37b6d0d56190 69 const void *dataptr, u16_t size);
samdanbury 6:37b6d0d56190 70 void netbuf_chain (struct netbuf *head,
samdanbury 6:37b6d0d56190 71 struct netbuf *tail);
samdanbury 6:37b6d0d56190 72
samdanbury 6:37b6d0d56190 73 err_t netbuf_data (struct netbuf *buf,
samdanbury 6:37b6d0d56190 74 void **dataptr, u16_t *len);
samdanbury 6:37b6d0d56190 75 s8_t netbuf_next (struct netbuf *buf);
samdanbury 6:37b6d0d56190 76 void netbuf_first (struct netbuf *buf);
samdanbury 6:37b6d0d56190 77
samdanbury 6:37b6d0d56190 78
samdanbury 6:37b6d0d56190 79 #define netbuf_copy_partial(buf, dataptr, len, offset) \
samdanbury 6:37b6d0d56190 80 pbuf_copy_partial((buf)->p, (dataptr), (len), (offset))
samdanbury 6:37b6d0d56190 81 #define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0)
samdanbury 6:37b6d0d56190 82 #define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len)
samdanbury 6:37b6d0d56190 83 #define netbuf_len(buf) ((buf)->p->tot_len)
samdanbury 6:37b6d0d56190 84 #define netbuf_fromaddr(buf) (&((buf)->addr))
samdanbury 6:37b6d0d56190 85 #define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set((&(buf)->addr), fromaddr)
samdanbury 6:37b6d0d56190 86 #define netbuf_fromport(buf) ((buf)->port)
samdanbury 6:37b6d0d56190 87 #if LWIP_NETBUF_RECVINFO
samdanbury 6:37b6d0d56190 88 #define netbuf_destaddr(buf) (&((buf)->toaddr))
samdanbury 6:37b6d0d56190 89 #define netbuf_set_destaddr(buf, destaddr) ip_addr_set((&(buf)->addr), destaddr)
samdanbury 6:37b6d0d56190 90 #define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0)
samdanbury 6:37b6d0d56190 91 #endif /* LWIP_NETBUF_RECVINFO */
samdanbury 6:37b6d0d56190 92 #if LWIP_CHECKSUM_ON_COPY
samdanbury 6:37b6d0d56190 93 #define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \
samdanbury 6:37b6d0d56190 94 (buf)->toport_chksum = chksum; } while(0)
samdanbury 6:37b6d0d56190 95 #endif /* LWIP_CHECKSUM_ON_COPY */
samdanbury 6:37b6d0d56190 96
samdanbury 6:37b6d0d56190 97 #ifdef __cplusplus
samdanbury 6:37b6d0d56190 98 }
samdanbury 6:37b6d0d56190 99 #endif
samdanbury 6:37b6d0d56190 100
samdanbury 6:37b6d0d56190 101 #endif /* __LWIP_NETBUF_H__ */