Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

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