Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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