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