Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

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