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