Пример #1
0
int destiny_init_transport_layer(void)
{
    printf("Initializing transport layer packages. Size of socket_type: %u\n",
           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,
                                       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 */
    timex_t now;
    vtimer_now(&now);
    srand(now.microseconds);
#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");

    if (udp_thread_pid < 0) {
        return -1;
    }

    ipv6_register_next_header_handler(IPV6_PROTO_NUM_TCP, tcp_thread_pid);

    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;
}
Пример #2
0
int udp_init_transport_layer(void)
{
    printf("Initializing transport layer protocol: udp\n");
    /* SOCKETS */
    memset(socket_base_sockets, 0, MAX_SOCKETS * sizeof(socket_internal_t));

    int udp_thread_pid = thread_create(udp_stack_buffer, UDP_STACK_SIZE, THREAD_PRIORITY_MAIN,
                                        CREATE_STACKTEST, udp_packet_handler, NULL, "udp_packet_handler");

    if (udp_thread_pid < 0) {
        return -1;
    }

    ipv6_register_next_header_handler(IPV6_PROTO_NUM_UDP, udp_thread_pid);

    return 0;
}