Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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