Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:350011bf8be7 1 /*
simon 0:350011bf8be7 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
simon 0:350011bf8be7 3 * All rights reserved.
simon 0:350011bf8be7 4 *
simon 0:350011bf8be7 5 * Redistribution and use in source and binary forms, with or without modification,
simon 0:350011bf8be7 6 * are permitted provided that the following conditions are met:
simon 0:350011bf8be7 7 *
simon 0:350011bf8be7 8 * 1. Redistributions of source code must retain the above copyright notice,
simon 0:350011bf8be7 9 * this list of conditions and the following disclaimer.
simon 0:350011bf8be7 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
simon 0:350011bf8be7 11 * this list of conditions and the following disclaimer in the documentation
simon 0:350011bf8be7 12 * and/or other materials provided with the distribution.
simon 0:350011bf8be7 13 * 3. The name of the author may not be used to endorse or promote products
simon 0:350011bf8be7 14 * derived from this software without specific prior written permission.
simon 0:350011bf8be7 15 *
simon 0:350011bf8be7 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
simon 0:350011bf8be7 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
simon 0:350011bf8be7 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
simon 0:350011bf8be7 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
simon 0:350011bf8be7 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
simon 0:350011bf8be7 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
simon 0:350011bf8be7 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
simon 0:350011bf8be7 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
simon 0:350011bf8be7 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
simon 0:350011bf8be7 25 * OF SUCH DAMAGE.
simon 0:350011bf8be7 26 *
simon 0:350011bf8be7 27 * This file is part of the lwIP TCP/IP stack.
simon 0:350011bf8be7 28 *
simon 0:350011bf8be7 29 * Author: Adam Dunkels <adam@sics.se>
simon 0:350011bf8be7 30 *
simon 0:350011bf8be7 31 */
simon 0:350011bf8be7 32 #ifndef __LWIP_UDP_H__
simon 0:350011bf8be7 33 #define __LWIP_UDP_H__
simon 0:350011bf8be7 34
simon 0:350011bf8be7 35 #include "lwip/opt.h"
simon 0:350011bf8be7 36
simon 0:350011bf8be7 37 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
simon 0:350011bf8be7 38
simon 0:350011bf8be7 39 #include "lwip/pbuf.h"
simon 0:350011bf8be7 40 #include "lwip/netif.h"
simon 0:350011bf8be7 41 #include "lwip/ip_addr.h"
simon 0:350011bf8be7 42 #include "lwip/ip.h"
simon 0:350011bf8be7 43
simon 0:350011bf8be7 44 #ifdef __cplusplus
simon 0:350011bf8be7 45 extern "C" {
simon 0:350011bf8be7 46 #endif
simon 0:350011bf8be7 47
simon 0:350011bf8be7 48 #define UDP_HLEN 8
simon 0:350011bf8be7 49
simon 0:350011bf8be7 50 /* Fields are (of course) in network byte order. */
simon 0:350011bf8be7 51 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 52 # include "arch/bpstruct.h"
simon 0:350011bf8be7 53 #endif
simon 0:350011bf8be7 54 PACK_STRUCT_BEGIN
simon 0:350011bf8be7 55 struct udp_hdr {
simon 0:350011bf8be7 56 PACK_STRUCT_FIELD(u16_t src);
simon 0:350011bf8be7 57 PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
simon 0:350011bf8be7 58 PACK_STRUCT_FIELD(u16_t len);
simon 0:350011bf8be7 59 PACK_STRUCT_FIELD(u16_t chksum);
simon 0:350011bf8be7 60 } PACK_STRUCT_STRUCT;
simon 0:350011bf8be7 61 PACK_STRUCT_END
simon 0:350011bf8be7 62 #ifdef PACK_STRUCT_USE_INCLUDES
simon 0:350011bf8be7 63 # include "arch/epstruct.h"
simon 0:350011bf8be7 64 #endif
simon 0:350011bf8be7 65
simon 0:350011bf8be7 66 #define UDP_FLAGS_NOCHKSUM 0x01U
simon 0:350011bf8be7 67 #define UDP_FLAGS_UDPLITE 0x02U
simon 0:350011bf8be7 68 #define UDP_FLAGS_CONNECTED 0x04U
simon 0:350011bf8be7 69 #define UDP_FLAGS_MULTICAST_LOOP 0x08U
simon 0:350011bf8be7 70
simon 0:350011bf8be7 71 struct udp_pcb;
simon 0:350011bf8be7 72
simon 0:350011bf8be7 73 /** Function prototype for udp pcb receive callback functions
simon 0:350011bf8be7 74 * addr and port are in same byte order as in the pcb
simon 0:350011bf8be7 75 * The callback is responsible for freeing the pbuf
simon 0:350011bf8be7 76 * if it's not used any more.
simon 0:350011bf8be7 77 *
simon 0:350011bf8be7 78 * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf
simon 0:350011bf8be7 79 * makes 'addr' invalid, too.
simon 0:350011bf8be7 80 *
simon 0:350011bf8be7 81 * @param arg user supplied argument (udp_pcb.recv_arg)
simon 0:350011bf8be7 82 * @param pcb the udp_pcb which received data
simon 0:350011bf8be7 83 * @param p the packet buffer that was received
simon 0:350011bf8be7 84 * @param addr the remote IP address from which the packet was received
simon 0:350011bf8be7 85 * @param port the remote port from which the packet was received
simon 0:350011bf8be7 86 */
simon 0:350011bf8be7 87 typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
simon 0:350011bf8be7 88 ip_addr_t *addr, u16_t port);
simon 0:350011bf8be7 89
simon 0:350011bf8be7 90
simon 0:350011bf8be7 91 struct udp_pcb {
simon 0:350011bf8be7 92 /* Common members of all PCB types */
simon 0:350011bf8be7 93 IP_PCB;
simon 0:350011bf8be7 94
simon 0:350011bf8be7 95 /* Protocol specific PCB members */
simon 0:350011bf8be7 96
simon 0:350011bf8be7 97 struct udp_pcb *next;
simon 0:350011bf8be7 98
simon 0:350011bf8be7 99 u8_t flags;
simon 0:350011bf8be7 100 /** ports are in host byte order */
simon 0:350011bf8be7 101 u16_t local_port, remote_port;
simon 0:350011bf8be7 102
simon 0:350011bf8be7 103 #if LWIP_IGMP
simon 0:350011bf8be7 104 /** outgoing network interface for multicast packets */
simon 0:350011bf8be7 105 ip_addr_t multicast_ip;
simon 0:350011bf8be7 106 #endif /* LWIP_IGMP */
simon 0:350011bf8be7 107
simon 0:350011bf8be7 108 #if LWIP_UDPLITE
simon 0:350011bf8be7 109 /** used for UDP_LITE only */
simon 0:350011bf8be7 110 u16_t chksum_len_rx, chksum_len_tx;
simon 0:350011bf8be7 111 #endif /* LWIP_UDPLITE */
simon 0:350011bf8be7 112
simon 0:350011bf8be7 113 /** receive callback function */
simon 0:350011bf8be7 114 udp_recv_fn recv;
simon 0:350011bf8be7 115 /** user-supplied argument for the recv callback */
simon 0:350011bf8be7 116 void *recv_arg;
simon 0:350011bf8be7 117 };
simon 0:350011bf8be7 118 /* udp_pcbs export for exernal reference (e.g. SNMP agent) */
simon 0:350011bf8be7 119 extern struct udp_pcb *udp_pcbs;
simon 0:350011bf8be7 120
simon 0:350011bf8be7 121 /* The following functions is the application layer interface to the
simon 0:350011bf8be7 122 UDP code. */
simon 0:350011bf8be7 123 struct udp_pcb * udp_new (void);
simon 0:350011bf8be7 124 void udp_remove (struct udp_pcb *pcb);
simon 0:350011bf8be7 125 err_t udp_bind (struct udp_pcb *pcb, ip_addr_t *ipaddr,
simon 0:350011bf8be7 126 u16_t port);
simon 0:350011bf8be7 127 err_t udp_connect (struct udp_pcb *pcb, ip_addr_t *ipaddr,
simon 0:350011bf8be7 128 u16_t port);
simon 0:350011bf8be7 129 void udp_disconnect (struct udp_pcb *pcb);
simon 0:350011bf8be7 130 void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
simon 0:350011bf8be7 131 void *recv_arg);
simon 0:350011bf8be7 132 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p,
simon 0:350011bf8be7 133 ip_addr_t *dst_ip, u16_t dst_port,
simon 0:350011bf8be7 134 struct netif *netif);
simon 0:350011bf8be7 135 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
simon 0:350011bf8be7 136 ip_addr_t *dst_ip, u16_t dst_port);
simon 0:350011bf8be7 137 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
simon 0:350011bf8be7 138
simon 0:350011bf8be7 139 #if LWIP_CHECKSUM_ON_COPY
simon 0:350011bf8be7 140 err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p,
simon 0:350011bf8be7 141 ip_addr_t *dst_ip, u16_t dst_port,
simon 0:350011bf8be7 142 struct netif *netif, u8_t have_chksum,
simon 0:350011bf8be7 143 u16_t chksum);
simon 0:350011bf8be7 144 err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p,
simon 0:350011bf8be7 145 ip_addr_t *dst_ip, u16_t dst_port,
simon 0:350011bf8be7 146 u8_t have_chksum, u16_t chksum);
simon 0:350011bf8be7 147 err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
simon 0:350011bf8be7 148 u8_t have_chksum, u16_t chksum);
simon 0:350011bf8be7 149 #endif /* LWIP_CHECKSUM_ON_COPY */
simon 0:350011bf8be7 150
simon 0:350011bf8be7 151 #define udp_flags(pcb) ((pcb)->flags)
simon 0:350011bf8be7 152 #define udp_setflags(pcb, f) ((pcb)->flags = (f))
simon 0:350011bf8be7 153
simon 0:350011bf8be7 154 /* The following functions are the lower layer interface to UDP. */
simon 0:350011bf8be7 155 void udp_input (struct pbuf *p, struct netif *inp);
simon 0:350011bf8be7 156
simon 0:350011bf8be7 157 #define udp_init() /* Compatibility define, not init needed. */
simon 0:350011bf8be7 158
simon 0:350011bf8be7 159 #if UDP_DEBUG
simon 0:350011bf8be7 160 void udp_debug_print(struct udp_hdr *udphdr);
simon 0:350011bf8be7 161 #else
simon 0:350011bf8be7 162 #define udp_debug_print(udphdr)
simon 0:350011bf8be7 163 #endif
simon 0:350011bf8be7 164
simon 0:350011bf8be7 165 #ifdef __cplusplus
simon 0:350011bf8be7 166 }
simon 0:350011bf8be7 167 #endif
simon 0:350011bf8be7 168
simon 0:350011bf8be7 169 #endif /* LWIP_UDP */
simon 0:350011bf8be7 170
simon 0:350011bf8be7 171 #endif /* __LWIP_UDP_H__ */