Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
ethaderu
Date:
Tue Mar 05 02:34:44 2019 +0000
Revision:
3:78f223d34f36
Publish 1

Who changed what in which revision?

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