Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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