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