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