NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Committer:
donatien
Date:
Tue Jul 27 15:59:42 2010 +0000
Revision:
5:dd63a1e02b1b
Parent:
0:632c9925f013

        

Who changed what in which revision?

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