A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Committer:
root@mbed.org
Date:
Tue May 08 15:32:10 2012 +0100
Revision:
0:5e1631496985
initial commit

Who changed what in which revision?

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