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