Free (GPLv2) TCP/IP stack developed by TASS Belgium
Dependents: lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more
PicoTCP. Copyright (c) 2013 TASS Belgium NV.
Released under the GNU General Public License, version 2.
Different licensing models may exist, at the sole discretion of the Copyright holders.
Official homepage: http://www.picotcp.com
Bug tracker: https://github.com/tass-belgium/picotcp/issues
Development steps:
initial integration with mbed RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling optimizations- Debugging/benchmarking/testing
Demo application (measuring TCP sender performance):
Import programlpc1768-picotcp-demo
A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.
Diff: modules/pico_udp.c
- Revision:
- 149:5f4cb161cec3
- Parent:
- 131:4758606c9316
- Child:
- 152:a3d286bf94e5
--- a/modules/pico_udp.c Tue Mar 11 15:34:51 2014 +0100 +++ b/modules/pico_udp.c Wed Apr 09 14:31:41 2014 +0200 @@ -14,6 +14,8 @@ #include "pico_socket.h" #include "pico_stack.h" +#define UDP_FRAME_OVERHEAD (sizeof(struct pico_frame)) + /* Queues */ static struct pico_queue udp_in = { @@ -52,31 +54,65 @@ return pico_dualbuffer_checksum(&pseudo, sizeof(struct pico_ipv4_pseudo_hdr), udp_hdr, f->transport_len); } +#ifdef PICO_SUPPORT_IPV6 +uint16_t pico_udp_checksum_ipv6(struct pico_frame *f) +{ + struct pico_ipv6_hdr *ipv6_hdr = (struct pico_ipv6_hdr *)f->net_hdr; + struct pico_udp_hdr *udp_hdr = (struct pico_udp_hdr *)f->transport_hdr; + struct pico_ipv6_pseudo_hdr pseudo; + struct pico_socket *s = f->sock; + struct pico_remote_endpoint *remote_endpoint = (struct pico_remote_endpoint *)f->info; + + /* XXX If the IPv6 packet contains a Routing header, the Destination + * Address used in the pseudo-header is that of the final destination */ + if (s) { + /* Case of outgoing frame */ + pseudo.src = s->local_addr.ip6; + if (remote_endpoint) + pseudo.dst = remote_endpoint->remote_addr.ip6; + else + pseudo.dst = s->remote_addr.ip6; + } else { + /* Case of incomming frame */ + pseudo.src = ipv6_hdr->src; + pseudo.dst = ipv6_hdr->dst; + } + + pseudo.len = long_be(f->transport_len); + pseudo.nxthdr = PICO_PROTO_UDP; + + return pico_dualbuffer_checksum(&pseudo, sizeof(struct pico_ipv6_pseudo_hdr), udp_hdr, f->transport_len); +} +#endif + + static int pico_udp_process_out(struct pico_protocol *self, struct pico_frame *f) { IGNORE_PARAMETER(self); - return pico_network_send(f); + return (int)pico_network_send(f); } static int pico_udp_push(struct pico_protocol *self, struct pico_frame *f) { struct pico_udp_hdr *hdr = (struct pico_udp_hdr *) f->transport_hdr; - struct pico_remote_duple *remote_duple = (struct pico_remote_duple *) f->info; + struct pico_remote_endpoint *remote_endpoint = (struct pico_remote_endpoint *) f->info; /* this (fragmented) frame should contain a transport header */ if (f->transport_hdr != f->payload) { hdr->trans.sport = f->sock->local_port; - if (remote_duple) { - hdr->trans.dport = remote_duple->remote_port; + if (remote_endpoint) { + hdr->trans.dport = remote_endpoint->remote_port; } else { hdr->trans.dport = f->sock->remote_port; } hdr->len = short_be(f->transport_len); + /* do not perform CRC validation. If you want to, a system needs to be implemented to calculate the CRC over the total payload of a - fragmented payload */ + fragmented payload + */ hdr->crc = 0; } @@ -100,48 +136,10 @@ }; -#define PICO_UDP_MODE_UNICAST 0x01 -#define PICO_UDP_MODE_MULTICAST 0x02 -#define PICO_UDP_MODE_BROADCAST 0xFF - -struct pico_socket_udp -{ - struct pico_socket sock; - int mode; -#ifdef PICO_SUPPORT_MCAST - uint8_t mc_ttl; /* Multicasting TTL */ -#endif -}; - -#ifdef PICO_SUPPORT_MCAST -int pico_udp_set_mc_ttl(struct pico_socket *s, uint8_t ttl) -{ - struct pico_socket_udp *u; - if(!s) { - pico_err = PICO_ERR_EINVAL; - return -1; - } - - u = (struct pico_socket_udp *) s; - u->mc_ttl = ttl; - return 0; -} - -int pico_udp_get_mc_ttl(struct pico_socket *s, uint8_t *ttl) -{ - struct pico_socket_udp *u; - if(!s) - return -1; - - u = (struct pico_socket_udp *) s; - *ttl = u->mc_ttl; - return 0; -} -#endif /* PICO_SUPPORT_MCAST */ struct pico_socket *pico_udp_open(void) { - struct pico_socket_udp *u = pico_zalloc(sizeof(struct pico_socket_udp)); + struct pico_socket_udp *u = PICO_ZALLOC(sizeof(struct pico_socket_udp)); if (!u) return NULL; @@ -165,7 +163,7 @@ f->payload_len = (uint16_t)(f->transport_len - sizeof(struct pico_udp_hdr)); } -/* dbg("expected: %d, got: %d\n", len, f->payload_len); */ + /* dbg("expected: %d, got: %d\n", len, f->payload_len); */ if (src) pico_store_network_origin(src, f);