From de33fcd31bff81c7b3a9c8437372d877f621e11c Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Fri, 20 Sep 2013 14:29:00 +0200 Subject: [PATCH 01/11] Refactor destiny.h --- sys/net/destiny/Makefile | 2 +- sys/net/destiny/destiny.c | 21 +++++++++++++++++---- sys/net/destiny/destiny.h | 13 ------------- sys/net/destiny/include/destiny.h | 13 +++++++++++++ 4 files changed, 31 insertions(+), 18 deletions(-) delete mode 100644 sys/net/destiny/destiny.h create mode 100644 sys/net/destiny/include/destiny.h diff --git a/sys/net/destiny/Makefile b/sys/net/destiny/Makefile index e771aa3e96..54c9d5a440 100644 --- a/sys/net/destiny/Makefile +++ b/sys/net/destiny/Makefile @@ -1,4 +1,4 @@ MODULE:=$(shell basename $(CURDIR)) -INCLUDES = -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/net/destiny -I$(RIOTBASE)/sys/net/sixlowpan/include -I$(RIOTBASE)/sys/net/net_help/ -I$(RIOTBASE)/drivers/cc110x_ng/include -I$(RIOTBASE)/drivers/cc110x +INCLUDES = -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/net/destiny/include -I$(RIOTBASE)/sys/net/sixlowpan/include -I$(RIOTBASE)/sys/net/net_help/ -I$(RIOTBASE)/drivers/cc110x_ng/include -I$(RIOTBASE)/drivers/cc110x include $(RIOTBASE)/Makefile.base diff --git a/sys/net/destiny/destiny.c b/sys/net/destiny/destiny.c index d5cfd44c0c..8d5c9b03a3 100644 --- a/sys/net/destiny/destiny.c +++ b/sys/net/destiny/destiny.c @@ -29,7 +29,7 @@ char tcp_stack_buffer[TCP_STACK_SIZE]; char udp_stack_buffer[UDP_STACK_SIZE]; -void init_transport_layer(void) +int destiny_init_transport_layer(void) { printf("Initializing transport layer packages. Size of socket_type: %u\n", sizeof(socket_internal_t)); @@ -39,7 +39,12 @@ void init_transport_layer(void) /* UDP */ int udp_thread_pid = thread_create(udp_stack_buffer, UDP_STACK_SIZE, PRIORITY_MAIN, CREATE_STACKTEST, - udp_packet_handler,"udp_packet_handler"); + udp_packet_handler, "udp_packet_handler"); + + if (udp_thread_pid < 0) { + return -1; + } + ipv6_register_next_header_handler(IPV6_PROTO_NUM_UDP, udp_thread_pid); /* TCP */ @@ -55,9 +60,17 @@ void init_transport_layer(void) int tcp_thread_pid = thread_create(tcp_stack_buffer, TCP_STACK_SIZE, PRIORITY_MAIN, CREATE_STACKTEST, tcp_packet_handler, "tcp_packet_handler"); + + if (udp_thread_pid < 0) { + return -1; + } + ipv6_register_next_header_handler(IPV6_PROTO_NUM_TCP, tcp_thread_pid); - thread_create(tcp_timer_stack, TCP_TIMER_STACKSIZE, PRIORITY_MAIN + 1, - CREATE_STACKTEST, tcp_general_timer, "tcp_general_timer"); + if (thread_create(tcp_timer_stack, TCP_TIMER_STACKSIZE, PRIORITY_MAIN + 1, + CREATE_STACKTEST, tcp_general_timer, "tcp_general_timer") < 0) { + return -1; + } + return 0; } diff --git a/sys/net/destiny/destiny.h b/sys/net/destiny/destiny.h deleted file mode 100644 index d3f5690638..0000000000 --- a/sys/net/destiny/destiny.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * destiny.h - * - * Created on: 03.09.2011 - * Author: Oliver - */ - -#ifndef DESTINY_H_ -#define DESTINY_H_ - -void init_transport_layer(void); - -#endif /* DESTINY_H_ */ diff --git a/sys/net/destiny/include/destiny.h b/sys/net/destiny/include/destiny.h new file mode 100644 index 0000000000..5e0af7fac6 --- /dev/null +++ b/sys/net/destiny/include/destiny.h @@ -0,0 +1,13 @@ +/* + * destiny.h + * + * Created on: 03.09.2011 + * Author: Oliver + */ + +#ifndef DESTINY_H +#define DESTINY_H + +int destiny_init_transport_layer(void); + +#endif /* DESTINY_H */ From 446be54a2474d137e0e66f4388394fa7041fafd5 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Fri, 20 Sep 2013 15:31:57 +0200 Subject: [PATCH 02/11] Add Documentation for destiny.h --- sys/net/destiny/include/destiny.h | 38 +++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/sys/net/destiny/include/destiny.h b/sys/net/destiny/include/destiny.h index 5e0af7fac6..105cf1b1a1 100644 --- a/sys/net/destiny/include/destiny.h +++ b/sys/net/destiny/include/destiny.h @@ -1,13 +1,43 @@ -/* - * destiny.h +/** + * destiny.h - Wraps all API types, constants and functions of the transport + * layer implementation. * - * Created on: 03.09.2011 - * Author: Oliver + * Copyright (C) 2013 INRIA. + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @defgroup destiny DESTiny - Transport layer implementation + * @ingroup net + * @brief DESTiny module implements the transport layer. This includes + * 6LoWPAN UDP header compression and (experimental) 6LoWPAN TCP header + * compression. + * @see + * RFC 6282 - Compression Format for IPv6 Datagrams over + * IEEE 802.15.4-Based Networks - UDP Header Compression + * + * @see + * RFC draft-aayadi-6lowpan-tcphc-01 - TCP header compression for + * 6LoWPAN + * + * @{ + * @file + * @brief destiny functions + * @author Oliver Gesch + * @author Martin Lenders */ #ifndef DESTINY_H #define DESTINY_H +/** + * Initializes transport layer. + * + * @return 0 on success, other else. + */ int destiny_init_transport_layer(void); #endif /* DESTINY_H */ From e899970ecda402aac417ed2f538f1c27ccdedf4b Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Fri, 20 Sep 2013 15:13:18 +0200 Subject: [PATCH 03/11] Refactor destiny/in.h --- sys/net/destiny/include/destiny.h | 2 ++ sys/net/destiny/{ => include/destiny}/in.h | 6 +++--- sys/net/destiny/socket.h | 2 +- sys/net/destiny/tcp.c | 2 +- sys/net/destiny/udp.c | 2 +- sys/net/sixlowpan/lowpan.c | 1 + 6 files changed, 9 insertions(+), 6 deletions(-) rename sys/net/destiny/{ => include/destiny}/in.h (99%) diff --git a/sys/net/destiny/include/destiny.h b/sys/net/destiny/include/destiny.h index 105cf1b1a1..1c796a5774 100644 --- a/sys/net/destiny/include/destiny.h +++ b/sys/net/destiny/include/destiny.h @@ -33,6 +33,8 @@ #ifndef DESTINY_H #define DESTINY_H +#include "destiny/in.h" + /** * Initializes transport layer. * diff --git a/sys/net/destiny/in.h b/sys/net/destiny/include/destiny/in.h similarity index 99% rename from sys/net/destiny/in.h rename to sys/net/destiny/include/destiny/in.h index 34bc2d60c7..a30e1c18d5 100644 --- a/sys/net/destiny/in.h +++ b/sys/net/destiny/include/destiny/in.h @@ -5,8 +5,8 @@ * Author: Oliver */ -#ifndef IN_H_ -#define IN_H_ +#ifndef DESTINY_IN_H +#define DESTINY_IN_H /* * Constants and structures defined by the internet system, * Per RFC 790, September 1981, and numerous additions. @@ -131,4 +131,4 @@ #define IN_LOOPBACKNET (127) /* official! */ -#endif /* IN_H_ */ +#endif /* DESTINY_IN_H */ diff --git a/sys/net/destiny/socket.h b/sys/net/destiny/socket.h index be8a554da7..de0c7627c0 100644 --- a/sys/net/destiny/socket.h +++ b/sys/net/destiny/socket.h @@ -23,7 +23,7 @@ #include "ipv6.h" #include "tcp.h" #include "udp.h" -#include "in.h" +#include "destiny/in.h" #include "ipv6.h" #include "cpu.h" diff --git a/sys/net/destiny/tcp.c b/sys/net/destiny/tcp.c index ca69f8e7ba..ddd44ae1fa 100644 --- a/sys/net/destiny/tcp.c +++ b/sys/net/destiny/tcp.c @@ -26,7 +26,7 @@ #include "tcp_timer.h" #include "tcp_hc.h" #include "tcp.h" -#include "in.h" +#include "destiny/in.h" #include "socket.h" #include "../net_help/net_help.h" #include "../net_help/msg_help.h" diff --git a/sys/net/destiny/udp.c b/sys/net/destiny/udp.c index 15b225c910..a018db8755 100644 --- a/sys/net/destiny/udp.c +++ b/sys/net/destiny/udp.c @@ -25,7 +25,7 @@ #include "ipv6.h" #include "sixlowpan.h" #include "socket.h" -#include "in.h" +#include "destiny/in.h" #include "../net_help/net_help.h" #include "../net_help/msg_help.h" diff --git a/sys/net/sixlowpan/lowpan.c b/sys/net/sixlowpan/lowpan.c index 81fdcd4db0..175d26d604 100644 --- a/sys/net/sixlowpan/lowpan.c +++ b/sys/net/sixlowpan/lowpan.c @@ -41,6 +41,7 @@ #include "icmp.h" #include "ieee802154_frame.h" +#include "destiny/in.h" #include "net_help.h" #define IP_PROCESS_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT * 6) From b223a8baf0309986e84f3b5889407f30505127f3 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Fri, 20 Sep 2013 15:59:38 +0200 Subject: [PATCH 04/11] Add Documentation destiny/in.h --- sys/net/destiny/include/destiny/in.h | 248 ++++++++++++++------------- 1 file changed, 129 insertions(+), 119 deletions(-) diff --git a/sys/net/destiny/include/destiny/in.h b/sys/net/destiny/include/destiny/in.h index a30e1c18d5..5184d674aa 100644 --- a/sys/net/destiny/include/destiny/in.h +++ b/sys/net/destiny/include/destiny/in.h @@ -1,134 +1,144 @@ -/* - * in.h - * - * Created on: 16.09.2011 - * Author: Oliver +/** + * destiny/in.h - Constants defined by the internet system, per RFC 790, + * September 1981, and numerous additions, inspired by + * netinet/in.h definitions. + * @{ + * @file + * @brief IP next header constants + * @see + * RFC790 - Assigned Numbers + * + * @see + * IEEE Std 1003.1, 2013 Edition - netinet/in.h + * + * @see + * IANA - Protocol Numbers + * + * @author Oliver Gesch + * @author Martin Lenders */ #ifndef DESTINY_IN_H #define DESTINY_IN_H -/* - * Constants and structures defined by the internet system, - * Per RFC 790, September 1981, and numerous additions. - */ /* * Protocols (RFC 1700) TODO: may be deleted due to some double definition * in sys/net/sixlowpan/include/sixlowpan/ip.h */ -#define IPPROTO_IP (0) /* dummy for IP */ -#define IPPROTO_HOPOPTS (0) /* IP6 hop-by-hop options */ -#define IPPROTO_ICMP (1) /* control message protocol */ -#define IPPROTO_IGMP (2) /* group mgmt protocol */ -#define IPPROTO_GGP (3) /* gateway^2 (deprecated) */ -#define IPPROTO_IPV4 (4) /* IPv4 encapsulation */ -#define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */ -#define IPPROTO_TCP (6) /* tcp */ -#define IPPROTO_ST (7) /* Stream protocol II */ -#define IPPROTO_EGP (8) /* exterior gateway protocol */ -#define IPPROTO_PIGP (9) /* private interior gateway */ -#define IPPROTO_RCCMON (10) /* BBN RCC Monitoring */ -#define IPPROTO_NVPII (11) /* network voice protocol*/ -#define IPPROTO_PUP (12) /* pup */ -#define IPPROTO_ARGUS (13) /* Argus */ -#define IPPROTO_EMCON (14) /* EMCON */ -#define IPPROTO_XNET (15) /* Cross Net Debugger */ -#define IPPROTO_CHAOS (16) /* Chaos*/ -#define IPPROTO_UDP (17) /* user datagram protocol */ -#define IPPROTO_MUX (18) /* Multiplexing */ -#define IPPROTO_MEAS (19) /* DCN Measurement Subsystems */ -#define IPPROTO_HMP (20) /* Host Monitoring */ -#define IPPROTO_PRM (21) /* Packet Radio Measurement */ -#define IPPROTO_IDP (22) /* xns idp */ -#define IPPROTO_TRUNK1 (23) /* Trunk-1 */ -#define IPPROTO_TRUNK2 (24) /* Trunk-2 */ -#define IPPROTO_LEAF1 (25) /* Leaf-1 */ -#define IPPROTO_LEAF2 (26) /* Leaf-2 */ -#define IPPROTO_RDP (27) /* Reliable Data */ -#define IPPROTO_IRTP (28) /* Reliable Transaction */ -#define IPPROTO_TP (29) /* tp-4 w/ class negotiation */ -#define IPPROTO_BLT (30) /* Bulk Data Transfer */ -#define IPPROTO_NSP (31) /* Network Services */ -#define IPPROTO_INP (32) /* Merit Internodal */ -#define IPPROTO_SEP (33) /* Sequential Exchange */ -#define IPPROTO_3PC (34) /* Third Party Connect */ -#define IPPROTO_IDPR (35) /* InterDomain Policy Routing */ -#define IPPROTO_XTP (36) /* XTP */ -#define IPPROTO_DDP (37) /* Datagram Delivery */ -#define IPPROTO_CMTP (38) /* Control Message Transport */ -#define IPPROTO_TPXX (39) /* TP++ Transport */ -#define IPPROTO_IL (40) /* IL transport protocol */ -#define IPPROTO_IPV6 (41) /* IP6 header */ -#define IPPROTO_SDRP (42) /* Source Demand Routing */ -#define IPPROTO_ROUTING (43) /* IP6 routing header */ -#define IPPROTO_FRAGMENT (44) /* IP6 fragmentation header */ -#define IPPROTO_IDRP (45) /* InterDomain Routing*/ -#define IPPROTO_RSVP (46) /* resource reservation */ -#define IPPROTO_GRE (47) /* General Routing Encap. */ -#define IPPROTO_MHRP (48) /* Mobile Host Routing */ -#define IPPROTO_BHA (49) /* BHA */ -#define IPPROTO_ESP (50) /* IP6 Encap Sec. Payload */ -#define IPPROTO_AH (51) /* IP6 Auth Header */ -#define IPPROTO_INLSP (52) /* Integ. Net Layer Security */ -#define IPPROTO_SWIPE (53) /* IP with encryption */ -#define IPPROTO_NHRP (54) /* Next Hop Resolution */ -/* 55-57: Unassigned */ -#define IPPROTO_ICMPV6 (58) /* ICMP6 */ -#define IPPROTO_NONE (59) /* IP6 no next header */ -#define IPPROTO_DSTOPTS (60) /* IP6 destination option */ -#define IPPROTO_AHIP (61) /* any host internal protocol */ -#define IPPROTO_CFTP (62) /* CFTP */ -#define IPPROTO_HELLO (63) /* "hello" routing protocol */ -#define IPPROTO_SATEXPAK (64) /* SATNET/Backroom EXPAK */ -#define IPPROTO_KRYPTOLAN (65) /* Kryptolan */ -#define IPPROTO_RVD (66) /* Remote Virtual Disk */ -#define IPPROTO_IPPC (67) /* Pluribus Packet Core */ -#define IPPROTO_ADFS (68) /* Any distributed FS */ -#define IPPROTO_SATMON (69) /* Satnet Monitoring */ -#define IPPROTO_VISA (70) /* VISA Protocol */ -#define IPPROTO_IPCV (71) /* Packet Core Utility */ -#define IPPROTO_CPNX (72) /* Comp. Prot. Net. Executive */ -#define IPPROTO_CPHB (73) /* Comp. Prot. HeartBeat */ -#define IPPROTO_WSN (74) /* Wang Span Network */ -#define IPPROTO_PVP (75) /* Packet Video Protocol */ -#define IPPROTO_BRSATMON (76) /* BackRoom SATNET Monitoring */ -#define IPPROTO_ND (77) /* Sun net disk proto (temp.) */ -#define IPPROTO_WBMON (78) /* WIDEBAND Monitoring */ -#define IPPROTO_WBEXPAK (79) /* WIDEBAND EXPAK */ -#define IPPROTO_EON (80) /* ISO cnlp */ -#define IPPROTO_VMTP (81) /* VMTP */ -#define IPPROTO_SVMTP (82) /* Secure VMTP */ -#define IPPROTO_VINES (83) /* Banyon VINES */ -#define IPPROTO_TTP (84) /* TTP */ -#define IPPROTO_IGP (85) /* NSFNET-IGP */ -#define IPPROTO_DGP (86) /* dissimilar gateway prot. */ -#define IPPROTO_TCF (87) /* TCF */ -#define IPPROTO_IGRP (88) /* Cisco/GXS IGRP */ -#define IPPROTO_OSPFIGP (89) /* OSPFIGP */ -#define IPPROTO_SRPC (90) /* Strite RPC protocol */ -#define IPPROTO_LARP (91) /* Locus Address Resoloution */ -#define IPPROTO_MTP (92) /* Multicast Transport */ -#define IPPROTO_AX25 (93) /* AX.25 Frames */ -#define IPPROTO_IPEIP (94) /* IP encapsulated in IP */ -#define IPPROTO_MICP (95) /* Mobile Int.ing control */ -#define IPPROTO_SCCSP (96) /* Semaphore Comm. security */ -#define IPPROTO_ETHERIP (97) /* Ethernet IP encapsulation */ -#define IPPROTO_ENCAP (98) /* encapsulation header */ -#define IPPROTO_APES (99) /* any private encr. scheme */ -#define IPPROTO_GMTP (100) /* GMTP*/ -#define IPPROTO_IPCOMP (108) /* payload compression (IPComp) */ -/* 101-254: Partly Unassigned */ -#define IPPROTO_PIM (103) /* Protocol Independent Mcast */ -#define IPPROTO_PGM (113) /* PGM */ +#define IPPROTO_IP (0) ///< dummy for IP +#define IPPROTO_HOPOPTS (0) ///< IP6 hop-by-hop options +#define IPPROTO_ICMP (1) ///< control message protocol +#define IPPROTO_IGMP (2) ///< group mgmt protocol +#define IPPROTO_GGP (3) ///< gateway^2 (deprecated) +#define IPPROTO_IPV4 (4) ///< IPv4 encapsulation +#define IPPROTO_IPIP IPPROTO_IPV4 ///< for compatibility +#define IPPROTO_TCP (6) ///< tcp +#define IPPROTO_ST (7) ///< Stream protocol II +#define IPPROTO_EGP (8) ///< exterior gateway protocol +#define IPPROTO_PIGP (9) ///< private interior gateway +#define IPPROTO_RCCMON (10) ///< BBN RCC Monitoring +#define IPPROTO_NVPII (11) ///< network voice protocol +#define IPPROTO_PUP (12) ///< pup +#define IPPROTO_ARGUS (13) ///< Argus +#define IPPROTO_EMCON (14) ///< EMCON +#define IPPROTO_XNET (15) ///< Cross Net Debugger +#define IPPROTO_CHAOS (16) ///< Chaos +#define IPPROTO_UDP (17) ///< user datagram protocol +#define IPPROTO_MUX (18) ///< Multiplexing +#define IPPROTO_MEAS (19) ///< DCN Measurement Subsystems +#define IPPROTO_HMP (20) ///< Host Monitoring +#define IPPROTO_PRM (21) ///< Packet Radio Measurement +#define IPPROTO_IDP (22) ///< xns idp +#define IPPROTO_TRUNK1 (23) ///< Trunk-1 +#define IPPROTO_TRUNK2 (24) ///< Trunk-2 +#define IPPROTO_LEAF1 (25) ///< Leaf-1 +#define IPPROTO_LEAF2 (26) ///< Leaf-2 +#define IPPROTO_RDP (27) ///< Reliable Data +#define IPPROTO_IRTP (28) ///< Reliable Transaction +#define IPPROTO_TP (29) ///< tp-4 w/ class negotiation +#define IPPROTO_BLT (30) ///< Bulk Data Transfer +#define IPPROTO_NSP (31) ///< Network Services +#define IPPROTO_INP (32) ///< Merit Internodal +#define IPPROTO_SEP (33) ///< Sequential Exchange +#define IPPROTO_3PC (34) ///< Third Party Connect +#define IPPROTO_IDPR (35) ///< InterDomain Policy Routing +#define IPPROTO_XTP (36) ///< XTP +#define IPPROTO_DDP (37) ///< Datagram Delivery +#define IPPROTO_CMTP (38) ///< Control Message Transport +#define IPPROTO_TPXX (39) ///< TP++ Transport +#define IPPROTO_IL (40) ///< IL transport protocol +#define IPPROTO_IPV6 (41) ///< IP6 header +#define IPPROTO_SDRP (42) ///< Source Demand Routing +#define IPPROTO_ROUTING (43) ///< IP6 routing header +#define IPPROTO_FRAGMENT (44) ///< IP6 fragmentation header +#define IPPROTO_IDRP (45) ///< InterDomain Routing +#define IPPROTO_RSVP (46) ///< resource reservation +#define IPPROTO_GRE (47) ///< General Routing Encap. +#define IPPROTO_MHRP (48) ///< Mobile Host Routing +#define IPPROTO_BHA (49) ///< BHA +#define IPPROTO_ESP (50) ///< IP6 Encap Sec. Payload +#define IPPROTO_AH (51) ///< IP6 Auth Header +#define IPPROTO_INLSP (52) ///< Integ. Net Layer Security +#define IPPROTO_SWIPE (53) ///< IP with encryption +#define IPPROTO_NHRP (54) ///< Next Hop Resolution +///< 55-57: Unassigned +#define IPPROTO_ICMPV6 (58) ///< ICMP6 +#define IPPROTO_NONE (59) ///< IP6 no next header +#define IPPROTO_DSTOPTS (60) ///< IP6 destination option +#define IPPROTO_AHIP (61) ///< any host internal protocol +#define IPPROTO_CFTP (62) ///< CFTP +#define IPPROTO_HELLO (63) ///< "hello" routing protocol +#define IPPROTO_SATEXPAK (64) ///< SATNET/Backroom EXPAK +#define IPPROTO_KRYPTOLAN (65) ///< Kryptolan +#define IPPROTO_RVD (66) ///< Remote Virtual Disk +#define IPPROTO_IPPC (67) ///< Pluribus Packet Core +#define IPPROTO_ADFS (68) ///< Any distributed FS +#define IPPROTO_SATMON (69) ///< Satnet Monitoring +#define IPPROTO_VISA (70) ///< VISA Protocol +#define IPPROTO_IPCV (71) ///< Packet Core Utility +#define IPPROTO_CPNX (72) ///< Comp. Prot. Net. Executive +#define IPPROTO_CPHB (73) ///< Comp. Prot. HeartBeat +#define IPPROTO_WSN (74) ///< Wang Span Network +#define IPPROTO_PVP (75) ///< Packet Video Protocol +#define IPPROTO_BRSATMON (76) ///< BackRoom SATNET Monitoring +#define IPPROTO_ND (77) ///< Sun net disk proto (temp.) +#define IPPROTO_WBMON (78) ///< WIDEBAND Monitoring +#define IPPROTO_WBEXPAK (79) ///< WIDEBAND EXPAK +#define IPPROTO_EON (80) ///< ISO cnlp +#define IPPROTO_VMTP (81) ///< VMTP +#define IPPROTO_SVMTP (82) ///< Secure VMTP +#define IPPROTO_VINES (83) ///< Banyon VINES +#define IPPROTO_TTP (84) ///< TTP +#define IPPROTO_IGP (85) ///< NSFNET-IGP +#define IPPROTO_DGP (86) ///< dissimilar gateway prot. +#define IPPROTO_TCF (87) ///< TCF +#define IPPROTO_IGRP (88) ///< Cisco/GXS IGRP +#define IPPROTO_OSPFIGP (89) ///< OSPFIGP +#define IPPROTO_SRPC (90) ///< Strite RPC protocol +#define IPPROTO_LARP (91) ///< Locus Address Resoloution +#define IPPROTO_MTP (92) ///< Multicast Transport +#define IPPROTO_AX25 (93) ///< AX.25 Frames +#define IPPROTO_IPEIP (94) ///< IP encapsulated in IP +#define IPPROTO_MICP (95) ///< Mobile Int.ing control +#define IPPROTO_SCCSP (96) ///< Semaphore Comm. security +#define IPPROTO_ETHERIP (97) ///< Ethernet IP encapsulation +#define IPPROTO_ENCAP (98) ///< encapsulation header +#define IPPROTO_APES (99) ///< any private encr. scheme +#define IPPROTO_GMTP (100) ///< GMTP +#define IPPROTO_IPCOMP (108) ///< payload compression (IPComp) +/** + * 101-254: Partly Unassigned + */ +#define IPPROTO_PIM (103) ///< Protocol Independent Mcast +#define IPPROTO_PGM (113) ///< PGM /* 255: Reserved */ -/* BSD Private, local use, namespace incursion */ -#define IPPROTO_DIVERT (254) /* divert pseudo-protocol */ -#define IPPROTO_RAW (255) /* raw IP packet */ +/* */ +#define IPPROTO_DIVERT (254) ///< divert pseudo-protocol (BSD Private, local use, namespace incursion) +#define IPPROTO_RAW (255) ///< raw IP packet #define IPPROTO_MAX (256) -/* last return value of *_input(), meaning "all job for this pkt is done". */ -#define IPPROTO_DONE (257) +#define IPPROTO_DONE (257) ///< last return value of *_input(), meaning "all job for this pkt is done". -#define IN_LOOPBACKNET (127) /* official! */ +#define IN_LOOPBACKNET (127) ///< official! #endif /* DESTINY_IN_H */ From 3149e83826a2ec526add56ba73e8fdde23640a97 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Mon, 23 Sep 2013 12:40:16 +0200 Subject: [PATCH 05/11] Refactor destiny/socket.h --- sys/net/destiny/destiny.c | 3 +- sys/net/destiny/include/destiny.h | 1 + sys/net/destiny/include/destiny/socket.h | 215 +++++++++++++++++++++++ sys/net/destiny/socket.c | 185 ++++++++++--------- sys/net/destiny/socket.h | 198 +++------------------ sys/net/destiny/tcp.c | 15 +- sys/net/destiny/tcp_hc.c | 5 +- sys/net/destiny/tcp_hc.h | 2 +- sys/net/destiny/tcp_timer.c | 7 +- sys/net/destiny/udp.c | 3 +- sys/net/net_help/Makefile | 2 +- sys/net/net_help/inet_ntop.c | 2 +- sys/net/net_help/inet_pton.c | 2 +- sys/net/sixlowpan/ip.c | 1 + 14 files changed, 361 insertions(+), 280 deletions(-) create mode 100644 sys/net/destiny/include/destiny/socket.h diff --git a/sys/net/destiny/destiny.c b/sys/net/destiny/destiny.c index 8d5c9b03a3..04589e6770 100644 --- a/sys/net/destiny/destiny.c +++ b/sys/net/destiny/destiny.c @@ -22,10 +22,11 @@ #include #include "udp.h" #include "tcp.h" -#include "socket.h" #include "tcp_timer.h" #include "destiny.h" +#include "socket.h" + char tcp_stack_buffer[TCP_STACK_SIZE]; char udp_stack_buffer[UDP_STACK_SIZE]; diff --git a/sys/net/destiny/include/destiny.h b/sys/net/destiny/include/destiny.h index 1c796a5774..71b7283b3b 100644 --- a/sys/net/destiny/include/destiny.h +++ b/sys/net/destiny/include/destiny.h @@ -34,6 +34,7 @@ #define DESTINY_H #include "destiny/in.h" +#include "destiny/socket.h" /** * Initializes transport layer. diff --git a/sys/net/destiny/include/destiny/socket.h b/sys/net/destiny/include/destiny/socket.h new file mode 100644 index 0000000000..d8a8d3febc --- /dev/null +++ b/sys/net/destiny/include/destiny/socket.h @@ -0,0 +1,215 @@ +/** + * destiny/socket.h - Destiny socket API + * + * Copyright (C) 2013 INRIA. + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * @ingroup destiny + * @{ + * @file + * @brief Header for BSD socket API + * @author Oliver Gesch + * @author Martin Lenders + */ + + +#ifndef DESTINY_SOCKET_H +#define DESTINY_SOCKET_H + +#include +#include "ipv6.h" +#include "destiny/in.h" + +/** + * POSIX compatible type for address family. + * + * @see + * IEEE Std 1003.1, 2013 Edition - sys/socket.h + * + */ +typedef uint8_t sa_family_t; +typedef uint32_t socklen_t; ///< POSIX compatible type for address lengths. + +/* + * Types + */ +#define SOCK_STREAM 1 /* stream socket */ +#define SOCK_DGRAM 2 /* datagram socket */ +#define SOCK_RAW 3 /* raw-protocol interface */ +#define SOCK_RDM 4 /* reliably-delivered message */ +#define SOCK_SEQPACKET 5 /* sequenced packet stream */ + +/* + * Address families. + */ +#define AF_UNSPEC 0 /* unspecified */ +#define AF_LOCAL 1 /* local to host (pipes, portals) */ +#define AF_UNIX AF_LOCAL /* backward compatibility */ +#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ +#define AF_IMPLINK 3 /* arpanet imp addresses */ +#define AF_PUP 4 /* pup protocols: e.g. BSP */ +#define AF_CHAOS 5 /* mit CHAOS protocols */ +#define AF_NS 6 /* XEROX NS protocols */ +#define AF_ISO 7 /* ISO protocols */ +#define AF_OSI AF_ISO +#define AF_ECMA 8 /* European computer manufacturers */ +#define AF_DATAKIT 9 /* datakit protocols */ +#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ +#define AF_SNA 11 /* IBM SNA */ +#define AF_DECnet 12 /* DECnet */ +#define AF_DLI 13 /* DEC Direct data link interface */ +#define AF_LAT 14 /* LAT */ +#define AF_HYLINK 15 /* NSC Hyperchannel */ +#define AF_APPLETALK 16 /* Apple Talk */ +#define AF_ROUTE 17 /* Internal Routing Protocol */ +#define AF_LINK 18 /* Link layer interface */ +#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ +#define AF_COIP 20 /* connection-oriented IP, aka ST II */ +#define AF_CNT 21 /* Computer Network Technology */ +#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ +#define AF_IPX 23 /* Novell Internet Protocol */ +#define AF_SIP 24 /* Simple Internet Protocol */ +#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ +#define AF_ISDN 26 /* Integrated Services Digital Network*/ +#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ +#define pseudo_AF_KEY 27 /* Internal key-management function */ +#define AF_INET6 28 /* IPv6 */ +#define AF_NATM 29 /* native ATM access */ +#define AF_ATM 30 /* ATM */ +#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers + * in interface output routine + */ +#define AF_NETGRAPH 32 /* Netgraph sockets */ +#define AF_MAX 33 + +/* + * Protocol families, same as address families for now. + */ +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_UNIX PF_LOCAL /* backward compatibility */ +#define PF_INET AF_INET +#define PF_IMPLINK AF_IMPLINK +#define PF_PUP AF_PUP +#define PF_CHAOS AF_CHAOS +#define PF_NS AF_NS +#define PF_ISO AF_ISO +#define PF_OSI AF_ISO +#define PF_ECMA AF_ECMA +#define PF_DATAKIT AF_DATAKIT +#define PF_CCITT AF_CCITT +#define PF_SNA AF_SNA +#define PF_DECnet AF_DECnet +#define PF_DLI AF_DLI +#define PF_LAT AF_LAT +#define PF_HYLINK AF_HYLINK +#define PF_APPLETALK AF_APPLETALK +#define PF_ROUTE AF_ROUTE +#define PF_LINK AF_LINK +#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ +#define PF_COIP AF_COIP +#define PF_CNT AF_CNT +#define PF_SIP AF_SIP +#define PF_IPX AF_IPX /* same format as AF_NS */ +#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ +#define PF_PIP pseudo_AF_PIP +#define PF_ISDN AF_ISDN +#define PF_KEY pseudo_AF_KEY +#define PF_INET6 AF_INET6 +#define PF_NATM AF_NATM +#define PF_ATM AF_ATM +#define PF_NETGRAPH AF_NETGRAPH +#define PF_MAX AF_MAX + +#define DESTINY_SOCKET_STATIC_MSS 48 +#define DESTINY_SOCKET_STATIC_WINDOW 1 * DESTINY_SOCKET_STATIC_MSS +#define DESTINY_SOCKET_MAX_TCP_BUFFER 1 * DESTINY_SOCKET_STATIC_WINDOW + +typedef struct __attribute__((packed)) { + uint8_t sin6_family; /* AF_INET6 */ + uint16_t sin6_port; /* transport layer port # */ + uint32_t sin6_flowinfo; /* IPv6 flow information */ + ipv6_addr_t sin6_addr; /* IPv6 address */ +} sockaddr6_t; + +int destiny_socket(int domain, int type, int protocol); +int destiny_socket_connect(int socket, sockaddr6_t *addr, + socklen_t addrlen); + +/** + * Receives data through socket *s* and saves it in buffer *buf*. Roughly + * identical to POSIX's recv(2). + * + * @param[in] s The ID of the socket to receive from. + * @param[in] buf Buffer to store received data in. + * @param[in] len Length of buffer. + * @param[in] flags Flags for possible later implementations (currently + * unused). + * + * @return Number of received bytes, -1 on error. + */ +int32_t destiny_socket_recv(int s, void *buf, uint32_t len, int flags); + +/** + * Receives data through socket *s* and saves it in buffer *buf*. The address + * of the sender is stored in *from*. Roughly identical to POSIX's + * recvfrom(2). + * + * @param[in] s The ID of the socket to receive from. + * @param[in] buf Buffer to store received data in. + * @param[in] len Length of buffer. + * @param[in] flags Flags for possible later implementations (currently + * unused). + * @param[in] from IPv6 Address of the data's sender. + * @param[in] fromlen Length of address in *from* in byte (always 16). + * + * @return Number of received bytes, -1 on error. + */ +int32_t destiny_socket_recvfrom(int s, void *buf, uint32_t len, int flags, + sockaddr6_t *from, socklen_t *fromlen); + +/** + * Sends data *buf* through socket *s*. Roughly identical to POSIX's + * send(2). + * + * @param[in] s The ID of the socket to send through. + * @param[in] buf Buffer to send the data from. + * @param[in] len Length of buffer. + * @param[in] flags Flags for possible later implementations (currently + * unused). + * + * @return Number of send bytes, -1 on error. + */ +int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags); + +/** + * Sends data *buf* through socket *s* to foreign host with IPv6 address *addr*. + * Roughly identical to POSIX's send(2). + * + * @param[in] s The ID of the socket to send through. + * @param[in] buf Buffer to send the data from. + * @param[in] len Length of buffer. + * @param[in] flags Flags for possible later implementations (currently + * unused). + * @param[in] from IPv6 Address to send data to. + * @param[in] fromlen Length of address in *from* in byte (always 16). + * + * @return Number of send bytes, -1 on error. + */ +int32_t destiny_socket_sendto(int s, const void *buf, uint32_t len, int flags, + sockaddr6_t *to, socklen_t tolen); +int32_t destiny_socket_send(int s, void *msg, uint32_t len, int flags); +int32_t destiny_socket_recv(int s, void *buf, uint32_t len, int flags); +int destiny_socket_close(int s); +int destiny_socket_bind(int s, sockaddr6_t *name, int namelen); +int destiny_socket_listen(int s, int backlog); +int destiny_socket_accept(int s, sockaddr6_t *addr, socklen_t *addrlen); +void destiny_socket_print_sockets(void); + +/** + * @} + */ +#endif /* DESTINY_SOCKET_H */ diff --git a/sys/net/destiny/socket.c b/sys/net/destiny/socket.c index 6de0129e97..b678b41bb1 100644 --- a/sys/net/destiny/socket.c +++ b/sys/net/destiny/socket.c @@ -24,7 +24,6 @@ #include "ipv6.h" #include "udp.h" #include "tcp.h" -#include "socket.h" #include "vtimer.h" #include "hwtimer.h" #include "tcp_timer.h" @@ -32,8 +31,24 @@ #include "../net_help/net_help.h" #include "../net_help/msg_help.h" +#include "socket.h" + +#define EPHEMERAL_PORTS 49152 + socket_internal_t sockets[MAX_SOCKETS]; +void print_socket(socket_t *current_socket); +void print_internal_socket(socket_internal_t *current_socket_internal); +void printf_tcp_context(tcp_hc_context_t *current_tcp_context); +int exists_socket(int socket); +void set_socket_address(sockaddr6_t *sockaddr, sa_family_t sin6_family, + uint16_t sin6_port, uint32_t sin6_flowinfo, + ipv6_addr_t *sin6_addr); +void set_tcp_packet(tcp_hdr_t *tcp_hdr, uint16_t src_port, uint16_t dst_port, + uint32_t seq_nr, uint32_t ack_nr, + uint8_t dataOffset_reserved, uint8_t reserved_flags, + uint16_t window, uint16_t checksum, uint16_t urg_pointer); + void printf_tcp_context(tcp_hc_context_t *current_tcp_context) { printf("Context: %u\n", current_tcp_context->context_id); @@ -152,7 +167,7 @@ void print_internal_socket(socket_internal_t *current_socket_internal) printf("\n--------------------------\n"); } -socket_internal_t *getSocket(uint8_t s) +socket_internal_t *get_socket(int s) { if (exists_socket(s)) { return &(sockets[s - 1]); @@ -162,19 +177,19 @@ socket_internal_t *getSocket(uint8_t s) } } -void print_sockets(void) +void destiny_socket_print_sockets(void) { int i; printf("\n--- Socket list: ---\n"); for (i = 1; i < MAX_SOCKETS + 1; i++) { - if (getSocket(i) != NULL) { - print_internal_socket(getSocket(i)); + if (get_socket(i) != NULL) { + print_internal_socket(get_socket(i)); } } } -bool exists_socket(uint8_t socket) +int exists_socket(int socket) { if (sockets[socket - 1].socket_id == 0) { return false; @@ -192,10 +207,10 @@ void close_socket(socket_internal_t *current_socket) bool isUDPSocket(uint8_t s) { if ((exists_socket(s)) && - (getSocket(s)->socket_values.domain == PF_INET6) && - (getSocket(s)->socket_values.type == SOCK_DGRAM) && - ((getSocket(s)->socket_values.protocol == IPPROTO_UDP) || - (getSocket(s)->socket_values.protocol == 0))) { + (get_socket(s)->socket_values.domain == PF_INET6) && + (get_socket(s)->socket_values.type == SOCK_DGRAM) && + ((get_socket(s)->socket_values.protocol == IPPROTO_UDP) || + (get_socket(s)->socket_values.protocol == 0))) { return true; } else { @@ -203,13 +218,13 @@ bool isUDPSocket(uint8_t s) } } -bool isTCPSocket(uint8_t s) +bool is_tcp_socket(int s) { if ((exists_socket(s)) && - (getSocket(s)->socket_values.domain == PF_INET6) && - (getSocket(s)->socket_values.type == SOCK_STREAM) && - ((getSocket(s)->socket_values.protocol == IPPROTO_TCP) || - (getSocket(s)->socket_values.protocol == 0))) { + (get_socket(s)->socket_values.domain == PF_INET6) && + (get_socket(s)->socket_values.type == SOCK_STREAM) && + ((get_socket(s)->socket_values.protocol == IPPROTO_TCP) || + (get_socket(s)->socket_values.protocol == 0))) { return true; } else { @@ -227,14 +242,14 @@ int bind_udp_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) for (i = 1; i < MAX_SOCKETS + 1; i++) { if (isUDPSocket(i) && - (getSocket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { + (get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { return -1; } } - memcpy(&getSocket(s)->socket_values.local_address, name, namelen); - getSocket(s)->recv_pid = pid; - return 1; + memcpy(&get_socket(s)->socket_values.local_address, name, namelen); + get_socket(s)->recv_pid = pid; + return 0; } int bind_tcp_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) @@ -246,23 +261,23 @@ int bind_tcp_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) } for (i = 1; i < MAX_SOCKETS + 1; i++) { - if (isTCPSocket(i) && - (getSocket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { + if (is_tcp_socket(i) && + (get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { return -1; } } - memcpy(&getSocket(s)->socket_values.local_address, name, namelen); - getSocket(s)->recv_pid = pid; - getSocket(s)->socket_values.tcp_control.rto = TCP_INITIAL_ACK_TIMEOUT; - return 1; + memcpy(&get_socket(s)->socket_values.local_address, name, namelen); + get_socket(s)->recv_pid = pid; + get_socket(s)->socket_values.tcp_control.rto = TCP_INITIAL_ACK_TIMEOUT; + return 0; } -int socket(int domain, int type, int protocol) +int destiny_socket(int domain, int type, int protocol) { int i = 1; - while (getSocket(i) != NULL) { + while (get_socket(i) != NULL) { i++; } @@ -286,9 +301,9 @@ socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header while (i < MAX_SOCKETS + 1) { if (isUDPSocket(i) && - (getSocket(i)->socket_values.local_address.sin6_port == + (get_socket(i)->socket_values.local_address.sin6_port == udp_header->dst_port)) { - return getSocket(i); + return get_socket(i); } i++; @@ -317,15 +332,15 @@ socket_internal_t *get_tcp_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header memset(compare, 0, 16); while (i < MAX_SOCKETS + 1) { - current_socket = getSocket(i); + current_socket = get_socket(i); /* Check for matching 4 touple, ESTABLISHED connection */ - if (isTCPSocket(i) && is_four_touple(current_socket, ipv6_header, + if (is_tcp_socket(i) && is_four_touple(current_socket, ipv6_header, tcp_header)) { return current_socket; } /* Sockets in LISTEN and SYN_RCVD state should only be tested on local TCP values */ - else if (isTCPSocket(i) && + else if (is_tcp_socket(i) && ((current_socket->socket_values.tcp_control.state == LISTEN) || (current_socket->socket_values.tcp_control.state == SYN_RCVD)) && (current_socket->socket_values.local_address.sin6_addr.uint8[15] == @@ -442,7 +457,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, current_mss_option.kind = TCP_MSS_OPTION; current_mss_option.len = sizeof(tcp_mss_option_t); - current_mss_option.mss = STATIC_MSS; + current_mss_option.mss = DESTINY_SOCKET_STATIC_MSS; memcpy(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN, ¤t_mss_option, sizeof(tcp_mss_option_t)); } @@ -499,7 +514,7 @@ void set_tcp_cb(tcp_cb_t *tcp_control, uint32_t rcv_nxt, uint16_t rcv_wnd, tcp_control->send_wnd = send_wnd; } -int connect(int socket, sockaddr6_t *addr, uint32_t addrlen) +int destiny_socket_connect(int socket, sockaddr6_t *addr, uint32_t addrlen) { /* Variables */ ipv6_addr_t src_addr; @@ -511,7 +526,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen) tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); /* Check if socket exists */ - current_int_tcp_socket = getSocket(socket); + current_int_tcp_socket = get_socket(socket); if (current_int_tcp_socket == NULL) { return -1; @@ -553,7 +568,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen) sizeof(tcp_hc_context_t)); #endif - set_tcp_cb(¤t_tcp_socket->tcp_control, 0, STATIC_WINDOW, + set_tcp_cb(¤t_tcp_socket->tcp_control, 0, DESTINY_SOCKET_STATIC_WINDOW, current_tcp_socket->tcp_control.send_iss, current_tcp_socket->tcp_control.send_iss, 0); @@ -608,7 +623,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen) *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); } else { - current_tcp_socket->tcp_control.mss = STATIC_MSS; + current_tcp_socket->tcp_control.mss = DESTINY_SOCKET_STATIC_MSS; } current_tcp_socket->tcp_control.rcv_irs = tcp_header->seq_nr; @@ -660,7 +675,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen) current_int_tcp_socket->recv_pid = 255; - print_sockets(); + destiny_socket_print_sockets(); return 0; } @@ -695,7 +710,7 @@ void calculate_rto(tcp_cb_t *tcp_control, long current_time) tcp_control->rto = rto; } -int32_t send(int s, void *msg, uint32_t len, int flags) +int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) { /* Variables */ msg_t recv_msg; @@ -708,11 +723,11 @@ int32_t send(int s, void *msg, uint32_t len, int flags) tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); /* Check if socket exists and is TCP socket */ - if (!isTCPSocket(s)) { + if (!is_tcp_socket(s)) { return -1; } - current_int_tcp_socket = getSocket(s); + current_int_tcp_socket = get_socket(s); current_tcp_socket = ¤t_int_tcp_socket->socket_values; /* Check for ESTABLISHED STATE */ @@ -742,14 +757,14 @@ int32_t send(int s, void *msg, uint32_t len, int flags) current_tcp_socket->tcp_control.mss) { /* Window size > Maximum Segment Size */ if ((len - total_sent_bytes) > current_tcp_socket->tcp_control.mss) { - memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], msg, + memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], buf, current_tcp_socket->tcp_control.mss); sent_bytes = current_tcp_socket->tcp_control.mss; total_sent_bytes += sent_bytes; } else { memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], - msg + total_sent_bytes, len - total_sent_bytes); + buf + total_sent_bytes, len - total_sent_bytes); sent_bytes = len - total_sent_bytes; total_sent_bytes = len; } @@ -757,14 +772,14 @@ int32_t send(int s, void *msg, uint32_t len, int flags) else { /* Window size <= Maximum Segment Size */ if ((len - total_sent_bytes) > current_tcp_socket->tcp_control.send_wnd) { - memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], msg, + memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], buf, current_tcp_socket->tcp_control.send_wnd); sent_bytes = current_tcp_socket->tcp_control.send_wnd; total_sent_bytes += sent_bytes; } else { memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], - msg + total_sent_bytes, len - total_sent_bytes); + buf + total_sent_bytes, len - total_sent_bytes); sent_bytes = len - total_sent_bytes; total_sent_bytes = len; } @@ -895,7 +910,7 @@ uint8_t read_from_socket(socket_internal_t *current_int_tcp_socket, } } -int recv(int s, void *buf, uint32_t len, int flags) +int32_t destiny_socket_recv(int s, void *buf, uint32_t len, int flags) { /* Variables */ uint8_t read_bytes; @@ -903,12 +918,12 @@ int recv(int s, void *buf, uint32_t len, int flags) socket_internal_t *current_int_tcp_socket; /* Check if socket exists */ - if (!isTCPSocket(s)) { + if (!is_tcp_socket(s)) { printf("INFO: NO TCP SOCKET!\n"); return -1; } - current_int_tcp_socket = getSocket(s); + current_int_tcp_socket = get_socket(s); /* Setting Thread PID */ current_int_tcp_socket->recv_pid = thread_getpid(); @@ -937,15 +952,15 @@ int recv(int s, void *buf, uint32_t len, int flags) return -1; } -int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, - uint32_t *fromlen) +int32_t destiny_socket_recvfrom(int s, void *buf, uint32_t len, int flags, + sockaddr6_t *from, uint32_t *fromlen) { if (isUDPSocket(s)) { msg_t m_recv, m_send; ipv6_hdr_t *ipv6_header; udp_hdr_t *udp_header; uint8_t *payload; - getSocket(s)->recv_pid = thread_getpid(); + get_socket(s)->recv_pid = thread_getpid(); msg_receive(&m_recv); @@ -964,8 +979,8 @@ int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, msg_reply(&m_recv, &m_send); return udp_header->length - UDP_HDR_LEN; } - else if (isTCPSocket(s)) { - return recv(s, buf, len, flags); + else if (is_tcp_socket(s)) { + return destiny_socket_recv(s, buf, len, flags); } else { printf("Socket Type not supported!\n"); @@ -973,11 +988,11 @@ int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, } } -int32_t sendto(int s, const void *msg, uint32_t len, int flags, - sockaddr6_t *to, uint32_t tolen) +int32_t destiny_socket_sendto(int s, const void *buf, uint32_t len, int flags, + sockaddr6_t *to, uint32_t tolen) { if (isUDPSocket(s) && - (getSocket(s)->socket_values.foreign_address.sin6_port == 0)) { + (get_socket(s)->socket_values.foreign_address.sin6_port == 0)) { uint8_t send_buffer[BUFFER_SIZE]; ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer)); @@ -991,7 +1006,7 @@ int32_t sendto(int s, const void *msg, uint32_t len, int flags, current_udp_packet->dst_port = to->sin6_port; current_udp_packet->checksum = 0; - memcpy(payload, msg, len); + memcpy(payload, buf, len); current_udp_packet->length = UDP_HDR_LEN + len; temp_ipv6_header->length = UDP_HDR_LEN + len; @@ -1008,12 +1023,12 @@ int32_t sendto(int s, const void *msg, uint32_t len, int flags, } } -int close(int s) +int destiny_socket_close(int s) { - socket_internal_t *current_socket = getSocket(s); + socket_internal_t *current_socket = get_socket(s); if (current_socket != NULL) { - if (isTCPSocket(s)) { + if (is_tcp_socket(s)) { /* Variables */ msg_t m_recv; uint8_t send_buffer[BUFFER_SIZE]; @@ -1021,14 +1036,14 @@ int close(int s) tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t *)(&send_buffer[IPV6_HDR_LEN])); /* Check if socket exists and is TCP socket */ - if (!isTCPSocket(s)) { + if (!is_tcp_socket(s)) { return -1; } /* Check for ESTABLISHED STATE */ if (current_socket->socket_values.tcp_control.state != ESTABLISHED) { close_socket(current_socket); - return 1; + return 0; } current_socket->send_pid = thread_getpid(); @@ -1049,7 +1064,7 @@ int close(int s) } else if (isUDPSocket(s)) { close_socket(current_socket); - return 1; + return 0; } return -1; @@ -1059,10 +1074,10 @@ int close(int s) } } -int bind(int s, sockaddr6_t *name, int namelen) +int destiny_socket_bind(int s, sockaddr6_t *addr, int addrlen) { if (exists_socket(s)) { - socket_t *current_socket = &getSocket(s)->socket_values; + socket_t *current_socket = &get_socket(s)->socket_values; switch(current_socket->domain) { case (PF_INET): { @@ -1077,7 +1092,7 @@ int bind(int s, sockaddr6_t *name, int namelen) case (SOCK_STREAM): { if ((current_socket->protocol == 0) || (current_socket->protocol == IPPROTO_TCP)) { - return bind_tcp_socket(s, name, namelen, + return bind_tcp_socket(s, addr, addrlen, thread_getpid()); break; } @@ -1093,7 +1108,7 @@ int bind(int s, sockaddr6_t *name, int namelen) case (SOCK_DGRAM): { if ((current_socket->protocol == 0) || (current_socket->protocol == IPPROTO_UDP)) { - return bind_udp_socket(s, name, namelen, + return bind_udp_socket(s, addr, addrlen, thread_getpid()); break; } @@ -1141,10 +1156,10 @@ int bind(int s, sockaddr6_t *name, int namelen) return -1; } -int listen(int s, int backlog) +int destiny_socket_listen(int s, int backlog) { - if (isTCPSocket(s) && getSocket(s)->socket_values.tcp_control.state == CLOSED) { - socket_internal_t *current_socket = getSocket(s); + if (is_tcp_socket(s) && get_socket(s)->socket_values.tcp_control.state == CLOSED) { + socket_internal_t *current_socket = get_socket(s); current_socket->socket_values.tcp_control.state = LISTEN; return 0; } @@ -1153,15 +1168,15 @@ int listen(int s, int backlog) } } -socket_internal_t *getWaitingConnectionSocket(int socket, - ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header) +socket_internal_t *get_waiting_connection_socket(int socket, + ipv6_hdr_t *ipv6_header, + tcp_hdr_t *tcp_header) { int i; - socket_internal_t *current_socket, *listening_socket = getSocket(socket); + socket_internal_t *current_socket, *listening_socket = get_socket(socket); for (i = 1; i < MAX_SOCKETS + 1; i++) { - current_socket = getSocket(i); + current_socket = get_socket(i); /* Connection establishment ACK, Check for 4 touple and state */ if ((ipv6_header != NULL) && (tcp_header != NULL)) { @@ -1264,18 +1279,18 @@ int handle_new_tcp_connection(socket_internal_t *current_queued_int_socket, /* Waiting for Clients ACK waiting period to time out */ vtimer_usleep(TCP_SYN_INITIAL_TIMEOUT / 2); - print_sockets(); + destiny_socket_print_sockets(); return current_queued_int_socket->socket_id; } -int accept(int s, sockaddr6_t *addr, uint32_t *addrlen) +int destiny_socket_accept(int s, sockaddr6_t *addr, uint32_t *addrlen) { - socket_internal_t *server_socket = getSocket(s); + socket_internal_t *server_socket = get_socket(s); - if (isTCPSocket(s) && (server_socket->socket_values.tcp_control.state == LISTEN)) { + if (is_tcp_socket(s) && (server_socket->socket_values.tcp_control.state == LISTEN)) { socket_internal_t *current_queued_socket = - getWaitingConnectionSocket(s, NULL, NULL); + get_waiting_connection_socket(s, NULL, NULL); if (current_queued_socket != NULL) { return handle_new_tcp_connection(current_queued_socket, @@ -1290,7 +1305,7 @@ int accept(int s, sockaddr6_t *addr, uint32_t *addrlen) msg_receive(&msg_recv_client_syn); } - current_queued_socket = getWaitingConnectionSocket(s, NULL, NULL); + current_queued_socket = get_waiting_connection_socket(s, NULL, NULL); return handle_new_tcp_connection(current_queued_socket, server_socket, thread_getpid()); @@ -1306,8 +1321,8 @@ socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, { int queued_socket_id; - queued_socket_id = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); - socket_internal_t *current_queued_socket = getSocket(queued_socket_id); + queued_socket_id = destiny_socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); + socket_internal_t *current_queued_socket = get_socket(queued_socket_id); /* Foreign address */ set_socket_address(¤t_queued_socket->socket_values.foreign_address, @@ -1326,7 +1341,7 @@ socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); } else { - current_queued_socket->socket_values.tcp_control.mss = STATIC_MSS; + current_queued_socket->socket_values.tcp_control.mss = DESTINY_SOCKET_STATIC_MSS; } current_queued_socket->socket_values.tcp_control.rcv_irs = @@ -1337,7 +1352,7 @@ socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, mutex_unlock(&global_sequence_clunter_mutex); current_queued_socket->socket_values.tcp_control.state = SYN_RCVD; set_tcp_cb(¤t_queued_socket->socket_values.tcp_control, - tcp_header->seq_nr + 1, STATIC_WINDOW, + tcp_header->seq_nr + 1, DESTINY_SOCKET_STATIC_WINDOW, current_queued_socket->socket_values.tcp_control.send_iss, current_queued_socket->socket_values.tcp_control.send_iss, tcp_header->window); diff --git a/sys/net/destiny/socket.h b/sys/net/destiny/socket.h index de0c7627c0..978eb76a40 100644 --- a/sys/net/destiny/socket.h +++ b/sys/net/destiny/socket.h @@ -1,151 +1,18 @@ -/** - * Destiny socket API - * - * Copyright (C) 2013 INRIA. - * - * This file subject to the terms and conditions of the GNU Lesser General - * Public License. See the file LICENSE in the top level directory for more - * details. - * - * @ingroup destiny - * @{ - * @file socket.h - * @brief header for BSD socket API - * @author Oliver Gesch - * @} - */ - - -#ifndef SOCKET_H_ -#define SOCKET_H_ - -#include -#include "ipv6.h" -#include "tcp.h" -#include "udp.h" -#include "destiny/in.h" -#include "ipv6.h" +#ifndef _DESTINY_SOCKET +#define _DESTINY_SOCKET +#include "destiny/socket.h" #include "cpu.h" -/* - * POSIX compatibility - */ -typedef uint8_t sa_family_t; -typedef uint32_t socklen_t; - -/* - * Types - */ -#define SOCK_STREAM 1 /* stream socket */ -#define SOCK_DGRAM 2 /* datagram socket */ -#define SOCK_RAW 3 /* raw-protocol interface */ -#define SOCK_RDM 4 /* reliably-delivered message */ -#define SOCK_SEQPACKET 5 /* sequenced packet stream */ - -/* - * Address families. - */ -#define AF_UNSPEC 0 /* unspecified */ -#define AF_LOCAL 1 /* local to host (pipes, portals) */ -#define AF_UNIX AF_LOCAL /* backward compatibility */ -#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ -#define AF_IMPLINK 3 /* arpanet imp addresses */ -#define AF_PUP 4 /* pup protocols: e.g. BSP */ -#define AF_CHAOS 5 /* mit CHAOS protocols */ -#define AF_NS 6 /* XEROX NS protocols */ -#define AF_ISO 7 /* ISO protocols */ -#define AF_OSI AF_ISO -#define AF_ECMA 8 /* European computer manufacturers */ -#define AF_DATAKIT 9 /* datakit protocols */ -#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ -#define AF_SNA 11 /* IBM SNA */ -#define AF_DECnet 12 /* DECnet */ -#define AF_DLI 13 /* DEC Direct data link interface */ -#define AF_LAT 14 /* LAT */ -#define AF_HYLINK 15 /* NSC Hyperchannel */ -#define AF_APPLETALK 16 /* Apple Talk */ -#define AF_ROUTE 17 /* Internal Routing Protocol */ -#define AF_LINK 18 /* Link layer interface */ -#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ -#define AF_COIP 20 /* connection-oriented IP, aka ST II */ -#define AF_CNT 21 /* Computer Network Technology */ -#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ -#define AF_IPX 23 /* Novell Internet Protocol */ -#define AF_SIP 24 /* Simple Internet Protocol */ -#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ -#define AF_ISDN 26 /* Integrated Services Digital Network*/ -#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ -#define pseudo_AF_KEY 27 /* Internal key-management function */ -#define AF_INET6 28 /* IPv6 */ -#define AF_NATM 29 /* native ATM access */ -#define AF_ATM 30 /* ATM */ -#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers - * in interface output routine - */ -#define AF_NETGRAPH 32 /* Netgraph sockets */ -#define AF_MAX 33 - -/* - * Protocol families, same as address families for now. - */ -#define PF_UNSPEC AF_UNSPEC -#define PF_LOCAL AF_LOCAL -#define PF_UNIX PF_LOCAL /* backward compatibility */ -#define PF_INET AF_INET -#define PF_IMPLINK AF_IMPLINK -#define PF_PUP AF_PUP -#define PF_CHAOS AF_CHAOS -#define PF_NS AF_NS -#define PF_ISO AF_ISO -#define PF_OSI AF_ISO -#define PF_ECMA AF_ECMA -#define PF_DATAKIT AF_DATAKIT -#define PF_CCITT AF_CCITT -#define PF_SNA AF_SNA -#define PF_DECnet AF_DECnet -#define PF_DLI AF_DLI -#define PF_LAT AF_LAT -#define PF_HYLINK AF_HYLINK -#define PF_APPLETALK AF_APPLETALK -#define PF_ROUTE AF_ROUTE -#define PF_LINK AF_LINK -#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ -#define PF_COIP AF_COIP -#define PF_CNT AF_CNT -#define PF_SIP AF_SIP -#define PF_IPX AF_IPX /* same format as AF_NS */ -#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ -#define PF_PIP pseudo_AF_PIP -#define PF_ISDN AF_ISDN -#define PF_KEY pseudo_AF_KEY -#define PF_INET6 AF_INET6 -#define PF_NATM AF_NATM -#define PF_ATM AF_ATM -#define PF_NETGRAPH AF_NETGRAPH -#define PF_MAX AF_MAX +#include "tcp.h" +#include "udp.h" #define MAX_SOCKETS 5 // #define MAX_QUEUED_SOCKETS 2 -#define EPHEMERAL_PORTS 49152 - -#define STATIC_MSS 48 -#define STATIC_WINDOW 1 * STATIC_MSS -#define MAX_TCP_BUFFER 1 * STATIC_WINDOW - #define INC_PACKET 0 #define OUT_PACKET 1 -#define SEND_MSG_BUF_SIZE 64 - -typedef struct socka6 { - uint8_t sin6_family; /* AF_INET6 */ - uint16_t sin6_port; /* transport layer port # */ - uint32_t sin6_flowinfo; /* IPv6 flow information */ - ipv6_addr_t sin6_addr; /* IPv6 address */ -} sockaddr6_t; - -typedef struct tcp_hc_con { +typedef struct __attribute__((packed)) { uint16_t context_id; uint32_t seq_rcv; // Last received packet values uint32_t ack_rcv; @@ -156,7 +23,7 @@ typedef struct tcp_hc_con { uint8_t hc_type; } tcp_hc_context_t; -typedef struct tcp_control_block { +typedef struct __attribute__((packed)) { uint32_t send_una; uint32_t send_nxt; uint16_t send_wnd; @@ -179,10 +46,9 @@ typedef struct tcp_control_block { #ifdef TCP_HC tcp_hc_context_t tcp_context; #endif - } tcp_cb_t; -typedef struct sock_t { +typedef struct __attribute__((packed)) { uint8_t domain; uint8_t type; uint8_t protocol; @@ -191,60 +57,38 @@ typedef struct sock_t { sockaddr6_t foreign_address; } socket_t; -typedef struct socket_in_t { +typedef struct __attribute__((packed)) { uint8_t socket_id; uint8_t recv_pid; uint8_t send_pid; uint8_t tcp_input_buffer_end; mutex_t tcp_buffer_mutex; socket_t socket_values; - uint8_t tcp_input_buffer[MAX_TCP_BUFFER]; + uint8_t tcp_input_buffer[DESTINY_SOCKET_MAX_TCP_BUFFER]; } socket_internal_t; extern socket_internal_t sockets[MAX_SOCKETS]; -int socket(int domain, int type, int protocol); -int connect(int socket, sockaddr6_t *addr, socklen_t addrlen); -socket_internal_t *getWaitingConnectionSocket(int socket, - ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header); +socket_internal_t *get_waiting_connection_socket(int socket, + ipv6_hdr_t *ipv6_header, + tcp_hdr_t *tcp_header); void close_socket(socket_internal_t *current_socket); -int32_t recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, - socklen_t *fromlen); -int32_t sendto(int s, const void *msg, uint32_t len, int flags, - sockaddr6_t *to, socklen_t tolen); -int32_t send(int s, void *msg, uint32_t len, int flags); -int recv(int s, void *buf, uint32_t len, int flags); -int close(int s); -int bind(int s, sockaddr6_t *name, int namelen); -int listen(int s, int backlog); -int accept(int s, sockaddr6_t *addr, socklen_t *addrlen); -void socket_init(void); -socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header); -socket_internal_t *get_tcp_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header); -socket_internal_t *getSocket(uint8_t s); -void print_sockets(void); -void print_internal_socket(socket_internal_t *current_socket_internal); -void print_socket(socket_t *current_socket); -void printf_tcp_context(tcp_hc_context_t *current_tcp_context); -bool exists_socket(uint8_t socket); +socket_internal_t *get_socket(int s); +socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, + udp_hdr_t *udp_header); +socket_internal_t *get_tcp_socket(ipv6_hdr_t *ipv6_header, + tcp_hdr_t *tcp_header); socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header); void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_t *tcp_socket); -void set_socket_address(sockaddr6_t *sockaddr, sa_family_t sin6_family, - uint16_t sin6_port, uint32_t sin6_flowinfo, - ipv6_addr_t *sin6_addr); void set_tcp_cb(tcp_cb_t *tcp_control, uint32_t rcv_nxt, uint16_t rcv_wnd, uint32_t send_nxt, uint32_t send_una, uint16_t send_wnd); -void set_tcp_packet(tcp_hdr_t *tcp_hdr, uint16_t src_port, uint16_t dst_port, - uint32_t seq_nr, uint32_t ack_nr, - uint8_t dataOffset_reserved, uint8_t reserved_flags, - uint16_t window, uint16_t checksum, uint16_t urg_pointer); int check_tcp_consistency(socket_t *current_tcp_socket, tcp_hdr_t *tcp_header); void switch_tcp_packet_byte_order(tcp_hdr_t *current_tcp_packet); int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, ipv6_hdr_t *temp_ipv6_header, uint8_t flags, uint8_t payload_length); -bool isTCPSocket(uint8_t s); -#endif /* SOCKET_H_ */ +bool is_tcp_socket(int s); + +#endif /* _DESTINY_SOCKET */ diff --git a/sys/net/destiny/tcp.c b/sys/net/destiny/tcp.c index ddd44ae1fa..d59af1ffd2 100644 --- a/sys/net/destiny/tcp.c +++ b/sys/net/destiny/tcp.c @@ -27,11 +27,12 @@ #include "tcp_hc.h" #include "tcp.h" #include "destiny/in.h" -#include "socket.h" #include "../net_help/net_help.h" #include "../net_help/msg_help.h" #include "sixlowpan.h" +#include "socket.h" + void printTCPHeader(tcp_hdr_t *tcp_header) { printf("\nBEGIN: TCP HEADER\n"); @@ -122,8 +123,8 @@ void handle_tcp_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, msg_send(&m_send_tcp, tcp_socket->send_pid, 0); return; } - else if (getWaitingConnectionSocket(tcp_socket->socket_id, ipv6_header, - tcp_header) != NULL) { + else if (get_waiting_connection_socket(tcp_socket->socket_id, ipv6_header, + tcp_header) != NULL) { m_send_tcp.content.ptr = (char *)tcp_header; net_msg_send_recv(&m_send_tcp, &m_recv_tcp, tcp_socket->recv_pid, TCP_ACK); return; @@ -158,10 +159,10 @@ void handle_tcp_syn_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, #ifdef TCP_HC update_tcp_hc_context(true, new_socket, tcp_header); #endif - /* notify socket function accept(..) that a new connection request - * has arrived. No need to wait for an answer because the server - * accept() function isnt reading from anything other than the - * queued sockets */ + /* notify socket function destiny_socket_accept(..) that a new + * connection request has arrived. No need to wait for an answer + * because the server destiny_socket_accept() function isnt reading + * from anything other than the queued sockets */ net_msg_send(&m_send_tcp, tcp_socket->recv_pid, 0, TCP_SYN); } else { diff --git a/sys/net/destiny/tcp_hc.c b/sys/net/destiny/tcp_hc.c index 55cae3093f..1af76d38ff 100644 --- a/sys/net/destiny/tcp_hc.c +++ b/sys/net/destiny/tcp_hc.c @@ -21,11 +21,12 @@ #include #include "tcp_hc.h" -#include "socket.h" #include "tcp.h" #include "ipv6.h" #include "../net_help/net_help.h" +#include "socket.h" + #ifdef TCP_HC socket_internal_t *get_tcp_socket_by_context(ipv6_hdr_t *current_ipv6_header, @@ -34,7 +35,7 @@ socket_internal_t *get_tcp_socket_by_context(ipv6_hdr_t *current_ipv6_header, socket_internal_t *temp_socket; for (int i = 1; i < MAX_SOCKETS + 1; i++) { - temp_socket = getSocket(i); + temp_socket = get_socket(i); if ((temp_socket != NULL) && ipv6_addr_is_equal(&temp_socket->socket_values.foreign_address.sin6_addr, diff --git a/sys/net/destiny/tcp_hc.h b/sys/net/destiny/tcp_hc.h index e6cfbb7065..e7a26782c0 100644 --- a/sys/net/destiny/tcp_hc.h +++ b/sys/net/destiny/tcp_hc.h @@ -10,7 +10,7 @@ #include "tcp.h" #include "sixlowpan.h" -#include "socket.h" +#include "destiny/socket.h" #ifdef TCP_HC diff --git a/sys/net/destiny/tcp_timer.c b/sys/net/destiny/tcp_timer.c index a60b96ac7e..2b35561dd3 100644 --- a/sys/net/destiny/tcp_timer.c +++ b/sys/net/destiny/tcp_timer.c @@ -25,10 +25,11 @@ #include "vtimer.h" #include "thread.h" #include "destiny.h" -#include "socket.h" #include "../net_help/msg_help.h" #include "sixlowpan.h" +#include "socket.h" + void handle_synchro_timeout(socket_internal_t *current_socket) { msg_t send; @@ -101,9 +102,9 @@ void check_sockets(void) uint8_t i = 1; while (i < MAX_SOCKETS + 1) { - current_socket = getSocket(i); + current_socket = get_socket(i); - if (isTCPSocket(i)) { + if (is_tcp_socket(i)) { switch(current_socket->socket_values.tcp_control.state) { case ESTABLISHED: { handle_established(current_socket); diff --git a/sys/net/destiny/udp.c b/sys/net/destiny/udp.c index a018db8755..49cc03638b 100644 --- a/sys/net/destiny/udp.c +++ b/sys/net/destiny/udp.c @@ -24,11 +24,12 @@ #include "msg.h" #include "ipv6.h" #include "sixlowpan.h" -#include "socket.h" #include "destiny/in.h" #include "../net_help/net_help.h" #include "../net_help/msg_help.h" +#include "socket.h" + uint16_t udp_csum(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header) { uint16_t sum; diff --git a/sys/net/net_help/Makefile b/sys/net/net_help/Makefile index 158b6d764f..f8bae1eb97 100644 --- a/sys/net/net_help/Makefile +++ b/sys/net/net_help/Makefile @@ -1,4 +1,4 @@ MODULE:=$(shell basename $(CURDIR)) -INCLUDES += -I$(RIOTBASE)/sys/net/destiny/ -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/sys/net/sixlowpan/include +INCLUDES += -I$(RIOTBASE)/sys/net/destiny/include -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/sys/net/sixlowpan/include include $(RIOTBASE)/Makefile.base diff --git a/sys/net/net_help/inet_ntop.c b/sys/net/net_help/inet_ntop.c index 0221ae214d..f35e16d7d1 100644 --- a/sys/net/net_help/inet_ntop.c +++ b/sys/net/net_help/inet_ntop.c @@ -18,7 +18,7 @@ #include #include -#include "socket.h" +#include "destiny/socket.h" #include "inet_ntop.h" diff --git a/sys/net/net_help/inet_pton.c b/sys/net/net_help/inet_pton.c index baf812a0da..05fc033386 100644 --- a/sys/net/net_help/inet_pton.c +++ b/sys/net/net_help/inet_pton.c @@ -18,7 +18,7 @@ #include #include -#include "socket.h" +#include "destiny/socket.h" #include "inet_pton.h" diff --git a/sys/net/sixlowpan/ip.c b/sys/net/sixlowpan/ip.c index 67f1e9ea9d..12c169c571 100644 --- a/sys/net/sixlowpan/ip.c +++ b/sys/net/sixlowpan/ip.c @@ -31,6 +31,7 @@ #include "icmp.h" #include "lowpan.h" +#include "destiny/socket.h" #include "net_help.h" #define IP_PKT_RECV_BUF_SIZE (64) From 75064eb630633799c3c46f719c583a9980c6f5fa Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Mon, 23 Sep 2013 18:06:14 +0200 Subject: [PATCH 06/11] Add documentation for destiny/socket.h --- sys/net/destiny/include/destiny/socket.h | 314 +++++++++++++++-------- 1 file changed, 213 insertions(+), 101 deletions(-) diff --git a/sys/net/destiny/include/destiny/socket.h b/sys/net/destiny/include/destiny/socket.h index d8a8d3febc..f68d931bb6 100644 --- a/sys/net/destiny/include/destiny/socket.h +++ b/sys/net/destiny/include/destiny/socket.h @@ -11,6 +11,9 @@ * @{ * @file * @brief Header for BSD socket API + * @see + * IEEE Std 1003.1, 2013 Edition - sys/socket.h + * * @author Oliver Gesch * @author Martin Lenders */ @@ -23,119 +26,182 @@ #include "ipv6.h" #include "destiny/in.h" +typedef uint8_t sa_family_t; ///< POSIX compatible type for address family. +typedef uint32_t socklen_t; ///< POSIX compatible type for address length. + + +#define SOCK_STREAM 1 ///< POSIX compatible stream socket type. +#define SOCK_DGRAM 2 ///< POSIX compatible datagram socket type. +#define SOCK_RAW 3 ///< POSIX compatible raw-protocol interface type. +#define SOCK_RDM 4 ///< POSIX compatible reliably-delivered message type. +#define SOCK_SEQPACKET 5 ///< POSIX compatible sequenced packet stream type. + +#define AF_UNSPEC 0 ///< unspecified address family. +#define AF_LOCAL 1 ///< local to host (pipes, portals) address family. +#define AF_UNIX AF_LOCAL ///< alias for AF_LOCAL for backward compatibility. +#define AF_INET 2 ///< internetwork address family: UDP, TCP, etc. +#define AF_IMPLINK 3 ///< ARPAnet IMP address family. +#define AF_PUP 4 ///< PUP protocols address family: e.g. BSP +#define AF_CHAOS 5 ///< MIT CHAOS protocols address family +#define AF_NS 6 ///< XEROX NS protocols address family +#define AF_ISO 7 ///< ISO protocols address family +#define AF_OSI AF_ISO ///< alias for AF_ISO +#define AF_ECMA 8 ///< European computer manufacturers address family +#define AF_DATAKIT 9 ///< datakit protocols address family +#define AF_CCITT 10 ///< CCITT protocols address family, X.25 etc +#define AF_SNA 11 ///< IBM SNA address family +#define AF_DECnet 12 ///< DECnet address family +#define AF_DLI 13 ///< DEC Direct data link interface address family +#define AF_LAT 14 ///< LAT address family +#define AF_HYLINK 15 ///< NSC Hyperchannel address family +#define AF_APPLETALK 16 ///< Apple Talk address family +#define AF_ROUTE 17 ///< Internal Routing Protocol address family +#define AF_LINK 18 ///< Link layer interface address family +#define pseudo_AF_XTP 19 ///< eXpress Transfer Protocol (no AF) +#define AF_COIP 20 ///< connection-oriented IP, aka ST II address family. +#define AF_CNT 21 ///< Computer Network Technology address family +#define pseudo_AF_RTIP 22 ///< Help Identify RTIP packets address family +#define AF_IPX 23 ///< Novell Internet Protocol (no AF) +#define AF_SIP 24 ///< Simple Internet Protocol address family +#define pseudo_AF_PIP 25 ///< Help Identify PIP packets (no AF) +#define AF_ISDN 26 ///< Integrated Services Digital Network address family +#define AF_E164 AF_ISDN ///< CCITT E.164 recommendation +#define pseudo_AF_KEY 27 ///< Internal key-management function (no AF) /** - * POSIX compatible type for address family. + * IPv6 address family. * - * @see - * IEEE Std 1003.1, 2013 Edition - sys/socket.h - * + * @see AF_INET */ -typedef uint8_t sa_family_t; -typedef uint32_t socklen_t; ///< POSIX compatible type for address lengths. - -/* - * Types - */ -#define SOCK_STREAM 1 /* stream socket */ -#define SOCK_DGRAM 2 /* datagram socket */ -#define SOCK_RAW 3 /* raw-protocol interface */ -#define SOCK_RDM 4 /* reliably-delivered message */ -#define SOCK_SEQPACKET 5 /* sequenced packet stream */ - -/* - * Address families. - */ -#define AF_UNSPEC 0 /* unspecified */ -#define AF_LOCAL 1 /* local to host (pipes, portals) */ -#define AF_UNIX AF_LOCAL /* backward compatibility */ -#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ -#define AF_IMPLINK 3 /* arpanet imp addresses */ -#define AF_PUP 4 /* pup protocols: e.g. BSP */ -#define AF_CHAOS 5 /* mit CHAOS protocols */ -#define AF_NS 6 /* XEROX NS protocols */ -#define AF_ISO 7 /* ISO protocols */ -#define AF_OSI AF_ISO -#define AF_ECMA 8 /* European computer manufacturers */ -#define AF_DATAKIT 9 /* datakit protocols */ -#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ -#define AF_SNA 11 /* IBM SNA */ -#define AF_DECnet 12 /* DECnet */ -#define AF_DLI 13 /* DEC Direct data link interface */ -#define AF_LAT 14 /* LAT */ -#define AF_HYLINK 15 /* NSC Hyperchannel */ -#define AF_APPLETALK 16 /* Apple Talk */ -#define AF_ROUTE 17 /* Internal Routing Protocol */ -#define AF_LINK 18 /* Link layer interface */ -#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ -#define AF_COIP 20 /* connection-oriented IP, aka ST II */ -#define AF_CNT 21 /* Computer Network Technology */ -#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ -#define AF_IPX 23 /* Novell Internet Protocol */ -#define AF_SIP 24 /* Simple Internet Protocol */ -#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ -#define AF_ISDN 26 /* Integrated Services Digital Network*/ -#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ -#define pseudo_AF_KEY 27 /* Internal key-management function */ -#define AF_INET6 28 /* IPv6 */ -#define AF_NATM 29 /* native ATM access */ -#define AF_ATM 30 /* ATM */ -#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers - * in interface output routine - */ -#define AF_NETGRAPH 32 /* Netgraph sockets */ -#define AF_MAX 33 +#define AF_INET6 28 +#define AF_NATM 29 ///< native ATM access address family +#define AF_ATM 30 ///< ATM address family +#define pseudo_AF_HDRCMPLT 31 ///< Used by BPF to not rewrite headers in interface output routine +#define AF_NETGRAPH 32 ///< Netgraph sockets address family +#define AF_MAX 33 ///< Maximum for address families /* * Protocol families, same as address families for now. */ -#define PF_UNSPEC AF_UNSPEC -#define PF_LOCAL AF_LOCAL -#define PF_UNIX PF_LOCAL /* backward compatibility */ -#define PF_INET AF_INET -#define PF_IMPLINK AF_IMPLINK -#define PF_PUP AF_PUP -#define PF_CHAOS AF_CHAOS -#define PF_NS AF_NS -#define PF_ISO AF_ISO -#define PF_OSI AF_ISO -#define PF_ECMA AF_ECMA -#define PF_DATAKIT AF_DATAKIT -#define PF_CCITT AF_CCITT -#define PF_SNA AF_SNA -#define PF_DECnet AF_DECnet -#define PF_DLI AF_DLI -#define PF_LAT AF_LAT -#define PF_HYLINK AF_HYLINK -#define PF_APPLETALK AF_APPLETALK -#define PF_ROUTE AF_ROUTE -#define PF_LINK AF_LINK -#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ -#define PF_COIP AF_COIP -#define PF_CNT AF_CNT -#define PF_SIP AF_SIP -#define PF_IPX AF_IPX /* same format as AF_NS */ -#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ -#define PF_PIP pseudo_AF_PIP -#define PF_ISDN AF_ISDN -#define PF_KEY pseudo_AF_KEY -#define PF_INET6 AF_INET6 -#define PF_NATM AF_NATM -#define PF_ATM AF_ATM -#define PF_NETGRAPH AF_NETGRAPH -#define PF_MAX AF_MAX +#define PF_UNSPEC AF_UNSPEC ///< protocol family + ///< @see AF_UNSPEC +#define PF_LOCAL AF_LOCAL ///< protocol family + ///< @see AF_LOCAL +#define PF_UNIX PF_LOCAL ///< alias for PF_LOCAL for backward compatibility +#define PF_INET AF_INET ///< protocol family + ///< @see AF_INET +#define PF_IMPLINK AF_IMPLINK ///< protocol family + ///< @see AF_IMPLINK +#define PF_PUP AF_PUP ///< protocol family + ///< @see AF_PUP +#define PF_CHAOS AF_CHAOS ///< protocol family + ///< @see AF_CHAOS +#define PF_NS AF_NS ///< protocol family + ///< @see AF_NS +#define PF_ISO AF_ISO ///< protocol family + ///< @see AF_ISO +#define PF_OSI AF_OSI ///< protocol family + ///< @see AF_OSI +#define PF_ECMA AF_ECMA ///< protocol family + ///< @see AF_ECMA +#define PF_DATAKIT AF_DATAKIT ///< protocol family + ///< @see AF_DATAKIT +#define PF_CCITT AF_CCITT ///< protocol family + ///< @see AF_CCITT +#define PF_SNA AF_SNA ///< protocol family + ///< @see AF_SNA +#define PF_DECnet AF_DECnet ///< protocol family + ///< @see AF_DECnet +#define PF_DLI AF_DLI ///< protocol family + ///< @see AF_DLI +#define PF_LAT AF_LAT ///< protocol family + ///< @see AF_LAT +#define PF_HYLINK AF_HYLINK ///< protocol family + ///< @see AF_HYLINK +#define PF_APPLETALK AF_APPLETALK ///< protocol family + ///< @see AF_APPLETALK +#define PF_ROUTE AF_ROUTE ///< protocol family + ///< @see AF_ROUTE +#define PF_LINK AF_LINK ///< protocol family + ///< @see AF_LINK +#define PF_XTP pseudo_AF_XTP ///< protocol family (no address family defined, only PF) + ///< @see pseudo_AF_XTP +#define PF_COIP AF_COIP ///< protocol family + ///< @see AF_COIP +#define PF_CNT AF_CNT ///< protocol family + ///< @see AF_CNT +#define PF_SIP AF_SIP ///< protocol family + ///< @see AF_SIP +#define PF_IPX AF_IPX ///< protocol family (same format as AF_NS) + ///< @see AF_IPX + ///< @see AF_NS +#define PF_RTIP pseudo_AF_RTIP ///< protocol family (same format as AF_INET) + ///< @see pseudo_AF_RTIP +#define PF_PIP pseudo_AF_PIP ///< protocol family + ///< @see pseudo_AF_PIP +#define PF_ISDN AF_ISDN ///< protocol family + ///< @see AF_ISDN +#define PF_KEY pseudo_AF_KEY ///< protocol family + ///< @see pseudo_AF_KEY +#define PF_INET6 AF_INET6 ///< protocol family + ///< @see AF_INET6 +#define PF_NATM AF_NATM ///< protocol family + ///< @see AF_NATM +#define PF_ATM AF_ATM ///< protocol family + ///< @see AF_ATM +#define PF_NETGRAPH AF_NETGRAPH ///< protocol family + ///< @see AF_NETGRAPH +#define PF_MAX AF_MAX ///< maximum of protocol families + ///< @see AF_MAX -#define DESTINY_SOCKET_STATIC_MSS 48 +#define DESTINY_SOCKET_STATIC_MSS 48 ///< Static TCP maxmimum segment size. + +/** + * Static TCP flow control window for window size 1. + */ #define DESTINY_SOCKET_STATIC_WINDOW 1 * DESTINY_SOCKET_STATIC_MSS + +/** + * Maximum size of TCP buffer. + */ #define DESTINY_SOCKET_MAX_TCP_BUFFER 1 * DESTINY_SOCKET_STATIC_WINDOW +/** + * Socket address type for IPv6 communication. + */ typedef struct __attribute__((packed)) { - uint8_t sin6_family; /* AF_INET6 */ - uint16_t sin6_port; /* transport layer port # */ - uint32_t sin6_flowinfo; /* IPv6 flow information */ - ipv6_addr_t sin6_addr; /* IPv6 address */ + uint8_t sin6_family; ///< set to AF_INET6 + uint16_t sin6_port; ///< transport layer port number + uint32_t sin6_flowinfo; ///< IPv6 flow information + ipv6_addr_t sin6_addr; ///< IPv6 address } sockaddr6_t; +/** + * Creates new socket for communication in family *domain*, of type *type*, + * and with protocol *protocol*. Roughly identical to POSIX's + * socket(2). + * + * @param[in] domain Address family. Only AF_INET6 is supported by now (no + * check on creation). + * @param[in] type Communication type. + * @param[in] protocol Protocol type. May be left 0 if domain and type are + * sufficiant enough (I. e. domain=AF_INET6 and type=SOCK_STREAM + * imply IPPROTO_TCP, etc.) + * @return Socket ID on success, -1 otherwise. + */ int destiny_socket(int domain, int type, int protocol); + +/** + * Connects socket *socket* with a foreign host with IPv6 address *addr* + * (of length *addrlen*) for connection orientated communication (e. g. + * SOCK_STREAM). Roughly identical to POSIX's + * connect(2). + * + * @param[in] socket The ID of the socket. + * @param[in] addr The IPv6 address to connect to + * @param[in] addrlen Length of the IPv6 address in byte (always 16) + * + * @return 0 on success, -1 otherwise + */ int destiny_socket_connect(int socket, sockaddr6_t *addr, socklen_t addrlen); @@ -201,12 +267,58 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags); */ int32_t destiny_socket_sendto(int s, const void *buf, uint32_t len, int flags, sockaddr6_t *to, socklen_t tolen); -int32_t destiny_socket_send(int s, void *msg, uint32_t len, int flags); -int32_t destiny_socket_recv(int s, void *buf, uint32_t len, int flags); + +/** + * Closes the socket *s* and removes it. + * + * @param[in] s The ID of the socket to close. + * + * @return 0 on success, -1 otherwise. + */ int destiny_socket_close(int s); -int destiny_socket_bind(int s, sockaddr6_t *name, int namelen); + +/** + * Assigns an IPv6 address *addr* to the socket *s*. Roughly identical to + * POSIX's bind(2). + * + * @param[in] s The ID of the socket. + * @param[in] addr The IPv6 address to bind to. + * @param[in] addrlen Length of address in byte (always 16) + * + * @return 0 on success, -1 otherwise. + */ +int destiny_socket_bind(int s, sockaddr6_t *addr, int addrlen); + +/** + * Marks socket *s* as an passive socket, that listens for incoming messages. + * Roughly identical to POSIX's listen(2). + * + * @param[in] s The ID of the socket. + * @param[in] backlog Not implemented yet, may be 0. + * + * @return 0 on success, -1 otherwise. + */ int destiny_socket_listen(int s, int backlog); + +/** + * Blocks the current thread and waits for incoming communication on the listening + * socket *s*. Roughly identical to POSIX's + * accept(2). + * + * @param[in] s The ID of the socket. + * @param[in] addr The IPv6 address of the peer socket, or NULL if not + * needed (not implemented yet). + * @param[in] addrlen The length of *addr*, or NULL if not needed. + * + * @return New socket ID for communication. -1 on error. + */ int destiny_socket_accept(int s, sockaddr6_t *addr, socklen_t *addrlen); + +/** + * Outputs a list of all open sockets to stdout. Information includes its + * creation parameters, local and foreign address and ports, it's ID and the + * PIDs of the send and receive thread. + */ void destiny_socket_print_sockets(void); /** From 94217d03e8477549087b490b192d832c0b939ccd Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Mon, 30 Sep 2013 12:58:47 +0200 Subject: [PATCH 07/11] Move msg_help to destiny --- sys/net/{net_help => destiny}/msg_help.c | 0 sys/net/{net_help => destiny}/msg_help.h | 0 sys/net/destiny/socket.c | 2 +- sys/net/destiny/tcp.c | 2 +- sys/net/destiny/tcp_timer.c | 2 +- sys/net/destiny/udp.c | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename sys/net/{net_help => destiny}/msg_help.c (100%) rename sys/net/{net_help => destiny}/msg_help.h (100%) diff --git a/sys/net/net_help/msg_help.c b/sys/net/destiny/msg_help.c similarity index 100% rename from sys/net/net_help/msg_help.c rename to sys/net/destiny/msg_help.c diff --git a/sys/net/net_help/msg_help.h b/sys/net/destiny/msg_help.h similarity index 100% rename from sys/net/net_help/msg_help.h rename to sys/net/destiny/msg_help.h diff --git a/sys/net/destiny/socket.c b/sys/net/destiny/socket.c index b678b41bb1..c4a983dfa2 100644 --- a/sys/net/destiny/socket.c +++ b/sys/net/destiny/socket.c @@ -26,10 +26,10 @@ #include "tcp.h" #include "vtimer.h" #include "hwtimer.h" +#include "msg_help.h" #include "tcp_timer.h" #include "tcp_hc.h" #include "../net_help/net_help.h" -#include "../net_help/msg_help.h" #include "socket.h" diff --git a/sys/net/destiny/tcp.c b/sys/net/destiny/tcp.c index d59af1ffd2..a91892ed86 100644 --- a/sys/net/destiny/tcp.c +++ b/sys/net/destiny/tcp.c @@ -27,8 +27,8 @@ #include "tcp_hc.h" #include "tcp.h" #include "destiny/in.h" +#include "msg_help.h" #include "../net_help/net_help.h" -#include "../net_help/msg_help.h" #include "sixlowpan.h" #include "socket.h" diff --git a/sys/net/destiny/tcp_timer.c b/sys/net/destiny/tcp_timer.c index 2b35561dd3..35178f5053 100644 --- a/sys/net/destiny/tcp_timer.c +++ b/sys/net/destiny/tcp_timer.c @@ -22,10 +22,10 @@ #include #include #include "tcp_timer.h" +#include "msg_help.h" #include "vtimer.h" #include "thread.h" #include "destiny.h" -#include "../net_help/msg_help.h" #include "sixlowpan.h" #include "socket.h" diff --git a/sys/net/destiny/udp.c b/sys/net/destiny/udp.c index 49cc03638b..b1f78e7c9c 100644 --- a/sys/net/destiny/udp.c +++ b/sys/net/destiny/udp.c @@ -26,7 +26,7 @@ #include "sixlowpan.h" #include "destiny/in.h" #include "../net_help/net_help.h" -#include "../net_help/msg_help.h" +#include "msg_help.h" #include "socket.h" From 4825ec21b9a23bfbe878cd29f420cde6fedff451 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Mon, 30 Sep 2013 13:19:19 +0200 Subject: [PATCH 08/11] Order includes in destiny --- sys/net/destiny/destiny.c | 9 ++++---- sys/net/destiny/include/destiny/socket.h | 2 ++ sys/net/destiny/msg_help.c | 6 +++++- sys/net/destiny/msg_help.h | 2 ++ sys/net/destiny/socket.c | 25 +++++++++++++---------- sys/net/destiny/socket.h | 4 +++- sys/net/destiny/tcp.c | 26 +++++++++++++----------- sys/net/destiny/tcp.h | 4 ++-- sys/net/destiny/tcp_hc.c | 8 +++++--- sys/net/destiny/tcp_hc.h | 4 +++- sys/net/destiny/tcp_timer.c | 24 ++++++++++++---------- sys/net/destiny/udp.c | 16 ++++++++------- sys/net/destiny/udp.h | 4 ++-- 13 files changed, 79 insertions(+), 55 deletions(-) diff --git a/sys/net/destiny/destiny.c b/sys/net/destiny/destiny.c index 04589e6770..d61d992cef 100644 --- a/sys/net/destiny/destiny.c +++ b/sys/net/destiny/destiny.c @@ -19,13 +19,14 @@ #include #include #include -#include -#include "udp.h" -#include "tcp.h" -#include "tcp_timer.h" + #include "destiny.h" +#include "vtimer.h" #include "socket.h" +#include "tcp.h" +#include "tcp_timer.h" +#include "udp.h" char tcp_stack_buffer[TCP_STACK_SIZE]; char udp_stack_buffer[UDP_STACK_SIZE]; diff --git a/sys/net/destiny/include/destiny/socket.h b/sys/net/destiny/include/destiny/socket.h index f68d931bb6..b0009dd7b0 100644 --- a/sys/net/destiny/include/destiny/socket.h +++ b/sys/net/destiny/include/destiny/socket.h @@ -23,7 +23,9 @@ #define DESTINY_SOCKET_H #include + #include "ipv6.h" + #include "destiny/in.h" typedef uint8_t sa_family_t; ///< POSIX compatible type for address family. diff --git a/sys/net/destiny/msg_help.c b/sys/net/destiny/msg_help.c index e12840d466..74888b83f2 100644 --- a/sys/net/destiny/msg_help.c +++ b/sys/net/destiny/msg_help.c @@ -7,9 +7,13 @@ #include #include -#include "msg_help.h" + +#include "thread.h" + #include "tcp_timer.h" +#include "msg_help.h" + void block_continue_thread(void) { // msg_t recv_m; diff --git a/sys/net/destiny/msg_help.h b/sys/net/destiny/msg_help.h index 37993d2435..6068dbbd29 100644 --- a/sys/net/destiny/msg_help.h +++ b/sys/net/destiny/msg_help.h @@ -8,6 +8,8 @@ #ifndef MSG_HELP_H_ #define MSG_HELP_H_ +#include + // Function IDs #define FID_SIXLOWIP_TCP 0 #define FID_SIXLOWIP_UDP 1 diff --git a/sys/net/destiny/socket.c b/sys/net/destiny/socket.c index c4a983dfa2..f479e82405 100644 --- a/sys/net/destiny/socket.c +++ b/sys/net/destiny/socket.c @@ -15,22 +15,25 @@ * @} */ -#include -#include -#include -#include #include #include -#include "ipv6.h" -#include "udp.h" -#include "tcp.h" -#include "vtimer.h" +#include +#include +#include + #include "hwtimer.h" -#include "msg_help.h" -#include "tcp_timer.h" -#include "tcp_hc.h" +#include "ipv6.h" +#include "thread.h" +#include "vtimer.h" + #include "../net_help/net_help.h" +#include "msg_help.h" +#include "tcp.h" +#include "tcp_hc.h" +#include "tcp_timer.h" +#include "udp.h" + #include "socket.h" #define EPHEMERAL_PORTS 49152 diff --git a/sys/net/destiny/socket.h b/sys/net/destiny/socket.h index 978eb76a40..7bd639f918 100644 --- a/sys/net/destiny/socket.h +++ b/sys/net/destiny/socket.h @@ -1,8 +1,10 @@ #ifndef _DESTINY_SOCKET #define _DESTINY_SOCKET -#include "destiny/socket.h" + #include "cpu.h" +#include "destiny/socket.h" + #include "tcp.h" #include "udp.h" diff --git a/sys/net/destiny/tcp.c b/sys/net/destiny/tcp.c index a91892ed86..881408f324 100644 --- a/sys/net/destiny/tcp.c +++ b/sys/net/destiny/tcp.c @@ -15,23 +15,25 @@ * @} */ - -#include -#include -#include -#include #include +#include +#include +#include -#include "vtimer.h" -#include "tcp_timer.h" -#include "tcp_hc.h" -#include "tcp.h" -#include "destiny/in.h" -#include "msg_help.h" -#include "../net_help/net_help.h" #include "sixlowpan.h" +#include "thread.h" +#include "vtimer.h" +#include "destiny/in.h" + +#include "../net_help/net_help.h" + +#include "msg_help.h" #include "socket.h" +#include "tcp_hc.h" +#include "tcp_timer.h" + +#include "tcp.h" void printTCPHeader(tcp_hdr_t *tcp_header) { diff --git a/sys/net/destiny/tcp.h b/sys/net/destiny/tcp.h index 0a1fe5a6db..0980011d03 100644 --- a/sys/net/destiny/tcp.h +++ b/sys/net/destiny/tcp.h @@ -18,6 +18,8 @@ #ifndef TCP_H_ #define TCP_H_ +#include "ipv6.h" + #define TCP_HDR_LEN 20 #define TCP_EOO_OPTION 0x00 // End of option list @@ -78,8 +80,6 @@ enum tcp_codes { #define TCP_STACK_SIZE KERNEL_CONF_STACKSIZE_DEFAULT -#include "ipv6.h" - typedef struct __attribute__((packed)) tcp_mms_o_t { uint8_t kind; uint8_t len; diff --git a/sys/net/destiny/tcp_hc.c b/sys/net/destiny/tcp_hc.c index 1af76d38ff..1a6bbbd444 100644 --- a/sys/net/destiny/tcp_hc.c +++ b/sys/net/destiny/tcp_hc.c @@ -16,16 +16,18 @@ */ +#include #include #include -#include -#include "tcp_hc.h" -#include "tcp.h" #include "ipv6.h" + #include "../net_help/net_help.h" #include "socket.h" +#include "tcp.h" + +#include "tcp_hc.h" #ifdef TCP_HC diff --git a/sys/net/destiny/tcp_hc.h b/sys/net/destiny/tcp_hc.h index e7a26782c0..606b04c07b 100644 --- a/sys/net/destiny/tcp_hc.h +++ b/sys/net/destiny/tcp_hc.h @@ -8,10 +8,12 @@ #ifndef TCP_HC_H_ #define TCP_HC_H_ -#include "tcp.h" #include "sixlowpan.h" + #include "destiny/socket.h" +#include "tcp.h" + #ifdef TCP_HC #define FULL_HEADER 1 diff --git a/sys/net/destiny/tcp_timer.c b/sys/net/destiny/tcp_timer.c index 35178f5053..2b32278356 100644 --- a/sys/net/destiny/tcp_timer.c +++ b/sys/net/destiny/tcp_timer.c @@ -15,21 +15,23 @@ * @} */ - -#include -#include -#include -#include #include -#include "tcp_timer.h" -#include "msg_help.h" -#include "vtimer.h" -#include "thread.h" -#include "destiny.h" -#include "sixlowpan.h" +#include +#include +#include +#include "sixlowpan.h" +#include "thread.h" +#include "vtimer.h" + +#include "destiny.h" + +#include "msg_help.h" #include "socket.h" +#include "tcp_timer.h" + + void handle_synchro_timeout(socket_internal_t *current_socket) { msg_t send; diff --git a/sys/net/destiny/udp.c b/sys/net/destiny/udp.c index b1f78e7c9c..017aec49e9 100644 --- a/sys/net/destiny/udp.c +++ b/sys/net/destiny/udp.c @@ -15,21 +15,23 @@ * @} */ - #include -#include #include -#include "udp.h" -#include "msg.h" #include "ipv6.h" +#include "msg.h" #include "sixlowpan.h" -#include "destiny/in.h" -#include "../net_help/net_help.h" -#include "msg_help.h" +#include "thread.h" +#include "destiny/in.h" + +#include "../net_help/net_help.h" + +#include "msg_help.h" #include "socket.h" +#include "udp.h" + uint16_t udp_csum(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header) { uint16_t sum; diff --git a/sys/net/destiny/udp.h b/sys/net/destiny/udp.h index e92ee266f7..df70a037fe 100644 --- a/sys/net/destiny/udp.h +++ b/sys/net/destiny/udp.h @@ -25,12 +25,12 @@ #ifndef UDP_H_ #define UDP_H_ +#include "ipv6.h" + #define UDP_HDR_LEN 8 #define UDP_STACK_SIZE KERNEL_CONF_STACKSIZE_DEFAULT -#include "ipv6.h" - typedef struct __attribute__((packed)) udp_h_t { uint16_t src_port; uint16_t dst_port; From 6b999dc7bfa2545175d964956d61e59b98391b76 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Mon, 30 Sep 2013 13:28:19 +0200 Subject: [PATCH 09/11] Enforce coding conventions in destiny via astyle --- sys/net/destiny/destiny.c | 6 +- sys/net/destiny/socket.c | 124 ++++++++++++++++++------------------ sys/net/destiny/socket.h | 6 +- sys/net/destiny/tcp.c | 16 ++--- sys/net/destiny/tcp.h | 2 +- sys/net/destiny/tcp_hc.c | 42 ++++++------ sys/net/destiny/tcp_timer.c | 32 +++++----- sys/net/destiny/udp.c | 6 +- sys/net/destiny/udp.h | 2 +- 9 files changed, 118 insertions(+), 118 deletions(-) diff --git a/sys/net/destiny/destiny.c b/sys/net/destiny/destiny.c index d61d992cef..976a87ac73 100644 --- a/sys/net/destiny/destiny.c +++ b/sys/net/destiny/destiny.c @@ -1,5 +1,5 @@ /** - * Destiny transpor layer implementation + * Destiny transport layer implementation * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file destiny.c - * @brief transpor layer functions + * @brief transpor layer functions * @author Oliver Gesch * @} */ diff --git a/sys/net/destiny/socket.c b/sys/net/destiny/socket.c index f479e82405..6d99fa6aba 100644 --- a/sys/net/destiny/socket.c +++ b/sys/net/destiny/socket.c @@ -7,7 +7,7 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file socket.c * @brief functions for BSD socket API @@ -63,7 +63,7 @@ void print_tcp_flags(tcp_hdr_t *tcp_header) { printf("FLAGS: "); - switch(tcp_header->reserved_flags) { + switch (tcp_header->reserved_flags) { case TCP_ACK: { printf("ACK "); break; @@ -109,7 +109,7 @@ void print_tcp_cb(tcp_cb_t *cb) vtimer_now(&now); printf("Send_ISS: %" PRIu32 "\nSend_UNA: %" PRIu32 "\nSend_NXT: %" PRIu32 "\nSend_WND: %u\n", cb->send_iss, cb->send_una, cb->send_nxt, cb->send_wnd); - printf("Rcv_IRS: %" PRIu32 "\nRcv_NXT: %" PRIu32 "\nRcv_WND: %u\n", + printf("Rcv_IRS: %" PRIu32 "\nRcv_NXT: %" PRIu32 "\nRcv_WND: %u\n", cb->rcv_irs, cb->rcv_nxt, cb->rcv_wnd); printf("Time difference: %" PRIu32 ", No_of_retries: %u, State: %u\n\n", timex_sub(now, cb->last_packet_time).microseconds, cb->no_of_retries, cb->state); @@ -121,9 +121,9 @@ void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header, char addr_str[IPV6_MAX_ADDR_STR_LEN]; printf("--- %s TCP packet: ---\n", (in_or_out == INC_PACKET ? "Incoming" : "Outgoing")); - printf("IPv6 Source: %s\n", + printf("IPv6 Source: %s\n", ipv6_addr_to_str(addr_str, &ipv6_header->srcaddr)); - printf("IPv6 Dest: %s\n", + printf("IPv6 Dest: %s\n", ipv6_addr_to_str(addr_str, &ipv6_header->destaddr)); printf("TCP Length: %x\n", ipv6_header->length - TCP_HDR_LEN); printf("Source Port: %x, Dest. Port: %x\n", @@ -148,8 +148,8 @@ void print_socket(socket_t *current_socket) current_socket->domain, current_socket->type, current_socket->protocol); - printf("Local address: %s\n", - ipv6_addr_to_str(addr_str, + printf("Local address: %s\n", + ipv6_addr_to_str(addr_str, ¤t_socket->local_address.sin6_addr)); printf("Foreign address: %s\n", ipv6_addr_to_str(addr_str, @@ -210,10 +210,10 @@ void close_socket(socket_internal_t *current_socket) bool isUDPSocket(uint8_t s) { if ((exists_socket(s)) && - (get_socket(s)->socket_values.domain == PF_INET6) && - (get_socket(s)->socket_values.type == SOCK_DGRAM) && - ((get_socket(s)->socket_values.protocol == IPPROTO_UDP) || - (get_socket(s)->socket_values.protocol == 0))) { + (get_socket(s)->socket_values.domain == PF_INET6) && + (get_socket(s)->socket_values.type == SOCK_DGRAM) && + ((get_socket(s)->socket_values.protocol == IPPROTO_UDP) || + (get_socket(s)->socket_values.protocol == 0))) { return true; } else { @@ -224,10 +224,10 @@ bool isUDPSocket(uint8_t s) bool is_tcp_socket(int s) { if ((exists_socket(s)) && - (get_socket(s)->socket_values.domain == PF_INET6) && - (get_socket(s)->socket_values.type == SOCK_STREAM) && - ((get_socket(s)->socket_values.protocol == IPPROTO_TCP) || - (get_socket(s)->socket_values.protocol == 0))) { + (get_socket(s)->socket_values.domain == PF_INET6) && + (get_socket(s)->socket_values.type == SOCK_STREAM) && + ((get_socket(s)->socket_values.protocol == IPPROTO_TCP) || + (get_socket(s)->socket_values.protocol == 0))) { return true; } else { @@ -245,7 +245,7 @@ int bind_udp_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) for (i = 1; i < MAX_SOCKETS + 1; i++) { if (isUDPSocket(i) && - (get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { + (get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { return -1; } } @@ -265,7 +265,7 @@ int bind_tcp_socket(int s, sockaddr6_t *name, int namelen, uint8_t pid) for (i = 1; i < MAX_SOCKETS + 1; i++) { if (is_tcp_socket(i) && - (get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { + (get_socket(i)->socket_values.local_address.sin6_port == name->sin6_port)) { return -1; } } @@ -304,8 +304,8 @@ socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header while (i < MAX_SOCKETS + 1) { if (isUDPSocket(i) && - (get_socket(i)->socket_values.local_address.sin6_port == - udp_header->dst_port)) { + (get_socket(i)->socket_values.local_address.sin6_port == + udp_header->dst_port)) { return get_socket(i); } @@ -339,20 +339,20 @@ socket_internal_t *get_tcp_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header /* Check for matching 4 touple, ESTABLISHED connection */ if (is_tcp_socket(i) && is_four_touple(current_socket, ipv6_header, - tcp_header)) { + tcp_header)) { return current_socket; } /* Sockets in LISTEN and SYN_RCVD state should only be tested on local TCP values */ else if (is_tcp_socket(i) && - ((current_socket->socket_values.tcp_control.state == LISTEN) || - (current_socket->socket_values.tcp_control.state == SYN_RCVD)) && - (current_socket->socket_values.local_address.sin6_addr.uint8[15] == - ipv6_header->destaddr.uint8[15]) && - (current_socket->socket_values.local_address.sin6_port == - tcp_header->dst_port) && - (current_socket->socket_values.foreign_address.sin6_addr.uint8[15] == - 0x00) && - (current_socket->socket_values.foreign_address.sin6_port == 0)) { + ((current_socket->socket_values.tcp_control.state == LISTEN) || + (current_socket->socket_values.tcp_control.state == SYN_RCVD)) && + (current_socket->socket_values.local_address.sin6_addr.uint8[15] == + ipv6_header->destaddr.uint8[15]) && + (current_socket->socket_values.local_address.sin6_port == + tcp_header->dst_port) && + (current_socket->socket_values.foreign_address.sin6_addr.uint8[15] == + 0x00) && + (current_socket->socket_values.foreign_address.sin6_port == 0)) { listening_socket = current_socket; } @@ -371,7 +371,7 @@ uint16_t get_free_source_port(uint8_t protocol) /* Remember biggest ephemeral port number used so far and add 1 */ for (i = 0; i < MAX_SOCKETS; i++) { if ((sockets[i].socket_values.protocol == protocol) && - (sockets[i].socket_values.local_address.sin6_port > biggest_port)) { + (sockets[i].socket_values.local_address.sin6_port > biggest_port)) { biggest_port = sockets[i].socket_values.local_address.sin6_port; } } @@ -380,7 +380,7 @@ uint16_t get_free_source_port(uint8_t protocol) } void set_socket_address(sockaddr6_t *sockaddr, uint8_t sin6_family, - uint16_t sin6_port, uint32_t sin6_flowinfo, ipv6_addr_t *sin6_addr) + uint16_t sin6_port, uint32_t sin6_flowinfo, ipv6_addr_t *sin6_addr) { sockaddr->sin6_family = sin6_family; sockaddr->sin6_port = sin6_port; @@ -449,7 +449,7 @@ void switch_tcp_packet_byte_order(tcp_hdr_t *current_tcp_packet) } int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, - ipv6_hdr_t *temp_ipv6_header, uint8_t flags, uint8_t payload_length) + ipv6_hdr_t *temp_ipv6_header, uint8_t flags, uint8_t payload_length) { socket_t *current_tcp_socket = ¤t_socket->socket_values; uint8_t header_length = TCP_HDR_LEN / 4; @@ -462,7 +462,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, current_mss_option.len = sizeof(tcp_mss_option_t); current_mss_option.mss = DESTINY_SOCKET_STATIC_MSS; memcpy(((uint8_t *)current_tcp_packet) + TCP_HDR_LEN, - ¤t_mss_option, sizeof(tcp_mss_option_t)); + ¤t_mss_option, sizeof(tcp_mss_option_t)); } set_tcp_packet(current_tcp_packet, current_tcp_socket->local_address.sin6_port, @@ -474,9 +474,9 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, /* Fill IPv6 Header */ memcpy(&(temp_ipv6_header->destaddr), - ¤t_tcp_socket->foreign_address.sin6_addr, 16); + ¤t_tcp_socket->foreign_address.sin6_addr, 16); memcpy(&(temp_ipv6_header->srcaddr), - ¤t_tcp_socket->local_address.sin6_addr, 16); + ¤t_tcp_socket->local_address.sin6_addr, 16); temp_ipv6_header->length = header_length * 4 + payload_length; current_tcp_packet->checksum = ~tcp_csum(temp_ipv6_header, current_tcp_packet); @@ -495,7 +495,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, } ipv6_sendto(¤t_tcp_socket->foreign_address.sin6_addr, - IPPROTO_TCP, (uint8_t *)(current_tcp_packet), + IPPROTO_TCP, (uint8_t *)(current_tcp_packet), compressed_size); return 1; #else @@ -621,7 +621,7 @@ int destiny_socket_connect(int socket, sockaddr6_t *addr, uint32_t addrlen) /* Got SYN ACK from Server */ /* Refresh foreign TCP socket information */ if ((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) && - (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { + (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { current_tcp_socket->tcp_control.mss = *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); } @@ -694,14 +694,14 @@ void calculate_rto(tcp_cb_t *tcp_control, long current_time) srtt = rtt; rttvar = 0.5 * rtt; rto = rtt + (((4 * rttvar) < TCP_TIMER_RESOLUTION) ? - (TCP_TIMER_RESOLUTION) : (4 * rttvar)); + (TCP_TIMER_RESOLUTION) : (4 * rttvar)); } else { /* every other calculation */ srtt = (1 - TCP_ALPHA) * srtt + TCP_ALPHA * rtt; rttvar = (1 - TCP_BETA) * rttvar + TCP_BETA * abs(srtt - rtt); rto = srtt + (((4 * rttvar) < TCP_TIMER_RESOLUTION) ? - (TCP_TIMER_RESOLUTION) : (4 * rttvar)); + (TCP_TIMER_RESOLUTION) : (4 * rttvar)); } if (rto < SECOND) { @@ -757,7 +757,7 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) while (recv_msg.type != TCP_ACK) { /* Add packet data */ if (current_tcp_socket->tcp_control.send_wnd > - current_tcp_socket->tcp_control.mss) { + current_tcp_socket->tcp_control.mss) { /* Window size > Maximum Segment Size */ if ((len - total_sent_bytes) > current_tcp_socket->tcp_control.mss) { memcpy(&send_buffer[IPV6_HDR_LEN + TCP_HDR_LEN], buf, @@ -792,7 +792,7 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) current_tcp_socket->tcp_control.send_wnd -= sent_bytes; if (send_tcp(current_int_tcp_socket, current_tcp_packet, - temp_ipv6_header, 0, sent_bytes) != 1) { + temp_ipv6_header, 0, sent_bytes) != 1) { /* Error while sending tcp data */ current_tcp_socket->tcp_control.send_nxt -= sent_bytes; current_tcp_socket->tcp_control.send_wnd += sent_bytes; @@ -800,7 +800,7 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) memcpy(¤t_tcp_socket->tcp_control.tcp_context, &saved_tcp_context, sizeof(tcp_hc_context_t)); current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; + COMPRESSED_HEADER; #endif printf("Error while sending, returning to application thread!\n"); return -1; @@ -808,10 +808,10 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) /* Remember current time */ current_tcp_socket->tcp_control.last_packet_time.microseconds = - hwtimer_now(); + hwtimer_now(); net_msg_receive(&recv_msg); - switch(recv_msg.type) { + switch (recv_msg.type) { case TCP_ACK: { if (current_tcp_socket->tcp_control.no_of_retries == 0) { calculate_rto(¤t_tcp_socket->tcp_control, @@ -821,26 +821,26 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) tcp_hdr_t *tcp_header = ((tcp_hdr_t *)(recv_msg.content.ptr)); if ((current_tcp_socket->tcp_control.send_nxt == - tcp_header->ack_nr) && (total_sent_bytes == len)) { + tcp_header->ack_nr) && (total_sent_bytes == len)) { current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_wnd = tcp_header->window; /* Got ACK for every sent byte */ #ifdef TCP_HC current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; + COMPRESSED_HEADER; #endif return sent_bytes; } else if ((current_tcp_socket->tcp_control.send_nxt == - tcp_header->ack_nr) && (total_sent_bytes != len)) { + tcp_header->ack_nr) && (total_sent_bytes != len)) { current_tcp_socket->tcp_control.send_una = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr; current_tcp_socket->tcp_control.send_wnd = tcp_header->window; /* Got ACK for every sent byte */ #ifdef TCP_HC current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; + COMPRESSED_HEADER; #endif break; } @@ -862,7 +862,7 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) memcpy(¤t_tcp_socket->tcp_control.tcp_context, $&saved_tcp_context, sizeof(tcp_hc_context_t)); current_tcp_socket->tcp_control.tcp_context.hc_type = - MOSTLY_COMPRESSED_HEADER; + MOSTLY_COMPRESSED_HEADER; #endif break; } @@ -874,7 +874,7 @@ int32_t destiny_socket_send(int s, const void *buf, uint32_t len, int flags) memcpy(¤t_tcp_socket->tcp_control.tcp_context, &saved_tcp_context, sizeof(tcp_hc_context_t)); current_tcp_socket->tcp_control.tcp_context.hc_type = - COMPRESSED_HEADER; + COMPRESSED_HEADER; #endif return -1; break; @@ -995,7 +995,7 @@ int32_t destiny_socket_sendto(int s, const void *buf, uint32_t len, int flags, sockaddr6_t *to, uint32_t tolen) { if (isUDPSocket(s) && - (get_socket(s)->socket_values.foreign_address.sin6_port == 0)) { + (get_socket(s)->socket_values.foreign_address.sin6_port == 0)) { uint8_t send_buffer[BUFFER_SIZE]; ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer)); @@ -1014,9 +1014,9 @@ int32_t destiny_socket_sendto(int s, const void *buf, uint32_t len, int flags, temp_ipv6_header->length = UDP_HDR_LEN + len; current_udp_packet->checksum = ~udp_csum(temp_ipv6_header, - current_udp_packet); + current_udp_packet); - ipv6_sendto(&to->sin6_addr, IPPROTO_UDP, + ipv6_sendto(&to->sin6_addr, IPPROTO_UDP, (uint8_t *)(current_udp_packet), current_udp_packet->length); return current_udp_packet->length; @@ -1082,7 +1082,7 @@ int destiny_socket_bind(int s, sockaddr6_t *addr, int addrlen) if (exists_socket(s)) { socket_t *current_socket = &get_socket(s)->socket_values; - switch(current_socket->domain) { + switch (current_socket->domain) { case (PF_INET): { /* Not provided */ return -1; @@ -1090,7 +1090,7 @@ int destiny_socket_bind(int s, sockaddr6_t *addr, int addrlen) } case (PF_INET6): { - switch(current_socket->type) { + switch (current_socket->type) { /* TCP */ case (SOCK_STREAM): { if ((current_socket->protocol == 0) || @@ -1172,8 +1172,8 @@ int destiny_socket_listen(int s, int backlog) } socket_internal_t *get_waiting_connection_socket(int socket, - ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header) + ipv6_hdr_t *ipv6_header, + tcp_hdr_t *tcp_header) { int i; socket_internal_t *current_socket, *listening_socket = get_socket(socket); @@ -1184,15 +1184,15 @@ socket_internal_t *get_waiting_connection_socket(int socket, /* Connection establishment ACK, Check for 4 touple and state */ if ((ipv6_header != NULL) && (tcp_header != NULL)) { if (is_four_touple(current_socket, ipv6_header, tcp_header) && - (current_socket->socket_values.tcp_control.state == SYN_RCVD)) { + (current_socket->socket_values.tcp_control.state == SYN_RCVD)) { return current_socket; } } /* Connection establishment SYN ACK, check only for port and state */ else { if ((current_socket->socket_values.tcp_control.state == SYN_RCVD) && - (current_socket->socket_values.local_address.sin6_port == - listening_socket->socket_values.local_address.sin6_port)) { + (current_socket->socket_values.local_address.sin6_port == + listening_socket->socket_values.local_address.sin6_port)) { return current_socket; } } @@ -1320,7 +1320,7 @@ int destiny_socket_accept(int s, sockaddr6_t *addr, uint32_t *addrlen) } socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header) + tcp_hdr_t *tcp_header) { int queued_socket_id; @@ -1339,7 +1339,7 @@ socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, /* Foreign TCP information */ if ((tcp_header->dataOffset_reserved * 4 > TCP_HDR_LEN) && - (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { + (*(((uint8_t *)tcp_header) + TCP_HDR_LEN) == TCP_MSS_OPTION)) { current_queued_socket->socket_values.tcp_control.mss = *((uint16_t *)(((uint8_t *)tcp_header) + TCP_HDR_LEN + 2)); } diff --git a/sys/net/destiny/socket.h b/sys/net/destiny/socket.h index 7bd639f918..59afc08158 100644 --- a/sys/net/destiny/socket.h +++ b/sys/net/destiny/socket.h @@ -72,8 +72,8 @@ typedef struct __attribute__((packed)) { extern socket_internal_t sockets[MAX_SOCKETS]; socket_internal_t *get_waiting_connection_socket(int socket, - ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header); + ipv6_hdr_t *ipv6_header, + tcp_hdr_t *tcp_header); void close_socket(socket_internal_t *current_socket); socket_internal_t *get_socket(int s); socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, @@ -81,7 +81,7 @@ socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, socket_internal_t *get_tcp_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header); socket_internal_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, - tcp_hdr_t *tcp_header); + tcp_hdr_t *tcp_header); void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_t *tcp_socket); void set_tcp_cb(tcp_cb_t *tcp_control, uint32_t rcv_nxt, uint16_t rcv_wnd, diff --git a/sys/net/destiny/tcp.c b/sys/net/destiny/tcp.c index 881408f324..e7642f3d82 100644 --- a/sys/net/destiny/tcp.c +++ b/sys/net/destiny/tcp.c @@ -1,5 +1,5 @@ /** - * Destiny TCP implementation + * Destiny TCP implementation * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file tcp.c - * @brief TCP implementation + * @brief TCP implementation * @author Oliver Gesch * @} */ @@ -87,7 +87,7 @@ uint8_t handle_payload(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, acknowledged_bytes = tcp_socket->socket_values.tcp_control.rcv_wnd; tcp_socket->socket_values.tcp_control.rcv_wnd = 0; tcp_socket->tcp_input_buffer_end = tcp_socket->tcp_input_buffer_end + - tcp_socket->socket_values.tcp_control.rcv_wnd; + tcp_socket->socket_values.tcp_control.rcv_wnd; mutex_unlock(&tcp_socket->tcp_buffer_mutex); } else { @@ -97,7 +97,7 @@ uint8_t handle_payload(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, tcp_socket->socket_values.tcp_control.rcv_wnd - tcp_payload_len; acknowledged_bytes = tcp_payload_len; tcp_socket->tcp_input_buffer_end = tcp_socket->tcp_input_buffer_end + - tcp_payload_len; + tcp_payload_len; mutex_unlock(&tcp_socket->tcp_buffer_mutex); } @@ -155,7 +155,7 @@ void handle_tcp_syn_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, if (tcp_socket->socket_values.tcp_control.state == LISTEN) { socket_internal_t *new_socket = new_tcp_queued_socket(ipv6_header, - tcp_header); + tcp_header); if (new_socket != NULL) { #ifdef TCP_HC @@ -312,7 +312,7 @@ void tcp_packet_handler(void) chksum = tcp_csum(ipv6_header, tcp_header); payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN + - tcp_header->dataOffset_reserved * 4); + tcp_header->dataOffset_reserved * 4); if ((chksum == 0xffff) && (tcp_socket != NULL)) { #ifdef TCP_HC @@ -321,7 +321,7 @@ void tcp_packet_handler(void) /* Remove reserved bits from tcp flags field */ uint8_t tcp_flags = tcp_header->reserved_flags & REMOVE_RESERVED; - switch(tcp_flags) { + switch (tcp_flags) { case TCP_ACK: { /* only ACK Bit set */ handle_tcp_ack_packet(ipv6_header, tcp_header, tcp_socket); diff --git a/sys/net/destiny/tcp.h b/sys/net/destiny/tcp.h index 0980011d03..126bdb87fc 100644 --- a/sys/net/destiny/tcp.h +++ b/sys/net/destiny/tcp.h @@ -7,7 +7,7 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file tcp.c * @brief TCP data structs and prototypes diff --git a/sys/net/destiny/tcp_hc.c b/sys/net/destiny/tcp_hc.c index 1a6bbbd444..08eda22f21 100644 --- a/sys/net/destiny/tcp_hc.c +++ b/sys/net/destiny/tcp_hc.c @@ -1,5 +1,5 @@ /** - * Destiny TCP header compression + * Destiny TCP header compression * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file tcp_hc.c - * @brief TCP HC + * @brief TCP HC * @author Oliver Gesch * @} */ @@ -32,7 +32,7 @@ #ifdef TCP_HC socket_internal_t *get_tcp_socket_by_context(ipv6_hdr_t *current_ipv6_header, - uint16_t current_context) + uint16_t current_context) { socket_internal_t *temp_socket; @@ -40,12 +40,12 @@ socket_internal_t *get_tcp_socket_by_context(ipv6_hdr_t *current_ipv6_header, temp_socket = get_socket(i); if ((temp_socket != NULL) && - ipv6_addr_is_equal(&temp_socket->socket_values.foreign_address.sin6_addr, - ¤t_ipv6_header->srcaddr) && - ipv6_addr_is_equal(&temp_socket->socket_values.local_address.sin6_addr, - ¤t_ipv6_header->destaddr) && - (temp_socket->socket_values.tcp_control.tcp_context.context_id == - current_context)) { + ipv6_addr_is_equal(&temp_socket->socket_values.foreign_address.sin6_addr, + ¤t_ipv6_header->srcaddr) && + ipv6_addr_is_equal(&temp_socket->socket_values.local_address.sin6_addr, + ¤t_ipv6_header->destaddr) && + (temp_socket->socket_values.tcp_control.tcp_context.context_id == + current_context)) { return temp_socket; } } @@ -103,7 +103,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, /* Return correct header length (+3) */ packet_size = ((((tcp_hdr_t *)(current_tcp_packet + 3))->dataOffset_reserved) * 4) + 3 + - payload_length; + payload_length; /* Update the tcp context fields */ update_tcp_hc_context(false, current_socket, (tcp_hdr_t *)(current_tcp_packet + 3)); @@ -150,7 +150,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, /* If the 24 most significant bits haven't changed from previous * packet, don't transmit them */ else if ((full_tcp_header.seq_nr & 0xFFFFFF00) == (tcp_context->seq_snd & - 0xFFFFFF00)) { + 0xFFFFFF00)) { /* Seq = (0|1) */ tcp_hc_header |= 0x0400; @@ -188,7 +188,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, /*| Acknowledgment number handling |*/ /*----------------------------------*/ if ((IS_TCP_ACK(full_tcp_header.reserved_flags) && - (tcp_cb->tcp_context.ack_snd == full_tcp_header.ack_nr))) { + (tcp_cb->tcp_context.ack_snd == full_tcp_header.ack_nr))) { tcp_context->ack_snd = tcp_context->seq_rcv; } @@ -198,7 +198,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, /* If the 24 most significant bits haven't changed from previous packet, * don't transmit them */ else if ((full_tcp_header.ack_nr & 0xFFFFFF00) == (tcp_context->ack_snd & - 0xFFFFFF00)) { + 0xFFFFFF00)) { /* Ack = (0|1) */ tcp_hc_header |= 0x0100; @@ -211,7 +211,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, /* If the 16 most significant bits haven't changed from previous packet, * don't transmit them */ else if ((full_tcp_header.ack_nr & 0xFFFF0000) == (tcp_context->ack_snd & - 0xFFFF0000)) { + 0xFFFF0000)) { /* Ack = (1|0) */ tcp_hc_header |= 0x0200; @@ -254,7 +254,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, /* If the 8 less significant bits haven't changed from previous packet, * don't transmit them */ else if ((full_tcp_header.window & 0x00FF) == (tcp_context->wnd_snd & - 0x00FF)) { + 0x00FF)) { /* Wnd = (1|0) */ tcp_hc_header |= 0x0080; @@ -415,10 +415,10 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header) /* Full header TCP segment */ if (*(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN) == 0x01) { switch_tcp_packet_byte_order(((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) + - IPV6_HDR_LEN + 3))); + IPV6_HDR_LEN + 3))); current_socket = get_tcp_socket(temp_ipv6_header, ((tcp_hdr_t *)(((uint8_t *)temp_ipv6_header) + - IPV6_HDR_LEN + 3))); + IPV6_HDR_LEN + 3))); if (current_socket != NULL) { if (current_socket->socket_values.tcp_control.state == LISTEN) { @@ -459,11 +459,11 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header) uint8_t header_type = UNDEFINED; if (BITSET(tcp_hc_header, 15) && !BITSET(tcp_hc_header, 14) && - !BITSET(tcp_hc_header, 13)) { + !BITSET(tcp_hc_header, 13)) { header_type = MOSTLY_COMPRESSED_HEADER; } else if (BITSET(tcp_hc_header, 15) && BITSET(tcp_hc_header, 14) && - !BITSET(tcp_hc_header, 13)) { + !BITSET(tcp_hc_header, 13)) { header_type = COMPRESSED_HEADER; } @@ -624,7 +624,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header) /* Copy TCP uncompressed header in front of payload */ memcpy(((uint8_t *)temp_ipv6_header) + IPV6_HDR_LEN, &full_tcp_header, - TCP_HDR_LEN); + TCP_HDR_LEN); /* Set IPV6 header length */ temp_ipv6_header->length = temp_ipv6_header->length - packet_size + diff --git a/sys/net/destiny/tcp_timer.c b/sys/net/destiny/tcp_timer.c index 2b32278356..6be9f2b0f5 100644 --- a/sys/net/destiny/tcp_timer.c +++ b/sys/net/destiny/tcp_timer.c @@ -1,5 +1,5 @@ /** - * Destiny TCP timer implementation + * Destiny TCP timer implementation * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file tcp_timer.c - * @brief TCP timer + * @brief TCP timer * @author Oliver Gesch * @} */ @@ -41,21 +41,21 @@ void handle_synchro_timeout(socket_internal_t *current_socket) vtimer_now(&now); if ((current_socket->socket_values.tcp_control.no_of_retries == 0) && - (timex_sub(now, - current_socket->socket_values.tcp_control.last_packet_time).microseconds > - TCP_SYN_INITIAL_TIMEOUT)) { + (timex_sub(now, + current_socket->socket_values.tcp_control.last_packet_time).microseconds > + TCP_SYN_INITIAL_TIMEOUT)) { current_socket->socket_values.tcp_control.no_of_retries++; net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY); } else if ((current_socket->socket_values.tcp_control.no_of_retries > 0) && - (timex_sub(now, - current_socket->socket_values.tcp_control.last_packet_time).microseconds > - (current_socket->socket_values.tcp_control.no_of_retries * - TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT))) { + (timex_sub(now, + current_socket->socket_values.tcp_control.last_packet_time).microseconds > + (current_socket->socket_values.tcp_control.no_of_retries * + TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT))) { current_socket->socket_values.tcp_control.no_of_retries++; if (current_socket->socket_values.tcp_control.no_of_retries > - TCP_MAX_SYN_RETRIES) { + TCP_MAX_SYN_RETRIES) { net_msg_send(&send, current_socket->recv_pid, 0, TCP_TIMEOUT); } else { @@ -77,10 +77,10 @@ void handle_established(socket_internal_t *current_socket) uint8_t i; if ((current_socket->socket_values.tcp_control.send_nxt > - current_socket->socket_values.tcp_control.send_una) && - (thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED)) { + current_socket->socket_values.tcp_control.send_una) && + (thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED)) { for (i = 0; i < current_socket->socket_values.tcp_control.no_of_retries; - i++) { + i++) { current_timeout *= 2; } @@ -91,7 +91,7 @@ void handle_established(socket_internal_t *current_socket) net_msg_send(&send, current_socket->send_pid, 0, TCP_TIMEOUT); } else if (timex_sub(now, current_socket->socket_values.tcp_control.last_packet_time).microseconds > - current_timeout) { + current_timeout) { current_socket->socket_values.tcp_control.no_of_retries++; net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY); } @@ -107,7 +107,7 @@ void check_sockets(void) current_socket = get_socket(i); if (is_tcp_socket(i)) { - switch(current_socket->socket_values.tcp_control.state) { + switch (current_socket->socket_values.tcp_control.state) { case ESTABLISHED: { handle_established(current_socket); break; diff --git a/sys/net/destiny/udp.c b/sys/net/destiny/udp.c index 017aec49e9..6ad15bc442 100644 --- a/sys/net/destiny/udp.c +++ b/sys/net/destiny/udp.c @@ -1,5 +1,5 @@ /** - * Destiny UDP implementation + * Destiny UDP implementation * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file udp.c - * @brief UDP implementation + * @brief UDP implementation * @author Oliver Gesch * @} */ diff --git a/sys/net/destiny/udp.h b/sys/net/destiny/udp.h index df70a037fe..d313f0ce28 100644 --- a/sys/net/destiny/udp.h +++ b/sys/net/destiny/udp.h @@ -7,7 +7,7 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup destiny + * @ingroup destiny * @{ * @file udp.c * @brief UDP data structs and prototypes From c02a097232c43cdae186d62c29dda7eb1bd98490 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Mon, 30 Sep 2013 14:06:46 +0200 Subject: [PATCH 10/11] Add module dependancies for destiny --- Makefile.dep | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile.dep b/Makefile.dep index 53261b4a05..286062dd2e 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -42,6 +42,15 @@ ifneq (,$(findstring at86rf231,$(USEMODULE))) endif endif +ifneq (,$(findstring destiny,$(USEMODULE))) + ifeq (,$(findstring sixlowpan,$(USEMODULE))) + USEMODULE += sixlowpan + endif + ifeq (,$(findstring net_help,$(USEMODULE))) + USEMODULE += net_help + endif +endif + ifneq (,$(findstring sixlowpan,$(USEMODULE))) ifeq (,$(findstring ieee802154,$(USEMODULE))) USEMODULE += ieee802154 From f537e19b26bb8a7df38fc544b73d3bcec9913ee3 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Fri, 25 Oct 2013 14:00:34 +0200 Subject: [PATCH 11/11] Move L4 packet headers to destiny/types.h --- sys/net/destiny/include/destiny.h | 1 + sys/net/destiny/include/destiny/types.h | 75 +++++++++++++++++++++++++ sys/net/destiny/tcp.h | 20 ++----- sys/net/destiny/udp.h | 23 ++------ 4 files changed, 88 insertions(+), 31 deletions(-) create mode 100644 sys/net/destiny/include/destiny/types.h diff --git a/sys/net/destiny/include/destiny.h b/sys/net/destiny/include/destiny.h index 71b7283b3b..e976240707 100644 --- a/sys/net/destiny/include/destiny.h +++ b/sys/net/destiny/include/destiny.h @@ -35,6 +35,7 @@ #include "destiny/in.h" #include "destiny/socket.h" +#include "destiny/types.h" /** * Initializes transport layer. diff --git a/sys/net/destiny/include/destiny/types.h b/sys/net/destiny/include/destiny/types.h new file mode 100644 index 0000000000..70679a3b52 --- /dev/null +++ b/sys/net/destiny/include/destiny/types.h @@ -0,0 +1,75 @@ +/** + * Destiny types header + * + * Copyright (C) 2013 INRIA. + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * @ingroup destiny + * @{ + * @file + * @brief Destiny types + * @author Oliver Gesch + * @author Martin Lenders + */ +#ifndef DESTINY_TYPES_H_ +#define DESTINY_TYPES_H_ +#include + +/** + * UDP packet header length + */ +#define UDP_HDR_LEN 8 + +/** + * TCP packet header length + */ +#define TCP_HDR_LEN 20 + +/** + * UDP packet header + * + * @see RFC 768 + */ +typedef struct __attribute__((packed)) { + uint16_t src_port; ///< source port + uint16_t dst_port; ///< destination port + uint16_t length; ///< payload length + /** + * internet checksum + * + * @see RFC 1071 + */ + uint16_t checksum; +} udp_hdr_t; + +/** + * TCP packet header + * + * @see RFC 793 + */ +typedef struct __attribute__((packed)) { + uint16_t src_port; ///< source port + uint16_t dst_port; ///< destination port + uint32_t seq_nr; ///< sequence number + uint32_t ack_nr; ///< acknowledgement number + uint8_t dataOffset_reserved; ///< 4 MSBs data offsets, + ///< 4 LSBs reserved (must be zero) + uint8_t reserved_flags; ///< MSB reserved, rest flags + uint16_t window; ///< receiver window + /** + * internet checksum + * + * @see RFC 1071 + */ + uint16_t checksum; + uint16_t urg_pointer; ///< urgent pointer +} tcp_hdr_t; + +/** + * @} + */ + +#endif DESTINY_TYPES_H_ diff --git a/sys/net/destiny/tcp.h b/sys/net/destiny/tcp.h index 126bdb87fc..6d9563c5cf 100644 --- a/sys/net/destiny/tcp.h +++ b/sys/net/destiny/tcp.h @@ -9,18 +9,16 @@ * * @ingroup destiny * @{ - * @file tcp.c + * @file * @brief TCP data structs and prototypes * @author Oliver Gesch - * @} */ #ifndef TCP_H_ #define TCP_H_ #include "ipv6.h" - -#define TCP_HDR_LEN 20 +#include "destiny/types.h" #define TCP_EOO_OPTION 0x00 // End of option list #define TCP_NOP_OPTION 0x01 // No operation @@ -28,16 +26,6 @@ #define TCP_WSF_OPTION 0x03 // Window scale factor #define TCP_TS_OPTION 0x08 // Timestamp -enum tcp_flags { - TCP_ACK = 0x08, - TCP_URG_PSH = 0x14, - TCP_RST = 0x20, - TCP_SYN = 0x40, - TCP_SYN_ACK = 0x48, - TCP_FIN = 0x80, - TCP_FIN_ACK = 0x88 -}; - enum tcp_states { CLOSED = 0, LISTEN = 1, @@ -111,4 +99,8 @@ uint16_t tcp_csum(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header); void printTCPHeader(tcp_hdr_t *tcp_header); void printArrayRange_tcp(uint8_t *udp_header, uint16_t len); +/** + * @} + */ + #endif /* TCP_H_ */ diff --git a/sys/net/destiny/udp.h b/sys/net/destiny/udp.h index d313f0ce28..5eab7c460e 100644 --- a/sys/net/destiny/udp.h +++ b/sys/net/destiny/udp.h @@ -9,36 +9,25 @@ * * @ingroup destiny * @{ - * @file udp.c + * @file * @brief UDP data structs and prototypes * @author Oliver Gesch - * @} */ -/* - * udp.h - * - * Created on: 05.09.2011 - * Author: Oliver - */ #ifndef UDP_H_ #define UDP_H_ #include "ipv6.h" - -#define UDP_HDR_LEN 8 +#include "destiny/types.h" #define UDP_STACK_SIZE KERNEL_CONF_STACKSIZE_DEFAULT -typedef struct __attribute__((packed)) udp_h_t { - uint16_t src_port; - uint16_t dst_port; - uint16_t length; - uint16_t checksum; -} udp_hdr_t; - uint16_t udp_csum(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header); void udp_packet_handler(void); +/** + * @} + */ + #endif /* UDP_H_ */