V1

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
lemniskata
Date:
Thu Jun 13 20:00:31 2013 +0000
Revision:
11:c9233fe7de67
Parent:
0:51ac1d130fd4
V1

Who changed what in which revision?

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