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