Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed

Dependencies:   mbed

Committer:
pehrhovey
Date:
Sun Mar 14 00:54:12 2010 +0000
Revision:
0:a548a085de55

        

Who changed what in which revision?

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