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