mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #217 from authmillenon/destiny_refactor
Refactor destiny (transport layer) module
This commit is contained in:
commit
7ff3d4c52c
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
@ -19,17 +19,19 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <vtimer.h>
|
||||
#include "udp.h"
|
||||
#include "tcp.h"
|
||||
#include "socket.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];
|
||||
|
||||
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 +41,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 +62,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;
|
||||
}
|
||||
|
@ -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_ */
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* in.h
|
||||
*
|
||||
* Created on: 16.09.2011
|
||||
* Author: Oliver
|
||||
*/
|
||||
|
||||
#ifndef IN_H_
|
||||
#define 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 */
|
||||
/* 255: Reserved */
|
||||
/* BSD Private, local use, namespace incursion */
|
||||
#define IPPROTO_DIVERT (254) /* divert pseudo-protocol */
|
||||
#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 IN_LOOPBACKNET (127) /* official! */
|
||||
|
||||
#endif /* IN_H_ */
|
47
sys/net/destiny/include/destiny.h
Normal file
47
sys/net/destiny/include/destiny.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* destiny.h - Wraps all API types, constants and functions of the transport
|
||||
* layer implementation.
|
||||
*
|
||||
* 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 <a href="http://tools.ietf.org/html/rfc6282#section-4.3">
|
||||
* RFC 6282 - Compression Format for IPv6 Datagrams over
|
||||
* IEEE 802.15.4-Based Networks - UDP Header Compression
|
||||
* </a>
|
||||
* @see <a href="http://tools.ietf.org/html/draft-aayadi-6lowpan-tcphc-01">
|
||||
* RFC draft-aayadi-6lowpan-tcphc-01 - TCP header compression for
|
||||
* 6LoWPAN
|
||||
* </a>
|
||||
* @{
|
||||
* @file
|
||||
* @brief destiny functions
|
||||
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef DESTINY_H
|
||||
#define DESTINY_H
|
||||
|
||||
#include "destiny/in.h"
|
||||
#include "destiny/socket.h"
|
||||
#include "destiny/types.h"
|
||||
|
||||
/**
|
||||
* Initializes transport layer.
|
||||
*
|
||||
* @return 0 on success, other else.
|
||||
*/
|
||||
int destiny_init_transport_layer(void);
|
||||
|
||||
#endif /* DESTINY_H */
|
144
sys/net/destiny/include/destiny/in.h
Normal file
144
sys/net/destiny/include/destiny/in.h
Normal file
@ -0,0 +1,144 @@
|
||||
/**
|
||||
* 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 <a href="http://tools.ietf.org/html/rfc790">
|
||||
* RFC790 - Assigned Numbers
|
||||
* </a>
|
||||
* @see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html">
|
||||
* IEEE Std 1003.1, 2013 Edition - netinet/in.h
|
||||
* </a>
|
||||
* @see <a href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml">
|
||||
* IANA - Protocol Numbers
|
||||
* </a>
|
||||
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef DESTINY_IN_H
|
||||
#define DESTINY_IN_H
|
||||
|
||||
/*
|
||||
* 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
|
||||
/* 255: Reserved */
|
||||
/* */
|
||||
#define IPPROTO_DIVERT (254) ///< divert pseudo-protocol (BSD Private, local use, namespace incursion)
|
||||
#define IPPROTO_RAW (255) ///< raw IP packet
|
||||
#define IPPROTO_MAX (256)
|
||||
|
||||
#define IPPROTO_DONE (257) ///< last return value of *_input(), meaning "all job for this pkt is done".
|
||||
|
||||
#define IN_LOOPBACKNET (127) ///< official!
|
||||
|
||||
#endif /* DESTINY_IN_H */
|
329
sys/net/destiny/include/destiny/socket.h
Normal file
329
sys/net/destiny/include/destiny/socket.h
Normal file
@ -0,0 +1,329 @@
|
||||
/**
|
||||
* 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
|
||||
* @see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html">
|
||||
* IEEE Std 1003.1, 2013 Edition - sys/socket.h
|
||||
* </a>
|
||||
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DESTINY_SOCKET_H
|
||||
#define DESTINY_SOCKET_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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)
|
||||
/**
|
||||
* IPv6 address family.
|
||||
*
|
||||
* @see AF_INET
|
||||
*/
|
||||
#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 ///< 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 ///< 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; ///< 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
|
||||
* <a href="http://man.he.net/man2/socket">socket(2)</a>.
|
||||
*
|
||||
* @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
|
||||
* <a href="http://man.he.net/man2/connect">connect(2)</a>.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Receives data through socket *s* and saves it in buffer *buf*. Roughly
|
||||
* identical to POSIX's <a href="http://man.he.net/man2/recv">recv(2)</a>.
|
||||
*
|
||||
* @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
|
||||
* <a href="http://man.he.net/man2/recvfrom">recvfrom(2)</a>.
|
||||
*
|
||||
* @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
|
||||
* <a href="http://man.he.net/man2/send">send(2)</a>.
|
||||
*
|
||||
* @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 <a href="http://man.he.net/man2/send">send(2)</a>.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Assigns an IPv6 address *addr* to the socket *s*. Roughly identical to
|
||||
* POSIX's <a href="http://man.he.net/man2/bind">bind(2)</a>.
|
||||
*
|
||||
* @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 <a href="http://man.he.net/man2/listen">listen(2)</a>.
|
||||
*
|
||||
* @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
|
||||
* <a href="http://man.he.net/man2/accept">accept(2)</a>.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* DESTINY_SOCKET_H */
|
75
sys/net/destiny/include/destiny/types.h
Normal file
75
sys/net/destiny/include/destiny/types.h
Normal file
@ -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 <oliver.gesch@googlemail.com>
|
||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef DESTINY_TYPES_H_
|
||||
#define DESTINY_TYPES_H_
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* UDP packet header length
|
||||
*/
|
||||
#define UDP_HDR_LEN 8
|
||||
|
||||
/**
|
||||
* TCP packet header length
|
||||
*/
|
||||
#define TCP_HDR_LEN 20
|
||||
|
||||
/**
|
||||
* UDP packet header
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc768">RFC 768</a>
|
||||
*/
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t src_port; ///< source port
|
||||
uint16_t dst_port; ///< destination port
|
||||
uint16_t length; ///< payload length
|
||||
/**
|
||||
* internet checksum
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc1071">RFC 1071</a>
|
||||
*/
|
||||
uint16_t checksum;
|
||||
} udp_hdr_t;
|
||||
|
||||
/**
|
||||
* TCP packet header
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc793">RFC 793</a>
|
||||
*/
|
||||
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 <a href="http://tools.ietf.org/html/rfc1071">RFC 1071</a>
|
||||
*/
|
||||
uint16_t checksum;
|
||||
uint16_t urg_pointer; ///< urgent pointer
|
||||
} tcp_hdr_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif DESTINY_TYPES_H_
|
@ -7,9 +7,13 @@
|
||||
|
||||
#include <thread.h>
|
||||
#include <stdio.h>
|
||||
#include "msg_help.h"
|
||||
|
||||
#include "thread.h"
|
||||
|
||||
#include "tcp_timer.h"
|
||||
|
||||
#include "msg_help.h"
|
||||
|
||||
void block_continue_thread(void)
|
||||
{
|
||||
// msg_t recv_m;
|
@ -8,6 +8,8 @@
|
||||
#ifndef MSG_HELP_H_
|
||||
#define MSG_HELP_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Function IDs
|
||||
#define FID_SIXLOWIP_TCP 0
|
||||
#define FID_SIXLOWIP_UDP 1
|
@ -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
|
||||
@ -15,25 +15,43 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <thread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include "ipv6.h"
|
||||
#include "udp.h"
|
||||
#include "tcp.h"
|
||||
#include "socket.h"
|
||||
#include "vtimer.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hwtimer.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 "../net_help/msg_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
|
||||
|
||||
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);
|
||||
@ -45,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;
|
||||
@ -91,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);
|
||||
@ -103,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",
|
||||
@ -130,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,
|
||||
@ -152,7 +170,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 +180,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 +210,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 +221,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 +245,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 +264,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 +304,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 ==
|
||||
udp_header->dst_port)) {
|
||||
return getSocket(i);
|
||||
(get_socket(i)->socket_values.local_address.sin6_port ==
|
||||
udp_header->dst_port)) {
|
||||
return get_socket(i);
|
||||
}
|
||||
|
||||
i++;
|
||||
@ -317,24 +335,24 @@ 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,
|
||||
tcp_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) &&
|
||||
((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)) {
|
||||
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)) {
|
||||
listening_socket = current_socket;
|
||||
}
|
||||
|
||||
@ -353,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;
|
||||
}
|
||||
}
|
||||
@ -362,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;
|
||||
@ -431,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;
|
||||
@ -442,9 +460,9 @@ 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));
|
||||
¤t_mss_option, sizeof(tcp_mss_option_t));
|
||||
}
|
||||
|
||||
set_tcp_packet(current_tcp_packet, current_tcp_socket->local_address.sin6_port,
|
||||
@ -456,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);
|
||||
@ -477,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
|
||||
@ -499,7 +517,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 +529,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 +571,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);
|
||||
|
||||
@ -603,12 +621,12 @@ int 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));
|
||||
}
|
||||
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 +678,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;
|
||||
}
|
||||
|
||||
@ -676,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) {
|
||||
@ -695,7 +713,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 +726,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 */
|
||||
@ -739,17 +757,17 @@ int32_t send(int s, void *msg, 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], 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 +775,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;
|
||||
}
|
||||
@ -774,7 +792,7 @@ int32_t send(int s, void *msg, 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;
|
||||
@ -782,7 +800,7 @@ int32_t send(int s, void *msg, 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;
|
||||
@ -790,10 +808,10 @@ int32_t send(int s, void *msg, 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,
|
||||
@ -803,26 +821,26 @@ int32_t send(int s, void *msg, 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;
|
||||
}
|
||||
@ -844,7 +862,7 @@ int32_t send(int s, void *msg, 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;
|
||||
}
|
||||
@ -856,7 +874,7 @@ int32_t send(int s, void *msg, 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;
|
||||
@ -895,7 +913,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 +921,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 +955,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 +982,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 +991,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,14 +1009,14 @@ 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;
|
||||
|
||||
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;
|
||||
@ -1008,12 +1026,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 +1039,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 +1067,7 @@ int close(int s)
|
||||
}
|
||||
else if (isUDPSocket(s)) {
|
||||
close_socket(current_socket);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -1059,12 +1077,12 @@ 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) {
|
||||
switch (current_socket->domain) {
|
||||
case (PF_INET): {
|
||||
/* Not provided */
|
||||
return -1;
|
||||
@ -1072,12 +1090,12 @@ int bind(int s, sockaddr6_t *name, int namelen)
|
||||
}
|
||||
|
||||
case (PF_INET6): {
|
||||
switch(current_socket->type) {
|
||||
switch (current_socket->type) {
|
||||
/* TCP */
|
||||
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 +1111,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 +1159,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,28 +1171,28 @@ 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)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1264,18 +1282,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 +1308,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());
|
||||
@ -1302,12 +1320,12 @@ int 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;
|
||||
|
||||
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,
|
||||
@ -1321,12 +1339,12 @@ 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));
|
||||
}
|
||||
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 +1355,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);
|
||||
|
@ -1,151 +1,20 @@
|
||||
/**
|
||||
* 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 <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
#ifndef _DESTINY_SOCKET
|
||||
#define _DESTINY_SOCKET
|
||||
|
||||
|
||||
#ifndef SOCKET_H_
|
||||
#define SOCKET_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ipv6.h"
|
||||
#include "tcp.h"
|
||||
#include "udp.h"
|
||||
#include "in.h"
|
||||
#include "ipv6.h"
|
||||
#include "cpu.h"
|
||||
|
||||
/*
|
||||
* POSIX compatibility
|
||||
*/
|
||||
typedef uint8_t sa_family_t;
|
||||
typedef uint32_t socklen_t;
|
||||
#include "destiny/socket.h"
|
||||
|
||||
/*
|
||||
* 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 +25,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 +48,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 +59,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);
|
||||
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 */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Destiny TCP implementation
|
||||
* Destiny TCP implementation
|
||||
*
|
||||
* Copyright (C) 2013 INRIA.
|
||||
*
|
||||
@ -7,30 +7,33 @@
|
||||
* 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 <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <thread.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vtimer.h"
|
||||
#include "tcp_timer.h"
|
||||
#include "tcp_hc.h"
|
||||
#include "tcp.h"
|
||||
#include "in.h"
|
||||
#include "socket.h"
|
||||
#include "../net_help/net_help.h"
|
||||
#include "../net_help/msg_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)
|
||||
{
|
||||
@ -84,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 {
|
||||
@ -94,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);
|
||||
}
|
||||
|
||||
@ -122,8 +125,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;
|
||||
@ -152,16 +155,16 @@ 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
|
||||
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 {
|
||||
@ -309,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
|
||||
@ -318,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);
|
||||
|
@ -7,18 +7,18 @@
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*
|
||||
* @ingroup destiny
|
||||
* @ingroup destiny
|
||||
* @{
|
||||
* @file tcp.c
|
||||
* @file
|
||||
* @brief TCP data structs and prototypes
|
||||
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef TCP_H_
|
||||
#define TCP_H_
|
||||
|
||||
#define TCP_HDR_LEN 20
|
||||
#include "ipv6.h"
|
||||
#include "destiny/types.h"
|
||||
|
||||
#define TCP_EOO_OPTION 0x00 // End of option list
|
||||
#define TCP_NOP_OPTION 0x01 // No operation
|
||||
@ -26,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,
|
||||
@ -78,8 +68,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;
|
||||
@ -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_ */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Destiny TCP header compression
|
||||
* Destiny TCP header compression
|
||||
*
|
||||
* Copyright (C) 2013 INRIA.
|
||||
*
|
||||
@ -7,42 +7,45 @@
|
||||
* 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 <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "tcp_hc.h"
|
||||
#include "ipv6.h"
|
||||
|
||||
#include "../net_help/net_help.h"
|
||||
|
||||
#include "socket.h"
|
||||
#include "tcp.h"
|
||||
#include "ipv6.h"
|
||||
#include "../net_help/net_help.h"
|
||||
|
||||
#include "tcp_hc.h"
|
||||
|
||||
#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;
|
||||
|
||||
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,
|
||||
¤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;
|
||||
}
|
||||
}
|
||||
@ -100,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));
|
||||
@ -147,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;
|
||||
|
||||
@ -185,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;
|
||||
}
|
||||
|
||||
@ -195,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;
|
||||
|
||||
@ -208,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;
|
||||
|
||||
@ -251,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;
|
||||
|
||||
@ -412,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) {
|
||||
@ -456,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;
|
||||
}
|
||||
|
||||
@ -621,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 +
|
||||
|
@ -8,9 +8,11 @@
|
||||
#ifndef TCP_HC_H_
|
||||
#define TCP_HC_H_
|
||||
|
||||
#include "tcp.h"
|
||||
#include "sixlowpan.h"
|
||||
#include "socket.h"
|
||||
|
||||
#include "destiny/socket.h"
|
||||
|
||||
#include "tcp.h"
|
||||
|
||||
#ifdef TCP_HC
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Destiny TCP timer implementation
|
||||
* Destiny TCP timer implementation
|
||||
*
|
||||
* Copyright (C) 2013 INRIA.
|
||||
*
|
||||
@ -7,27 +7,30 @@
|
||||
* 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 <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#include <thread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "tcp_timer.h"
|
||||
#include "vtimer.h"
|
||||
#include "thread.h"
|
||||
#include "destiny.h"
|
||||
#include "socket.h"
|
||||
#include "../net_help/msg_help.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
@ -38,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 {
|
||||
@ -74,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;
|
||||
}
|
||||
|
||||
@ -88,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);
|
||||
}
|
||||
@ -101,10 +104,10 @@ 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)) {
|
||||
switch(current_socket->socket_values.tcp_control.state) {
|
||||
if (is_tcp_socket(i)) {
|
||||
switch (current_socket->socket_values.tcp_control.state) {
|
||||
case ESTABLISHED: {
|
||||
handle_established(current_socket);
|
||||
break;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Destiny UDP implementation
|
||||
* Destiny UDP implementation
|
||||
*
|
||||
* Copyright (C) 2013 INRIA.
|
||||
*
|
||||
@ -7,27 +7,30 @@
|
||||
* 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 <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <thread.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "udp.h"
|
||||
#include "msg.h"
|
||||
#include "ipv6.h"
|
||||
#include "msg.h"
|
||||
#include "sixlowpan.h"
|
||||
#include "socket.h"
|
||||
#include "in.h"
|
||||
#include "thread.h"
|
||||
|
||||
#include "destiny/in.h"
|
||||
|
||||
#include "../net_help/net_help.h"
|
||||
#include "../net_help/msg_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)
|
||||
{
|
||||
|
@ -7,38 +7,27 @@
|
||||
* Public License. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*
|
||||
* @ingroup destiny
|
||||
* @ingroup destiny
|
||||
* @{
|
||||
* @file udp.c
|
||||
* @file
|
||||
* @brief UDP data structs and prototypes
|
||||
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
/*
|
||||
* udp.h
|
||||
*
|
||||
* Created on: 05.09.2011
|
||||
* Author: Oliver
|
||||
*/
|
||||
|
||||
#ifndef UDP_H_
|
||||
#define UDP_H_
|
||||
|
||||
#define UDP_HDR_LEN 8
|
||||
#include "ipv6.h"
|
||||
#include "destiny/types.h"
|
||||
|
||||
#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;
|
||||
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_ */
|
||||
|
@ -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
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "socket.h"
|
||||
#include "destiny/socket.h"
|
||||
|
||||
#include "inet_ntop.h"
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "socket.h"
|
||||
#include "destiny/socket.h"
|
||||
|
||||
#include "inet_pton.h"
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user