Donatien Garnier / EthernetNetIfBeta
Committer:
donatien
Date:
Mon Jul 26 16:25:55 2010 +0000
Revision:
0:7f97f2ad3030

        

Who changed what in which revision?

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