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-2003 Swedish Institute of Computer Science.
samdanbury 6:37b6d0d56190 3 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
samdanbury 6:37b6d0d56190 4 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
samdanbury 6:37b6d0d56190 5 * All rights reserved.
samdanbury 6:37b6d0d56190 6 *
samdanbury 6:37b6d0d56190 7 * Redistribution and use in source and binary forms, with or without modification,
samdanbury 6:37b6d0d56190 8 * are permitted provided that the following conditions are met:
samdanbury 6:37b6d0d56190 9 *
samdanbury 6:37b6d0d56190 10 * 1. Redistributions of source code must retain the above copyright notice,
samdanbury 6:37b6d0d56190 11 * this list of conditions and the following disclaimer.
samdanbury 6:37b6d0d56190 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
samdanbury 6:37b6d0d56190 13 * this list of conditions and the following disclaimer in the documentation
samdanbury 6:37b6d0d56190 14 * and/or other materials provided with the distribution.
samdanbury 6:37b6d0d56190 15 * 3. The name of the author may not be used to endorse or promote products
samdanbury 6:37b6d0d56190 16 * derived from this software without specific prior written permission.
samdanbury 6:37b6d0d56190 17 *
samdanbury 6:37b6d0d56190 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
samdanbury 6:37b6d0d56190 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
samdanbury 6:37b6d0d56190 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
samdanbury 6:37b6d0d56190 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
samdanbury 6:37b6d0d56190 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
samdanbury 6:37b6d0d56190 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
samdanbury 6:37b6d0d56190 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
samdanbury 6:37b6d0d56190 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
samdanbury 6:37b6d0d56190 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
samdanbury 6:37b6d0d56190 27 * OF SUCH DAMAGE.
samdanbury 6:37b6d0d56190 28 *
samdanbury 6:37b6d0d56190 29 * This file is part of the lwIP TCP/IP stack.
samdanbury 6:37b6d0d56190 30 *
samdanbury 6:37b6d0d56190 31 * Author: Adam Dunkels <adam@sics.se>
samdanbury 6:37b6d0d56190 32 *
samdanbury 6:37b6d0d56190 33 */
samdanbury 6:37b6d0d56190 34
samdanbury 6:37b6d0d56190 35 #ifndef __NETIF_ETHARP_H__
samdanbury 6:37b6d0d56190 36 #define __NETIF_ETHARP_H__
samdanbury 6:37b6d0d56190 37
samdanbury 6:37b6d0d56190 38 #include "lwip/opt.h"
samdanbury 6:37b6d0d56190 39
samdanbury 6:37b6d0d56190 40 #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
samdanbury 6:37b6d0d56190 41
samdanbury 6:37b6d0d56190 42 #include "lwip/pbuf.h"
samdanbury 6:37b6d0d56190 43 #include "lwip/ip_addr.h"
samdanbury 6:37b6d0d56190 44 #include "lwip/netif.h"
samdanbury 6:37b6d0d56190 45 #include "lwip/ip.h"
samdanbury 6:37b6d0d56190 46
samdanbury 6:37b6d0d56190 47 #ifdef __cplusplus
samdanbury 6:37b6d0d56190 48 extern "C" {
samdanbury 6:37b6d0d56190 49 #endif
samdanbury 6:37b6d0d56190 50
samdanbury 6:37b6d0d56190 51 #ifndef ETHARP_HWADDR_LEN
samdanbury 6:37b6d0d56190 52 #define ETHARP_HWADDR_LEN 6
samdanbury 6:37b6d0d56190 53 #endif
samdanbury 6:37b6d0d56190 54
samdanbury 6:37b6d0d56190 55 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 56 # include "arch/bpstruct.h"
samdanbury 6:37b6d0d56190 57 #endif
samdanbury 6:37b6d0d56190 58 PACK_STRUCT_BEGIN
samdanbury 6:37b6d0d56190 59 struct eth_addr {
samdanbury 6:37b6d0d56190 60 PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
samdanbury 6:37b6d0d56190 61 } PACK_STRUCT_STRUCT;
samdanbury 6:37b6d0d56190 62 PACK_STRUCT_END
samdanbury 6:37b6d0d56190 63 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 64 # include "arch/epstruct.h"
samdanbury 6:37b6d0d56190 65 #endif
samdanbury 6:37b6d0d56190 66
samdanbury 6:37b6d0d56190 67 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 68 # include "arch/bpstruct.h"
samdanbury 6:37b6d0d56190 69 #endif
samdanbury 6:37b6d0d56190 70 PACK_STRUCT_BEGIN
samdanbury 6:37b6d0d56190 71 /** Ethernet header */
samdanbury 6:37b6d0d56190 72 struct eth_hdr {
samdanbury 6:37b6d0d56190 73 #if ETH_PAD_SIZE
samdanbury 6:37b6d0d56190 74 PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
samdanbury 6:37b6d0d56190 75 #endif
samdanbury 6:37b6d0d56190 76 PACK_STRUCT_FIELD(struct eth_addr dest);
samdanbury 6:37b6d0d56190 77 PACK_STRUCT_FIELD(struct eth_addr src);
samdanbury 6:37b6d0d56190 78 PACK_STRUCT_FIELD(u16_t type);
samdanbury 6:37b6d0d56190 79 } PACK_STRUCT_STRUCT;
samdanbury 6:37b6d0d56190 80 PACK_STRUCT_END
samdanbury 6:37b6d0d56190 81 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 82 # include "arch/epstruct.h"
samdanbury 6:37b6d0d56190 83 #endif
samdanbury 6:37b6d0d56190 84
samdanbury 6:37b6d0d56190 85 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
samdanbury 6:37b6d0d56190 86
samdanbury 6:37b6d0d56190 87 #if ETHARP_SUPPORT_VLAN
samdanbury 6:37b6d0d56190 88
samdanbury 6:37b6d0d56190 89 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 90 # include "arch/bpstruct.h"
samdanbury 6:37b6d0d56190 91 #endif
samdanbury 6:37b6d0d56190 92 PACK_STRUCT_BEGIN
samdanbury 6:37b6d0d56190 93 /** VLAN header inserted between ethernet header and payload
samdanbury 6:37b6d0d56190 94 * if 'type' in ethernet header is ETHTYPE_VLAN.
samdanbury 6:37b6d0d56190 95 * See IEEE802.Q */
samdanbury 6:37b6d0d56190 96 struct eth_vlan_hdr {
samdanbury 6:37b6d0d56190 97 PACK_STRUCT_FIELD(u16_t prio_vid);
samdanbury 6:37b6d0d56190 98 PACK_STRUCT_FIELD(u16_t tpid);
samdanbury 6:37b6d0d56190 99 } PACK_STRUCT_STRUCT;
samdanbury 6:37b6d0d56190 100 PACK_STRUCT_END
samdanbury 6:37b6d0d56190 101 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 102 # include "arch/epstruct.h"
samdanbury 6:37b6d0d56190 103 #endif
samdanbury 6:37b6d0d56190 104
samdanbury 6:37b6d0d56190 105 #define SIZEOF_VLAN_HDR 4
samdanbury 6:37b6d0d56190 106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
samdanbury 6:37b6d0d56190 107
samdanbury 6:37b6d0d56190 108 #endif /* ETHARP_SUPPORT_VLAN */
samdanbury 6:37b6d0d56190 109
samdanbury 6:37b6d0d56190 110 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 111 # include "arch/bpstruct.h"
samdanbury 6:37b6d0d56190 112 #endif
samdanbury 6:37b6d0d56190 113 PACK_STRUCT_BEGIN
samdanbury 6:37b6d0d56190 114 /** the ARP message, see RFC 826 ("Packet format") */
samdanbury 6:37b6d0d56190 115 struct etharp_hdr {
samdanbury 6:37b6d0d56190 116 PACK_STRUCT_FIELD(u16_t hwtype);
samdanbury 6:37b6d0d56190 117 PACK_STRUCT_FIELD(u16_t proto);
samdanbury 6:37b6d0d56190 118 PACK_STRUCT_FIELD(u8_t hwlen);
samdanbury 6:37b6d0d56190 119 PACK_STRUCT_FIELD(u8_t protolen);
samdanbury 6:37b6d0d56190 120 PACK_STRUCT_FIELD(u16_t opcode);
samdanbury 6:37b6d0d56190 121 PACK_STRUCT_FIELD(struct eth_addr shwaddr);
samdanbury 6:37b6d0d56190 122 PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
samdanbury 6:37b6d0d56190 123 PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
samdanbury 6:37b6d0d56190 124 PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
samdanbury 6:37b6d0d56190 125 } PACK_STRUCT_STRUCT;
samdanbury 6:37b6d0d56190 126 PACK_STRUCT_END
samdanbury 6:37b6d0d56190 127 #ifdef PACK_STRUCT_USE_INCLUDES
samdanbury 6:37b6d0d56190 128 # include "arch/epstruct.h"
samdanbury 6:37b6d0d56190 129 #endif
samdanbury 6:37b6d0d56190 130
samdanbury 6:37b6d0d56190 131 #define SIZEOF_ETHARP_HDR 28
samdanbury 6:37b6d0d56190 132 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
samdanbury 6:37b6d0d56190 133
samdanbury 6:37b6d0d56190 134 /** 5 seconds period */
samdanbury 6:37b6d0d56190 135 #define ARP_TMR_INTERVAL 5000
samdanbury 6:37b6d0d56190 136
samdanbury 6:37b6d0d56190 137 #define ETHTYPE_ARP 0x0806U
samdanbury 6:37b6d0d56190 138 #define ETHTYPE_IP 0x0800U
samdanbury 6:37b6d0d56190 139 #define ETHTYPE_VLAN 0x8100U
samdanbury 6:37b6d0d56190 140 #define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */
samdanbury 6:37b6d0d56190 141 #define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */
samdanbury 6:37b6d0d56190 142
samdanbury 6:37b6d0d56190 143 /** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
samdanbury 6:37b6d0d56190 144 * or known to be 32-bit aligned within the protocol header. */
samdanbury 6:37b6d0d56190 145 #ifndef ETHADDR32_COPY
samdanbury 6:37b6d0d56190 146 #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
samdanbury 6:37b6d0d56190 147 #endif
samdanbury 6:37b6d0d56190 148
samdanbury 6:37b6d0d56190 149 /** MEMCPY-like macro to copy to/from struct eth_addr's that are no local
samdanbury 6:37b6d0d56190 150 * variables and known to be 16-bit aligned within the protocol header. */
samdanbury 6:37b6d0d56190 151 #ifndef ETHADDR16_COPY
samdanbury 6:37b6d0d56190 152 #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
samdanbury 6:37b6d0d56190 153 #endif
samdanbury 6:37b6d0d56190 154
samdanbury 6:37b6d0d56190 155 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
samdanbury 6:37b6d0d56190 156
samdanbury 6:37b6d0d56190 157 /** ARP message types (opcodes) */
samdanbury 6:37b6d0d56190 158 #define ARP_REQUEST 1
samdanbury 6:37b6d0d56190 159 #define ARP_REPLY 2
samdanbury 6:37b6d0d56190 160
samdanbury 6:37b6d0d56190 161 /** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
samdanbury 6:37b6d0d56190 162 * to a filter function that returns the correct netif when using multiple
samdanbury 6:37b6d0d56190 163 * netifs on one hardware interface where the netif's low-level receive
samdanbury 6:37b6d0d56190 164 * routine cannot decide for the correct netif (e.g. when mapping multiple
samdanbury 6:37b6d0d56190 165 * IP addresses to one hardware interface).
samdanbury 6:37b6d0d56190 166 */
samdanbury 6:37b6d0d56190 167 #ifndef LWIP_ARP_FILTER_NETIF
samdanbury 6:37b6d0d56190 168 #define LWIP_ARP_FILTER_NETIF 0
samdanbury 6:37b6d0d56190 169 #endif
samdanbury 6:37b6d0d56190 170
samdanbury 6:37b6d0d56190 171 #if ARP_QUEUEING
samdanbury 6:37b6d0d56190 172 /** struct for queueing outgoing packets for unknown address
samdanbury 6:37b6d0d56190 173 * defined here to be accessed by memp.h
samdanbury 6:37b6d0d56190 174 */
samdanbury 6:37b6d0d56190 175 struct etharp_q_entry {
samdanbury 6:37b6d0d56190 176 struct etharp_q_entry *next;
samdanbury 6:37b6d0d56190 177 struct pbuf *p;
samdanbury 6:37b6d0d56190 178 };
samdanbury 6:37b6d0d56190 179 #endif /* ARP_QUEUEING */
samdanbury 6:37b6d0d56190 180
samdanbury 6:37b6d0d56190 181 #define etharp_init() /* Compatibility define, not init needed. */
samdanbury 6:37b6d0d56190 182 void etharp_tmr(void);
samdanbury 6:37b6d0d56190 183 s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr,
samdanbury 6:37b6d0d56190 184 struct eth_addr **eth_ret, ip_addr_t **ip_ret);
samdanbury 6:37b6d0d56190 185 err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
samdanbury 6:37b6d0d56190 186 err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q);
samdanbury 6:37b6d0d56190 187 err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr);
samdanbury 6:37b6d0d56190 188 /** For Ethernet network interfaces, we might want to send "gratuitous ARP";
samdanbury 6:37b6d0d56190 189 * this is an ARP packet sent by a node in order to spontaneously cause other
samdanbury 6:37b6d0d56190 190 * nodes to update an entry in their ARP cache.
samdanbury 6:37b6d0d56190 191 * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
samdanbury 6:37b6d0d56190 192 #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
samdanbury 6:37b6d0d56190 193
samdanbury 6:37b6d0d56190 194 #if ETHARP_SUPPORT_STATIC_ENTRIES
samdanbury 6:37b6d0d56190 195 err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr);
samdanbury 6:37b6d0d56190 196 err_t etharp_remove_static_entry(ip_addr_t *ipaddr);
samdanbury 6:37b6d0d56190 197 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
samdanbury 6:37b6d0d56190 198
samdanbury 6:37b6d0d56190 199 #if LWIP_AUTOIP
samdanbury 6:37b6d0d56190 200 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
samdanbury 6:37b6d0d56190 201 const struct eth_addr *ethdst_addr,
samdanbury 6:37b6d0d56190 202 const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
samdanbury 6:37b6d0d56190 203 const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
samdanbury 6:37b6d0d56190 204 const u16_t opcode);
samdanbury 6:37b6d0d56190 205 #endif /* LWIP_AUTOIP */
samdanbury 6:37b6d0d56190 206
samdanbury 6:37b6d0d56190 207 #endif /* LWIP_ARP */
samdanbury 6:37b6d0d56190 208
samdanbury 6:37b6d0d56190 209 err_t ethernet_input(struct pbuf *p, struct netif *netif);
samdanbury 6:37b6d0d56190 210
samdanbury 6:37b6d0d56190 211 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
samdanbury 6:37b6d0d56190 212
samdanbury 6:37b6d0d56190 213 extern const struct eth_addr ethbroadcast, ethzero;
samdanbury 6:37b6d0d56190 214
samdanbury 6:37b6d0d56190 215 #ifdef __cplusplus
samdanbury 6:37b6d0d56190 216 }
samdanbury 6:37b6d0d56190 217 #endif
samdanbury 6:37b6d0d56190 218
samdanbury 6:37b6d0d56190 219 #endif /* LWIP_ARP || LWIP_ETHERNET */
samdanbury 6:37b6d0d56190 220
samdanbury 6:37b6d0d56190 221 #endif /* __NETIF_ARP_H__ */