From 53eaa4feb87a5273870529dc99c876b3e1874902 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 17 Nov 2014 09:24:24 +0100 Subject: [PATCH 1/3] net_help: remove printArrayRange() The od module does the same, much less specialized, much more sophisticated. --- sys/net/crosslayer/net_help/net_help.c | 12 ------------ sys/net/include/net_help.h | 1 - sys/net/transport_layer/tcp/tcp.c | 14 -------------- 3 files changed, 27 deletions(-) diff --git a/sys/net/crosslayer/net_help/net_help.c b/sys/net/crosslayer/net_help/net_help.c index cc33e1e196..8939e058ab 100644 --- a/sys/net/crosslayer/net_help/net_help.c +++ b/sys/net/crosslayer/net_help/net_help.c @@ -19,18 +19,6 @@ #include "net_help.h" -void printArrayRange(uint8_t *array, uint16_t len, char *str) -{ - int i = 0; - printf("-------------%s-------------\n", str); - - for (i = 0; i < len; i++) { - printf("%#x ", *(array + i)); - } - - printf("\n-----------%u-------------\n", len); -} - uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len) { int count = len >> 1; diff --git a/sys/net/include/net_help.h b/sys/net/include/net_help.h index f5d359bf16..c27f08d2b0 100644 --- a/sys/net/include/net_help.h +++ b/sys/net/include/net_help.h @@ -68,7 +68,6 @@ static inline uint64_t NTOHLL(uint64_t a) #define CMP_IPV6_ADDR(a, b) (memcmp(a, b, 16)) uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len); -void printArrayRange(uint8_t *array, uint16_t len, char *str); #ifdef __cplusplus } diff --git a/sys/net/transport_layer/tcp/tcp.c b/sys/net/transport_layer/tcp/tcp.c index 0e636c5fb5..88dc6584f3 100644 --- a/sys/net/transport_layer/tcp/tcp.c +++ b/sys/net/transport_layer/tcp/tcp.c @@ -71,18 +71,6 @@ void printTCPHeader(tcp_hdr_t *tcp_header) printf("END: TCP HEADER\n"); } -void printArrayRange_tcp(uint8_t *udp_header, uint16_t len) -{ - int i = 0; - printf("-------------MEMORY-------------\n"); - - for (i = 0; i < len; i++) { - printf("%#x ", *(udp_header + i)); - } - - printf("-------------MEMORY-------------\n"); -} - void print_tcp_flags(tcp_hdr_t *tcp_header) { printf("FLAGS: "); @@ -744,8 +732,6 @@ void *tcp_packet_handler(void *arg) else { printf("Wrong checksum (%x) or no corresponding socket found!\n", chksum); - printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN + - NTOHS(ipv6_header->length), "Incoming"); print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values); } From 4d82c2c6460ae76654eeb0221e286b4a895ff28b Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 17 Nov 2014 09:27:56 +0100 Subject: [PATCH 2/3] net_help: remove IPV6_CMP_ADDR macro Used nowhere; alternative: ipv6_addr_is_equal(), since other use-cases (is an IPv6 address smaller than the other) are not applicable anyway. --- sys/net/include/net_help.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/sys/net/include/net_help.h b/sys/net/include/net_help.h index c27f08d2b0..0c4377cf1f 100644 --- a/sys/net/include/net_help.h +++ b/sys/net/include/net_help.h @@ -65,8 +65,6 @@ static inline uint64_t NTOHLL(uint64_t a) return byteorder_ntohll(*(network_uint64_t *) &a); } -#define CMP_IPV6_ADDR(a, b) (memcmp(a, b, 16)) - uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len); #ifdef __cplusplus From c9219b87d64acf5ecd382c81fc0dcb0f89274e16 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 17 Nov 2014 09:38:06 +0100 Subject: [PATCH 3/3] net_help: prefix csum properly and add documentation --- sys/net/crosslayer/net_help/net_help.c | 2 +- sys/net/include/net_help.h | 15 ++++++++++++++- sys/net/network_layer/sixlowpan/icmp.c | 4 ++-- sys/net/network_layer/sixlowpan/ip.c | 4 ++-- sys/net/transport_layer/udp/udp.c | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/sys/net/crosslayer/net_help/net_help.c b/sys/net/crosslayer/net_help/net_help.c index 8939e058ab..7ffc29f1cb 100644 --- a/sys/net/crosslayer/net_help/net_help.c +++ b/sys/net/crosslayer/net_help/net_help.c @@ -19,7 +19,7 @@ #include "net_help.h" -uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len) +uint16_t net_help_csum(uint16_t sum, uint8_t *buf, uint16_t len) { int count = len >> 1; diff --git a/sys/net/include/net_help.h b/sys/net/include/net_help.h index 0c4377cf1f..c743ef8110 100644 --- a/sys/net/include/net_help.h +++ b/sys/net/include/net_help.h @@ -65,7 +65,20 @@ static inline uint64_t NTOHLL(uint64_t a) return byteorder_ntohll(*(network_uint64_t *) &a); } -uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len); +/** + * @brief Computes the Internet Checksum for *buf* with initial value *init* + * + * @see + * RFC 1071 + * + * + * @param[in] init Initial value for the checksum (0 in most cases) + * @param[in] buf A byte array to calculate the checksum of + * @param[in] buf_len Length of *buf* + * + * @return The Internet Checksum of *buf* with initial value *init* + */ +uint16_t net_help_csum(uint16_t init, uint8_t *buf, uint16_t buf_len); #ifdef __cplusplus } diff --git a/sys/net/network_layer/sixlowpan/icmp.c b/sys/net/network_layer/sixlowpan/icmp.c index 1490f35cb9..3a8bc8989c 100644 --- a/sys/net/network_layer/sixlowpan/icmp.c +++ b/sys/net/network_layer/sixlowpan/icmp.c @@ -1437,8 +1437,8 @@ uint16_t icmpv6_csum(ipv6_hdr_t *ipv6_buf, icmpv6_hdr_t *icmpv6_buf) icmpv6_buf->checksum = 0; sum = len + IPV6_PROTO_NUM_ICMPV6; - sum = csum(sum, (uint8_t *)&ipv6_buf->srcaddr, 2 * sizeof(ipv6_addr_t)); - sum = csum(sum, (uint8_t *)icmpv6_buf, len); + sum = net_help_csum(sum, (uint8_t *)&ipv6_buf->srcaddr, 2 * sizeof(ipv6_addr_t)); + sum = net_help_csum(sum, (uint8_t *)icmpv6_buf, len); return (sum == 0) ? 0 : ~HTONS(sum); } diff --git a/sys/net/network_layer/sixlowpan/ip.c b/sys/net/network_layer/sixlowpan/ip.c index c0955827ff..8ad2ccb3d0 100644 --- a/sys/net/network_layer/sixlowpan/ip.c +++ b/sys/net/network_layer/sixlowpan/ip.c @@ -820,7 +820,7 @@ uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, uint8_t &ipv6_header->destaddr), len, buf, proto); sum = len + proto; - sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); - sum = csum(sum, buf, len); + sum = net_help_csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); + sum = net_help_csum(sum, buf, len); return (sum == 0) ? 0xffff : HTONS(sum); } diff --git a/sys/net/transport_layer/udp/udp.c b/sys/net/transport_layer/udp/udp.c index 3bf2b48112..230ac61674 100644 --- a/sys/net/transport_layer/udp/udp.c +++ b/sys/net/transport_layer/udp/udp.c @@ -43,8 +43,8 @@ uint16_t udp_csum(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header) uint16_t len = NTOHS(udp_header->length); sum = len + IPPROTO_UDP; - sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); - sum = csum(sum, (uint8_t *)udp_header, len); + sum = net_help_csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); + sum = net_help_csum(sum, (uint8_t *)udp_header, len); return (sum == 0) ? 0xffff : HTONS(sum); }