diff --git a/Makefile.dep b/Makefile.dep index cef86d98a3878d58e5f1412b4fd6e0903ce75901..3bc6d2bd6ac60d09852fdfa7520130483ec52631 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -154,6 +154,7 @@ endif ifneq (,$(filter ng_udp,$(USEMODULE))) USEMODULE += ng_netbase USEMODULE += inet_csum + USEMODULE += udp endif ifneq (,$(filter ng_nettest,$(USEMODULE))) diff --git a/sys/Makefile b/sys/Makefile index bcde17877f42ef35e6cdb9cd8ee14c00959ed194..6343af63fe93a6b6d50089288994faa6d8f1f91c 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -133,6 +133,9 @@ endif ifneq (,$(filter ng_netdev_eth,$(USEMODULE))) DIRS += net/link_layer/ng_netdev_eth endif +ifneq (,$(filter udp,$(USEMODULE))) + DIRS += net/transport_layer/udp +endif DIRS += $(dir $(wildcard $(addsuffix /Makefile, ${USEMODULE}))) diff --git a/sys/include/net/ng_udp.h b/sys/include/net/ng_udp.h index 0caa8352eea44a7926dd3f61893a996697773c50..259d642d11b7c0ade8a6b49c5b07b82db3425bb4 100644 --- a/sys/include/net/ng_udp.h +++ b/sys/include/net/ng_udp.h @@ -26,6 +26,7 @@ #include "byteorder.h" #include "net/ng_netbase.h" +#include "net/udp.h" #ifdef __cplusplus extern "C" { @@ -52,17 +53,6 @@ extern "C" { #define NG_UDP_STACK_SIZE (THREAD_STACKSIZE_DEFAULT) #endif -/** - * @brief UDP header definition - */ -typedef struct __attribute__((packed)) { - network_uint16_t src_port; /**< source port, in network byte order */ - network_uint16_t dst_port; /**< destination port, network byte order */ - network_uint16_t length; /**< payload length (including the header), - * network byte order */ - network_uint16_t checksum; /**< checksum */ -} ng_udp_hdr_t; - /** * @brief Calculate the checksum for the given packet * @@ -93,13 +83,6 @@ ng_pktsnip_t *ng_udp_hdr_build(ng_pktsnip_t *payload, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len); -/** - * @brief Print the given UDP header to STDOUT - * - * @param[in] hdr UDP header to print - */ -void ng_udp_hdr_print(ng_udp_hdr_t *hdr); - /** * @brief Initialize and start UDP * diff --git a/sys/include/net/udp.h b/sys/include/net/udp.h new file mode 100644 index 0000000000000000000000000000000000000000..636797ead239cfbdbeb68f3e6d702f16b5490bcd --- /dev/null +++ b/sys/include/net/udp.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup net_udp UDP + * @ingroup net + * @brief UDP header definition + * @see <a href="https://tools.ietf.org/html/rfc768"> + * RFC 768 + * </a> + * @{ + * + * @file + * @brief UDP header definition + * + * @author Martine Lenders <mlenders@inf.fu-berlin.de> + */ +#ifndef UDP_H_ +#define UDP_H_ + +#include "byteorder.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief UDP header + */ +typedef struct __attribute__((packed)) { + network_uint16_t src_port; /**< source port */ + network_uint16_t dst_port; /**< destination port */ + network_uint16_t length; /**< payload length (including the header) */ + network_uint16_t checksum; /**< checksum */ +} udp_hdr_t; + +/** + * @brief Print the given UDP header to STDOUT + * + * @param[in] hdr UDP header to print + */ +void udp_hdr_print(udp_hdr_t *hdr); + +#ifdef __cplusplus +} +#endif + +#endif /* UDP_H_ */ +/** @} */ diff --git a/sys/net/crosslayer/ng_pktdump/ng_pktdump.c b/sys/net/crosslayer/ng_pktdump/ng_pktdump.c index d27088e7f61f4dc778456998075ef94df5c490a2..2bc6decb3b3474f2106dd37c554938c0cc34d23f 100644 --- a/sys/net/crosslayer/ng_pktdump/ng_pktdump.c +++ b/sys/net/crosslayer/ng_pktdump/ng_pktdump.c @@ -31,7 +31,7 @@ #include "net/ipv6/addr.h" #include "net/ipv6/hdr.h" #include "net/ng_sixlowpan.h" -#include "net/ng_udp.h" +#include "net/udp.h" #include "od.h" /** @@ -82,7 +82,7 @@ static void _dump_snip(ng_pktsnip_t *pkt) #ifdef MODULE_NG_UDP case NG_NETTYPE_UDP: printf("NETTYPE_UDP (%i)\n", pkt->type); - ng_udp_hdr_print(pkt->data); + udp_hdr_print(pkt->data); break; #endif #ifdef TEST_SUITES diff --git a/sys/net/transport_layer/ng_udp/ng_udp.c b/sys/net/transport_layer/ng_udp/ng_udp.c index d4e384b5b86a83c9fbf1a0d318a9bba6d240604f..9c165518a9a623c41dead72a5043b1315fc79e80 100644 --- a/sys/net/transport_layer/ng_udp/ng_udp.c +++ b/sys/net/transport_layer/ng_udp/ng_udp.c @@ -74,7 +74,7 @@ static uint16_t _calc_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr, payload = payload->next; } /* process applicable UDP header bytes */ - csum = inet_csum(csum, (uint8_t *)hdr->data, sizeof(ng_udp_hdr_t)); + csum = inet_csum(csum, (uint8_t *)hdr->data, sizeof(udp_hdr_t)); switch (pseudo_hdr->type) { #ifdef MODULE_NG_IPV6 @@ -93,7 +93,7 @@ static uint16_t _calc_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr, static void _receive(ng_pktsnip_t *pkt) { ng_pktsnip_t *udp, *ipv6; - ng_udp_hdr_t *hdr; + udp_hdr_t *hdr; uint32_t port; /* mark UDP header */ @@ -104,7 +104,7 @@ static void _receive(ng_pktsnip_t *pkt) return; } pkt = udp; - udp = ng_pktbuf_mark(pkt, sizeof(ng_udp_hdr_t), NG_NETTYPE_UDP); + udp = ng_pktbuf_mark(pkt, sizeof(udp_hdr_t), NG_NETTYPE_UDP); if (udp == NULL) { DEBUG("udp: error marking UDP header, dropping packet\n"); ng_pktbuf_release(pkt); @@ -113,7 +113,7 @@ static void _receive(ng_pktsnip_t *pkt) /* mark payload as Type: UNDEF */ pkt->type = NG_NETTYPE_UNDEF; /* get explicit pointer to UDP header */ - hdr = (ng_udp_hdr_t *)udp->data; + hdr = (udp_hdr_t *)udp->data; LL_SEARCH_SCALAR(pkt, ipv6, type, NG_NETTYPE_IPV6); @@ -138,7 +138,7 @@ static void _receive(ng_pktsnip_t *pkt) static void _send(ng_pktsnip_t *pkt) { - ng_udp_hdr_t *hdr; + udp_hdr_t *hdr; ng_pktsnip_t *udp_snip; /* get udp snip and hdr */ @@ -152,7 +152,7 @@ static void _send(ng_pktsnip_t *pkt) ng_pktbuf_release(pkt); return; } - hdr = (ng_udp_hdr_t *)udp_snip->data; + hdr = (udp_hdr_t *)udp_snip->data; /* fill in size field */ hdr->length = byteorder_htons(ng_pkt_len(udp_snip)); @@ -221,7 +221,7 @@ int ng_udp_calc_csum(ng_pktsnip_t *hdr, ng_pktsnip_t *pseudo_hdr) if (csum == 0) { return -ENOENT; } - ((ng_udp_hdr_t *)hdr->data)->checksum = byteorder_htons(csum); + ((udp_hdr_t *)hdr->data)->checksum = byteorder_htons(csum); return 0; } @@ -230,7 +230,7 @@ ng_pktsnip_t *ng_udp_hdr_build(ng_pktsnip_t *payload, uint8_t *dst, size_t dst_len) { ng_pktsnip_t *res; - ng_udp_hdr_t *hdr; + udp_hdr_t *hdr; /* check parameters */ if (src == NULL || dst == NULL || @@ -238,12 +238,12 @@ ng_pktsnip_t *ng_udp_hdr_build(ng_pktsnip_t *payload, return NULL; } /* allocate header */ - res = ng_pktbuf_add(payload, NULL, sizeof(ng_udp_hdr_t), NG_NETTYPE_UDP); + res = ng_pktbuf_add(payload, NULL, sizeof(udp_hdr_t), NG_NETTYPE_UDP); if (res == NULL) { return NULL; } /* initialize header */ - hdr = (ng_udp_hdr_t *)res->data; + hdr = (udp_hdr_t *)res->data; hdr->src_port = byteorder_htons(*((uint16_t *)src)); hdr->dst_port = byteorder_htons(*((uint16_t *)dst)); hdr->checksum = byteorder_htons(0); diff --git a/sys/net/transport_layer/udp/Makefile b/sys/net/transport_layer/udp/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..48422e909a47d7cd428d10fa73825060ccc8d8c2 --- /dev/null +++ b/sys/net/transport_layer/udp/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/net/transport_layer/ng_udp/ng_udp_hdr_print.c b/sys/net/transport_layer/udp/udp_hdr_print.c similarity index 92% rename from sys/net/transport_layer/ng_udp/ng_udp_hdr_print.c rename to sys/net/transport_layer/udp/udp_hdr_print.c index 1701038b0842e08a34a9a733141127b7af5d8c7c..757a00ba6ed0cfc9840e54eee4cede863f6c62c0 100644 --- a/sys/net/transport_layer/ng_udp/ng_udp_hdr_print.c +++ b/sys/net/transport_layer/udp/udp_hdr_print.c @@ -21,9 +21,9 @@ #include <stdio.h> #include <inttypes.h> -#include "net/ng_udp.h" +#include "net/udp.h" -void ng_udp_hdr_print(ng_udp_hdr_t *hdr) +void udp_hdr_print(udp_hdr_t *hdr) { printf(" src-port: %5" PRIu16 " dst-port: %5" PRIu16 "\n", byteorder_ntohs(hdr->src_port), byteorder_ntohs(hdr->dst_port));