Leest de waarde van een sensor binnen een maakt deze beschikbaar via internet

Dependencies:   NTPClient_NetServices mbed

Committer:
hendrikvincent
Date:
Mon Dec 02 09:01:23 2013 +0000
Revision:
0:05ccbd4f84f1
eerste programma;

Who changed what in which revision?

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