Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested

Dependents:   STM32F746_iothub_client_sample_mqtt DISCO-F746NG_Ethernet Nucleo_F746ZG_Ethernet thethingsiO-DISCO_F746NG-mqtt ... more

Committer:
DieterGraef
Date:
Thu Jun 23 09:04:23 2016 +0000
Revision:
1:28ba13dd96f7
Parent:
0:d26c1b55cfca
corrected MAC issue. The MAC is now 02:00:00:xx:xx:xx where xx is the sum over the unique device register

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:d26c1b55cfca 1 /**
DieterGraef 0:d26c1b55cfca 2 * @file
DieterGraef 0:d26c1b55cfca 3 *
DieterGraef 0:d26c1b55cfca 4 * AutoIP Automatic LinkLocal IP Configuration
DieterGraef 0:d26c1b55cfca 5 */
DieterGraef 0:d26c1b55cfca 6
DieterGraef 0:d26c1b55cfca 7 /*
DieterGraef 0:d26c1b55cfca 8 *
DieterGraef 0:d26c1b55cfca 9 * Copyright (c) 2007 Dominik Spies <kontakt@dspies.de>
DieterGraef 0:d26c1b55cfca 10 * All rights reserved.
DieterGraef 0:d26c1b55cfca 11 *
DieterGraef 0:d26c1b55cfca 12 * Redistribution and use in source and binary forms, with or without modification,
DieterGraef 0:d26c1b55cfca 13 * are permitted provided that the following conditions are met:
DieterGraef 0:d26c1b55cfca 14 *
DieterGraef 0:d26c1b55cfca 15 * 1. Redistributions of source code must retain the above copyright notice,
DieterGraef 0:d26c1b55cfca 16 * this list of conditions and the following disclaimer.
DieterGraef 0:d26c1b55cfca 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
DieterGraef 0:d26c1b55cfca 18 * this list of conditions and the following disclaimer in the documentation
DieterGraef 0:d26c1b55cfca 19 * and/or other materials provided with the distribution.
DieterGraef 0:d26c1b55cfca 20 * 3. The name of the author may not be used to endorse or promote products
DieterGraef 0:d26c1b55cfca 21 * derived from this software without specific prior written permission.
DieterGraef 0:d26c1b55cfca 22 *
DieterGraef 0:d26c1b55cfca 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
DieterGraef 0:d26c1b55cfca 24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
DieterGraef 0:d26c1b55cfca 25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
DieterGraef 0:d26c1b55cfca 26 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
DieterGraef 0:d26c1b55cfca 27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
DieterGraef 0:d26c1b55cfca 28 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
DieterGraef 0:d26c1b55cfca 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
DieterGraef 0:d26c1b55cfca 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
DieterGraef 0:d26c1b55cfca 31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
DieterGraef 0:d26c1b55cfca 32 * OF SUCH DAMAGE.
DieterGraef 0:d26c1b55cfca 33 *
DieterGraef 0:d26c1b55cfca 34 * Author: Dominik Spies <kontakt@dspies.de>
DieterGraef 0:d26c1b55cfca 35 *
DieterGraef 0:d26c1b55cfca 36 * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
DieterGraef 0:d26c1b55cfca 37 * with RFC 3927.
DieterGraef 0:d26c1b55cfca 38 *
DieterGraef 0:d26c1b55cfca 39 *
DieterGraef 0:d26c1b55cfca 40 * Please coordinate changes and requests with Dominik Spies
DieterGraef 0:d26c1b55cfca 41 * <kontakt@dspies.de>
DieterGraef 0:d26c1b55cfca 42 */
DieterGraef 0:d26c1b55cfca 43
DieterGraef 0:d26c1b55cfca 44 #ifndef __LWIP_AUTOIP_H__
DieterGraef 0:d26c1b55cfca 45 #define __LWIP_AUTOIP_H__
DieterGraef 0:d26c1b55cfca 46
DieterGraef 0:d26c1b55cfca 47 #include "lwip/opt.h"
DieterGraef 0:d26c1b55cfca 48
DieterGraef 0:d26c1b55cfca 49 #if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
DieterGraef 0:d26c1b55cfca 50
DieterGraef 0:d26c1b55cfca 51 #include "lwip/netif.h"
DieterGraef 0:d26c1b55cfca 52 #include "lwip/udp.h"
DieterGraef 0:d26c1b55cfca 53 #include "netif/etharp.h"
DieterGraef 0:d26c1b55cfca 54
DieterGraef 0:d26c1b55cfca 55 #ifdef __cplusplus
DieterGraef 0:d26c1b55cfca 56 extern "C" {
DieterGraef 0:d26c1b55cfca 57 #endif
DieterGraef 0:d26c1b55cfca 58
DieterGraef 0:d26c1b55cfca 59 /* AutoIP Timing */
DieterGraef 0:d26c1b55cfca 60 #define AUTOIP_TMR_INTERVAL 100
DieterGraef 0:d26c1b55cfca 61 #define AUTOIP_TICKS_PER_SECOND (1000 / AUTOIP_TMR_INTERVAL)
DieterGraef 0:d26c1b55cfca 62
DieterGraef 0:d26c1b55cfca 63 /* RFC 3927 Constants */
DieterGraef 0:d26c1b55cfca 64 #define PROBE_WAIT 1 /* second (initial random delay) */
DieterGraef 0:d26c1b55cfca 65 #define PROBE_MIN 1 /* second (minimum delay till repeated probe) */
DieterGraef 0:d26c1b55cfca 66 #define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */
DieterGraef 0:d26c1b55cfca 67 #define PROBE_NUM 3 /* (number of probe packets) */
DieterGraef 0:d26c1b55cfca 68 #define ANNOUNCE_NUM 2 /* (number of announcement packets) */
DieterGraef 0:d26c1b55cfca 69 #define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */
DieterGraef 0:d26c1b55cfca 70 #define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */
DieterGraef 0:d26c1b55cfca 71 #define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */
DieterGraef 0:d26c1b55cfca 72 #define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */
DieterGraef 0:d26c1b55cfca 73 #define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */
DieterGraef 0:d26c1b55cfca 74
DieterGraef 0:d26c1b55cfca 75 /* AutoIP client states */
DieterGraef 0:d26c1b55cfca 76 #define AUTOIP_STATE_OFF 0
DieterGraef 0:d26c1b55cfca 77 #define AUTOIP_STATE_PROBING 1
DieterGraef 0:d26c1b55cfca 78 #define AUTOIP_STATE_ANNOUNCING 2
DieterGraef 0:d26c1b55cfca 79 #define AUTOIP_STATE_BOUND 3
DieterGraef 0:d26c1b55cfca 80
DieterGraef 0:d26c1b55cfca 81 struct autoip
DieterGraef 0:d26c1b55cfca 82 {
DieterGraef 0:d26c1b55cfca 83 ip_addr_t llipaddr; /* the currently selected, probed, announced or used LL IP-Address */
DieterGraef 0:d26c1b55cfca 84 u8_t state; /* current AutoIP state machine state */
DieterGraef 0:d26c1b55cfca 85 u8_t sent_num; /* sent number of probes or announces, dependent on state */
DieterGraef 0:d26c1b55cfca 86 u16_t ttw; /* ticks to wait, tick is AUTOIP_TMR_INTERVAL long */
DieterGraef 0:d26c1b55cfca 87 u8_t lastconflict; /* ticks until a conflict can be solved by defending */
DieterGraef 0:d26c1b55cfca 88 u8_t tried_llipaddr; /* total number of probed/used Link Local IP-Addresses */
DieterGraef 0:d26c1b55cfca 89 };
DieterGraef 0:d26c1b55cfca 90
DieterGraef 0:d26c1b55cfca 91
DieterGraef 0:d26c1b55cfca 92 #define autoip_init() /* Compatibility define, no init needed. */
DieterGraef 0:d26c1b55cfca 93
DieterGraef 0:d26c1b55cfca 94 /** Set a struct autoip allocated by the application to work with */
DieterGraef 0:d26c1b55cfca 95 void autoip_set_struct(struct netif *netif, struct autoip *autoip);
DieterGraef 0:d26c1b55cfca 96
DieterGraef 0:d26c1b55cfca 97 /** Start AutoIP client */
DieterGraef 0:d26c1b55cfca 98 err_t autoip_start(struct netif *netif);
DieterGraef 0:d26c1b55cfca 99
DieterGraef 0:d26c1b55cfca 100 /** Stop AutoIP client */
DieterGraef 0:d26c1b55cfca 101 err_t autoip_stop(struct netif *netif);
DieterGraef 0:d26c1b55cfca 102
DieterGraef 0:d26c1b55cfca 103 /** Handles every incoming ARP Packet, called by etharp_arp_input */
DieterGraef 0:d26c1b55cfca 104 void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr);
DieterGraef 0:d26c1b55cfca 105
DieterGraef 0:d26c1b55cfca 106 /** Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds */
DieterGraef 0:d26c1b55cfca 107 void autoip_tmr(void);
DieterGraef 0:d26c1b55cfca 108
DieterGraef 0:d26c1b55cfca 109 /** Handle a possible change in the network configuration */
DieterGraef 0:d26c1b55cfca 110 void autoip_network_changed(struct netif *netif);
DieterGraef 0:d26c1b55cfca 111
DieterGraef 0:d26c1b55cfca 112 #ifdef __cplusplus
DieterGraef 0:d26c1b55cfca 113 }
DieterGraef 0:d26c1b55cfca 114 #endif
DieterGraef 0:d26c1b55cfca 115
DieterGraef 0:d26c1b55cfca 116 #endif /* LWIP_AUTOIP */
DieterGraef 0:d26c1b55cfca 117
DieterGraef 0:d26c1b55cfca 118 #endif /* __LWIP_AUTOIP_H__ */