SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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