1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/net/transport_layer/destiny/destiny.c

82 lines
2.1 KiB
C
Raw Normal View History

/**
* Destiny transport layer implementation
*
* Copyright (C) 2013 INRIA.
*
2013-11-22 20:47:05 +01:00
* This file is 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 destiny.c
* @brief transpor layer functions
* @author Oliver Gesch <oliver.gesch@googlemail.com>
* @}
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
2013-09-30 13:19:19 +02:00
2013-12-16 17:54:58 +01:00
#include "thread.h"
#include "destiny.h"
2013-09-30 13:19:19 +02:00
#include "vtimer.h"
2013-09-23 12:40:16 +02:00
#include "socket.h"
2013-09-30 13:19:19 +02:00
#include "tcp.h"
#include "tcp_timer.h"
#include "udp.h"
2013-09-23 12:40:16 +02:00
char tcp_stack_buffer[TCP_STACK_SIZE];
char udp_stack_buffer[UDP_STACK_SIZE];
char tcp_timer_stack[TCP_TIMER_STACKSIZE];
2013-09-20 14:29:00 +02:00
int destiny_init_transport_layer(void)
{
printf("Initializing transport layer packages. Size of socket_type: %u\n",
(unsigned int) sizeof(socket_internal_t));
/* SOCKETS */
memset(sockets, 0, MAX_SOCKETS * sizeof(socket_internal_t));
/* UDP */
int udp_thread_pid = thread_create(udp_stack_buffer, UDP_STACK_SIZE,
PRIORITY_MAIN, CREATE_STACKTEST,
2013-09-20 14:29:00 +02:00
udp_packet_handler, "udp_packet_handler");
if (udp_thread_pid < 0) {
return -1;
}
2013-08-13 06:41:05 +02:00
ipv6_register_next_header_handler(IPV6_PROTO_NUM_UDP, udp_thread_pid);
/* TCP */
timex_t now;
vtimer_now(&now);
2013-12-25 17:34:30 +01:00
srand(timex_uint64(now));
#ifdef TCP_HC
printf("TCP_HC enabled!\n");
global_context_counter = rand();
#endif
global_sequence_counter = rand();
int tcp_thread_pid = thread_create(tcp_stack_buffer, TCP_STACK_SIZE,
PRIORITY_MAIN, CREATE_STACKTEST,
tcp_packet_handler, "tcp_packet_handler");
2013-09-20 14:29:00 +02:00
2013-11-21 00:04:41 +01:00
if (tcp_thread_pid < 0) {
2013-09-20 14:29:00 +02:00
return -1;
}
2013-08-13 06:41:05 +02:00
ipv6_register_next_header_handler(IPV6_PROTO_NUM_TCP, tcp_thread_pid);
2013-09-20 14:29:00 +02:00
if (thread_create(tcp_timer_stack, TCP_TIMER_STACKSIZE, PRIORITY_MAIN + 1,
CREATE_STACKTEST, tcp_general_timer, "tcp_general_timer") < 0) {
return -1;
}
2013-09-20 14:29:00 +02:00
return 0;
}