Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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