HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

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