2014-07-31 17:53:46 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin.
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SOCKET_BASE_SOCKET
|
|
|
|
#define _SOCKET_BASE_SOCKET
|
2013-09-30 13:19:19 +02:00
|
|
|
|
2013-09-23 12:40:16 +02:00
|
|
|
#include "cpu.h"
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
#include "socket_base/socket.h"
|
2013-09-30 13:19:19 +02:00
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
#ifdef MODULE_UDP
|
2013-08-15 10:17:15 +02:00
|
|
|
#include "udp.h"
|
2014-07-31 17:53:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_TCP
|
|
|
|
#include "tcp.h"
|
|
|
|
#endif
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 20:51:50 +02:00
|
|
|
#define MAX_SOCKETS 5
|
|
|
|
// #define MAX_QUEUED_SOCKETS 2
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 20:51:50 +02:00
|
|
|
#define INC_PACKET 0
|
|
|
|
#define OUT_PACKET 1
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
#ifdef MODULE_TCP
|
2013-09-23 12:40:16 +02:00
|
|
|
typedef struct __attribute__((packed)) {
|
2014-07-31 20:51:50 +02:00
|
|
|
uint16_t context_id;
|
|
|
|
uint32_t seq_rcv; // Last received packet values
|
|
|
|
uint32_t ack_rcv;
|
|
|
|
uint16_t wnd_rcv;
|
|
|
|
uint32_t seq_snd; // Last sent packet values
|
|
|
|
uint32_t ack_snd;
|
|
|
|
uint16_t wnd_snd;
|
|
|
|
uint8_t hc_type;
|
2013-08-15 10:17:15 +02:00
|
|
|
} tcp_hc_context_t;
|
|
|
|
|
2013-09-23 12:40:16 +02:00
|
|
|
typedef struct __attribute__((packed)) {
|
2014-07-31 20:51:50 +02:00
|
|
|
uint32_t send_una;
|
|
|
|
uint32_t send_nxt;
|
|
|
|
uint16_t send_wnd;
|
|
|
|
uint32_t send_iss;
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 20:51:50 +02:00
|
|
|
uint32_t rcv_nxt;
|
|
|
|
uint16_t rcv_wnd;
|
|
|
|
uint32_t rcv_irs;
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 20:51:50 +02:00
|
|
|
timex_t last_packet_time;
|
|
|
|
uint8_t no_of_retries;
|
|
|
|
uint16_t mss;
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 20:51:50 +02:00
|
|
|
uint8_t state;
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 20:51:50 +02:00
|
|
|
double srtt;
|
|
|
|
double rttvar;
|
|
|
|
double rto;
|
2013-08-15 10:17:15 +02:00
|
|
|
|
|
|
|
#ifdef TCP_HC
|
2014-07-31 20:51:50 +02:00
|
|
|
tcp_hc_context_t tcp_context;
|
2013-08-15 10:17:15 +02:00
|
|
|
#endif
|
|
|
|
} tcp_cb_t;
|
2014-07-31 17:53:46 +02:00
|
|
|
#endif
|
2013-08-15 10:17:15 +02:00
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
typedef struct {
|
2014-07-31 20:51:50 +02:00
|
|
|
uint8_t domain;
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t protocol;
|
2014-07-31 17:53:46 +02:00
|
|
|
#ifdef MODULE_TCP
|
2014-07-31 20:51:50 +02:00
|
|
|
tcp_cb_t tcp_control;
|
2014-07-31 17:53:46 +02:00
|
|
|
#endif
|
2014-07-31 20:51:50 +02:00
|
|
|
sockaddr6_t local_address;
|
|
|
|
sockaddr6_t foreign_address;
|
2013-08-15 10:17:15 +02:00
|
|
|
} socket_t;
|
|
|
|
|
2014-07-08 20:40:55 +02:00
|
|
|
typedef struct {
|
2014-07-31 20:51:50 +02:00
|
|
|
uint8_t socket_id;
|
2014-07-31 17:53:46 +02:00
|
|
|
uint8_t recv_pid;
|
|
|
|
uint8_t send_pid;
|
|
|
|
socket_t socket_values;
|
|
|
|
#ifdef MODULE_TCP
|
2014-07-31 20:51:50 +02:00
|
|
|
uint8_t tcp_input_buffer_end;
|
|
|
|
mutex_t tcp_buffer_mutex;
|
2014-07-31 17:53:46 +02:00
|
|
|
uint8_t tcp_input_buffer[TRANSPORT_LAYER_SOCKET_MAX_TCP_BUFFER];
|
|
|
|
#endif
|
2013-08-15 10:17:15 +02:00
|
|
|
} socket_internal_t;
|
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
extern socket_internal_t socket_base_sockets[MAX_SOCKETS];
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
socket_internal_t *socket_base_get_socket(int s);
|
|
|
|
uint16_t socket_base_get_free_source_port(uint8_t protocol);
|
2014-12-02 14:58:44 +01:00
|
|
|
bool socket_base_exists_socket(int socket);
|
2014-07-31 17:53:46 +02:00
|
|
|
int socket_base_socket(int domain, int type, int protocol);
|
|
|
|
void socket_base_print_sockets(void);
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-31 17:53:46 +02:00
|
|
|
#endif /* _SOCKET_BASE_SOCKET */
|