Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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