mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-29 16:31:18 +01:00
[projects tlayer]
- Added: Close_TCP, TCP_Performance test, UDP_Performance test [sys net destiny] - bugfixes - Added: Simultaneous close, Memory protection for tcp timer thread [sys net sixlowpan] - Added: separate sending buffer (just a HACK workaround!)
This commit is contained in:
parent
c258075aaa
commit
1465da2e84
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <posix_io.h>
|
||||
#include <shell.h>
|
||||
@ -28,7 +29,11 @@
|
||||
#include "sys/net/net_help/net_help.h"
|
||||
#include "sys/net/net_help/msg_help.h"
|
||||
|
||||
#define SEND_TCP_THREAD_SIZE 3072
|
||||
#define SHELL_EXTRA_STACK_SIZE 3072
|
||||
|
||||
uint8_t udp_server_thread_pid;
|
||||
|
||||
char udp_server_stack_buffer[UDP_STACK_SIZE];
|
||||
|
||||
uint8_t tcp_server_thread_pid;
|
||||
@ -39,7 +44,10 @@ char tcp_cht_stack_buffer[TCP_STACK_SIZE];
|
||||
|
||||
int tcp_socket_id = -1;
|
||||
uint8_t tcp_send_pid = -1;
|
||||
char tcp_send_stack_buffer[2048];
|
||||
|
||||
char tcp_send_stack_buffer[SEND_TCP_THREAD_SIZE];
|
||||
// TODO: Add UDP_STACK_SIZE definition again!
|
||||
char shell_extra_stack[SHELL_EXTRA_STACK_SIZE];
|
||||
|
||||
typedef struct tcp_msg_t
|
||||
{
|
||||
@ -81,7 +89,10 @@ void tcp_ch(void)
|
||||
while (read_bytes != -1)
|
||||
{
|
||||
read_bytes = recv(SocketFD, buff_msg, MAX_TCP_BUFFER, 0);
|
||||
printf("--- Message: %s ---\n", buff_msg);
|
||||
if (read_bytes > 0)
|
||||
{
|
||||
printf("--- Message: %s ---\n", buff_msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -109,15 +120,15 @@ void init_udp_server(void)
|
||||
{
|
||||
printf("ERROR: recsize < 0!\n");
|
||||
}
|
||||
printf("recsize: %i\n ", recsize);
|
||||
printf("datagram: %s\n", buffer_main);
|
||||
// printf("recsize: %i\n ", recsize);
|
||||
// printf("datagram: %s\n", buffer_main);
|
||||
}
|
||||
}
|
||||
|
||||
void init_tcp_server(void)
|
||||
{
|
||||
sockaddr6_t stSockAddr;
|
||||
int read_bytes = 0;
|
||||
int read_bytes;
|
||||
char buff_msg[MAX_TCP_BUFFER];
|
||||
int SocketFD = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
@ -137,32 +148,38 @@ void init_tcp_server(void)
|
||||
|
||||
if(-1 == bind(SocketFD, &stSockAddr, sizeof(stSockAddr)))
|
||||
{
|
||||
perror("error bind failed");
|
||||
printf("error bind failed\n");
|
||||
close(SocketFD);
|
||||
exit(EXIT_FAILURE);
|
||||
return;
|
||||
}
|
||||
print_internal_socket(getSocket(SocketFD));
|
||||
if(-1 == listen(SocketFD, 10))
|
||||
{
|
||||
perror("error listen failed");
|
||||
printf("error listen failed\n");
|
||||
close(SocketFD);
|
||||
exit(EXIT_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("INFO: WAITING FOR INC CONNECTIONS!\n");
|
||||
int ConnectFD = accept(SocketFD, NULL, 0);
|
||||
if(0 > ConnectFD)
|
||||
while (1)
|
||||
{
|
||||
perror("error accept failed");
|
||||
close(SocketFD);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
tcp_socket_id = ConnectFD;
|
||||
while (read_bytes != -1)
|
||||
{
|
||||
read_bytes = recv(ConnectFD, buff_msg, MAX_TCP_BUFFER, 0);
|
||||
printf("--- Message: %s ---\n", buff_msg);
|
||||
read_bytes = 0;
|
||||
printf("INFO: WAITING FOR INC CONNECTIONS!\n");
|
||||
int ConnectFD = accept(SocketFD, NULL, 0);
|
||||
if(0 > ConnectFD)
|
||||
{
|
||||
printf("error accept failed\n");
|
||||
close(SocketFD);
|
||||
return;
|
||||
}
|
||||
tcp_socket_id = ConnectFD;
|
||||
while (read_bytes != -1)
|
||||
{
|
||||
read_bytes = recv(ConnectFD, buff_msg, MAX_TCP_BUFFER, 0);
|
||||
|
||||
if (read_bytes > 0)
|
||||
{
|
||||
printf("--- Message: %s ---\n", buff_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,6 +235,7 @@ void send_tcp_msg(char *str)
|
||||
send_msg.content.value = 1;
|
||||
}
|
||||
msg_send_receive(&send_msg, &recv_msg, tcp_send_pid);
|
||||
// msg_send(&send_msg, tcp_send_pid, 0);
|
||||
}
|
||||
|
||||
void send_tcp_bulk(char *str)
|
||||
@ -233,6 +251,29 @@ void send_tcp_bulk(char *str)
|
||||
}
|
||||
}
|
||||
|
||||
void send_tcp_bandwidth_test(char *str)
|
||||
{
|
||||
timex_t start, end, total;
|
||||
uint32_t secs;
|
||||
|
||||
int i = 0, count;
|
||||
char command[61];
|
||||
char msg_string[] = "abcdefghijklmnopqrstuvwxyz0123456789!-=$%&/()";
|
||||
|
||||
sscanf(str, "tcp_bw %i", &count);
|
||||
start = vtimer_now();
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
sprintf(command, "send_tcp %s%i", msg_string, i);
|
||||
send_tcp_msg(command);
|
||||
}
|
||||
end = vtimer_now();
|
||||
total = timex_sub(end, start);
|
||||
printf("Start: %lu, End: %lu, Total: %lu\n", start.microseconds, end.microseconds, total.microseconds);
|
||||
secs = total.microseconds / 1000000;
|
||||
printf("Time: %lu seconds, Bandwidth: %lu byte/second\n", secs, (count*48)/secs);
|
||||
}
|
||||
|
||||
void connect_tcp(char *str)
|
||||
{
|
||||
msg_t send_msg;
|
||||
@ -312,7 +353,7 @@ void init(char *str){
|
||||
break;
|
||||
}
|
||||
tcp_send_pid = thread_create( tcp_send_stack_buffer,
|
||||
2048,
|
||||
SEND_TCP_THREAD_SIZE,
|
||||
PRIORITY_MAIN,
|
||||
CREATE_STACKTEST,
|
||||
send_tcp_thread,
|
||||
@ -360,13 +401,15 @@ void send_packet(char *str){
|
||||
|
||||
void send_udp(char *str)
|
||||
{
|
||||
timex_t start, end, total;
|
||||
uint32_t secs;
|
||||
int sock;
|
||||
sockaddr6_t sa;
|
||||
ipv6_addr_t ipaddr;
|
||||
int bytes_sent;
|
||||
int address;
|
||||
uint8_t text[20];
|
||||
sscanf(str, "send_udp %s %i", text, &address);
|
||||
int address, count;
|
||||
uint8_t text[] = "abcdefghijklmnopqrstuvwxyz0123456789!-=$%&/()";
|
||||
sscanf(str, "send_udp %i %i", &count, &address);
|
||||
|
||||
sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (-1 == sock)
|
||||
@ -383,13 +426,20 @@ void send_udp(char *str)
|
||||
sa.sin6_family = AF_INET;
|
||||
memcpy(&sa.sin6_addr, &ipaddr, 16);
|
||||
sa.sin6_port = HTONS(7654);
|
||||
|
||||
bytes_sent = sendto(sock, (char*)text, strlen((char*)text)+1, 0, &sa, sizeof sa);
|
||||
if (bytes_sent < 0)
|
||||
start = vtimer_now();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
printf("Error sending packet!\n");
|
||||
bytes_sent = sendto(sock, (char*)text, strlen((char*)text)+1, 0, &sa, sizeof sa);
|
||||
if (bytes_sent < 0)
|
||||
{
|
||||
printf("Error sending packet!\n");
|
||||
}
|
||||
}
|
||||
|
||||
end = vtimer_now();
|
||||
total = timex_sub(end, start);
|
||||
printf("Start: %lu, End: %lu, Total: %lu\n", start.microseconds, end.microseconds, total.microseconds);
|
||||
secs = total.microseconds / 1000000;
|
||||
printf("Time: %lu seconds, Bandwidth: %lu byte/second\n", secs, (count*48)/secs);
|
||||
close(sock);
|
||||
}
|
||||
|
||||
@ -452,6 +502,17 @@ void continue_process(char *str)
|
||||
msg_send(&send, pid, 0);
|
||||
}
|
||||
|
||||
void close_tcp_thread(void)
|
||||
{
|
||||
close(tcp_socket_id);
|
||||
}
|
||||
|
||||
void close_tcp (char *str)
|
||||
{
|
||||
thread_create(shell_extra_stack, SHELL_EXTRA_STACK_SIZE, PRIORITY_MAIN,
|
||||
CREATE_STACKTEST, close_tcp_thread, "close_tcp_thread");
|
||||
}
|
||||
|
||||
const shell_command_t shell_commands[] = {
|
||||
{"init", "", init},
|
||||
{"addr", "", get_r_address},
|
||||
@ -461,7 +522,6 @@ const shell_command_t shell_commands[] = {
|
||||
{"shows", "Show Sockets", shows},
|
||||
{"show_reas", "Show reassembly Buffers", showReas},
|
||||
{"context", "", context},
|
||||
{"init_tl", "", init_tl},
|
||||
{"init_udp_server_thread", "", init_udp_server_thread},
|
||||
{"init_tcp_server_thread", "", init_tcp_server_thread},
|
||||
{"init_tcp_cht", "", init_tcp_cht},
|
||||
@ -471,6 +531,8 @@ const shell_command_t shell_commands[] = {
|
||||
{"send_tcp_bulk", "send_tcp_bulk NO_OF_PACKETS PAYLOAD", send_tcp_bulk},
|
||||
{"kill_process", "", kill_process},
|
||||
{"continue_process", "", continue_process},
|
||||
{"close_tcp", "", close_tcp},
|
||||
{"tcp_bw", "tcp_bw NO_OF_PACKETS", send_tcp_bandwidth_test},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
@ -478,6 +540,7 @@ int main(void) {
|
||||
printf("6LoWPAN Transport Layers\n");
|
||||
posix_open(uart0_handler_pid, 0);
|
||||
init_tl(NULL);
|
||||
|
||||
shell_t shell;
|
||||
shell_init(&shell, shell_commands, uart0_readc, uart0_putc);
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ void init_transport_layer(void)
|
||||
// TCP
|
||||
int tcp_thread_pid = thread_create(tcp_stack_buffer, TCP_STACK_SIZE, PRIORITY_MAIN, CREATE_STACKTEST, tcp_packet_handler, "tcp_packet_handler");
|
||||
set_tcp_packet_handler_pid(tcp_thread_pid);
|
||||
|
||||
tcp_timer_pid = thread_create(tcp_timer_stack, TCP_TIMER_STACKSIZE, PRIORITY_MAIN+1, CREATE_STACKTEST, tcp_general_timer, "tcp_general_timer");
|
||||
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ void print_tcp_cb(tcp_cb *cb)
|
||||
{
|
||||
printf("Send_ISS: %lu\nSend_UNA: %lu\nSend_NXT: %lu\nSend_WND: %u\n", cb->send_iss, cb->send_una, cb->send_nxt, cb->send_wnd);
|
||||
printf("Rcv_IRS: %lu\nRcv_NXT: %lu\nRcv_WND: %u\n", cb->rcv_irs, cb->rcv_nxt, cb->rcv_wnd);
|
||||
printf("Time difference: %lu, No_of_retrie: %u, State: %u\n\n", timex_sub(vtimer_now(), cb->last_packet_time).microseconds, cb->no_of_retry, cb->state);
|
||||
printf("Time difference: %lu, No_of_retries: %u, State: %u\n\n", timex_sub(vtimer_now(), cb->last_packet_time).microseconds, cb->no_of_retry, cb->state);
|
||||
}
|
||||
|
||||
void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_t *tcp_socket)
|
||||
@ -150,7 +150,8 @@ bool exists_socket(uint8_t socket)
|
||||
|
||||
void close_socket(socket_internal_t *current_socket)
|
||||
{
|
||||
memset(current_socket, 0, sizeof(current_socket));
|
||||
printf("Closing Socket %i with size %i!\n", current_socket->socket_id, sizeof(socket_internal_t));
|
||||
memset(current_socket, 0, sizeof(socket_internal_t));
|
||||
}
|
||||
|
||||
bool isUDPSocket(uint8_t s)
|
||||
@ -520,7 +521,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
|
||||
sent_bytes = len;
|
||||
}
|
||||
|
||||
current_tcp_socket->tcp_control.send_nxt += sent_bytes - 1;
|
||||
current_tcp_socket->tcp_control.send_nxt += sent_bytes;
|
||||
current_tcp_socket->tcp_control.send_wnd -= sent_bytes;
|
||||
send_tcp(NULL, current_tcp_socket, current_tcp_packet, temp_ipv6_header, 0, sent_bytes);
|
||||
|
||||
@ -528,18 +529,20 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
|
||||
current_tcp_socket->tcp_control.last_packet_time = vtimer_now();
|
||||
|
||||
net_msg_receive(&recv_msg);
|
||||
// printf("Send(): Got Message from TCP Layer: %u\n", recv_msg.type);
|
||||
switch (recv_msg.type)
|
||||
{
|
||||
case TCP_ACK:
|
||||
{
|
||||
tcp_hdr_t *tcp_header = ((tcp_hdr_t*)(recv_msg.content.ptr));
|
||||
// printf("send nxt: %li, tcp_ack_nr: %li\n", current_tcp_socket->tcp_control.send_nxt, tcp_header->ack_nr);
|
||||
if (current_tcp_socket->tcp_control.send_nxt == tcp_header->ack_nr-1)
|
||||
// printf("send nxt: %li, tcp_ack_nr: %li\n", current_tcp_socket->tcp_control.send_nxt, tcp_header->ack_nr);
|
||||
if (current_tcp_socket->tcp_control.send_nxt == tcp_header->ack_nr)
|
||||
{
|
||||
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
|
||||
// printf("Returning from sen().\n");
|
||||
return sent_bytes;
|
||||
}
|
||||
else
|
||||
@ -550,7 +553,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
|
||||
}
|
||||
case TCP_RETRY:
|
||||
{
|
||||
current_tcp_socket->tcp_control.send_nxt -= sent_bytes - 1;
|
||||
current_tcp_socket->tcp_control.send_nxt -= sent_bytes;
|
||||
current_tcp_socket->tcp_control.send_wnd += sent_bytes;
|
||||
break;
|
||||
}
|
||||
@ -570,23 +573,27 @@ uint8_t read_from_socket(socket_internal_t *current_int_tcp_socket, void *buf, i
|
||||
{
|
||||
if (len > current_int_tcp_socket->tcp_input_buffer_end)
|
||||
{
|
||||
mutex_lock(¤t_int_tcp_socket->tcp_buffer_mutex);
|
||||
uint8_t read_bytes = current_int_tcp_socket->tcp_input_buffer_end;
|
||||
memcpy(buf, current_int_tcp_socket->tcp_input_buffer, current_int_tcp_socket->tcp_input_buffer_end);
|
||||
current_int_tcp_socket->tcp_input_buffer_end = 0;
|
||||
current_int_tcp_socket->socket_values.tcp_control.rcv_wnd += read_bytes;
|
||||
mutex_unlock(¤t_int_tcp_socket->tcp_buffer_mutex, 0);
|
||||
return read_bytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutex_lock(¤t_int_tcp_socket->tcp_buffer_mutex);
|
||||
memcpy(buf, current_int_tcp_socket->tcp_input_buffer, len);
|
||||
memmove(current_int_tcp_socket->tcp_input_buffer, (current_int_tcp_socket->tcp_input_buffer+len), current_int_tcp_socket->tcp_input_buffer_end-len);
|
||||
current_int_tcp_socket->tcp_input_buffer_end = current_int_tcp_socket->tcp_input_buffer_end-len;
|
||||
current_int_tcp_socket->socket_values.tcp_control.rcv_wnd += len;
|
||||
mutex_unlock(¤t_int_tcp_socket->tcp_buffer_mutex, 0);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t recv(int s, void *buf, uint64_t len, int flags)
|
||||
int recv(int s, void *buf, uint64_t len, int flags)
|
||||
{
|
||||
// Variables
|
||||
msg_t m_recv;
|
||||
@ -613,19 +620,21 @@ int32_t recv(int s, void *buf, uint64_t len, int flags)
|
||||
|
||||
msg_receive(&m_recv);
|
||||
|
||||
if (current_int_tcp_socket->tcp_input_buffer_end > 0)
|
||||
if ((exists_socket(s)) && (current_int_tcp_socket->tcp_input_buffer_end > 0))
|
||||
{
|
||||
return read_from_socket(current_int_tcp_socket, buf, len);
|
||||
}
|
||||
|
||||
// Received FIN
|
||||
if (m_recv.content.value == CLOSE_CONN)
|
||||
if (m_recv.type == CLOSE_CONN)
|
||||
{
|
||||
// Sent FIN_ACK, wait for ACK
|
||||
msg_receive(&m_recv);
|
||||
// Received ACK, return with closed socket!
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Received Last ACK (connection closed) or no data to read yet
|
||||
printf("Returning from Recv()!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -673,7 +682,7 @@ int32_t sendto(int s, void *msg, uint64_t len, int flags, sockaddr6_t *to, uint3
|
||||
udp_hdr_t *current_udp_packet = ((udp_hdr_t*)(&send_buffer[IPV6_HDR_LEN]));
|
||||
uint8_t *payload = &send_buffer[IPV6_HDR_LEN+UDP_HDR_LEN];
|
||||
|
||||
ipv6_print_addr(&to->sin6_addr);
|
||||
// ipv6_print_addr(&to->sin6_addr);
|
||||
|
||||
memcpy(&(temp_ipv6_header->destaddr), &to->sin6_addr, 16);
|
||||
ipv6_get_saddr(&(temp_ipv6_header->srcaddr), &(temp_ipv6_header->destaddr));
|
||||
@ -721,6 +730,8 @@ int close(int s)
|
||||
return 1;
|
||||
}
|
||||
|
||||
current_socket->send_pid = thread_getpid();
|
||||
|
||||
// Refresh local TCP socket information
|
||||
current_socket->socket_values.tcp_control.send_una++;
|
||||
current_socket->socket_values.tcp_control.state = FIN_WAIT_1;
|
||||
@ -728,6 +739,7 @@ int close(int s)
|
||||
send_tcp(NULL, ¤t_socket->socket_values, current_tcp_packet, temp_ipv6_header, TCP_FIN, 0);
|
||||
msg_receive(&m_recv);
|
||||
close_socket(current_socket);
|
||||
printf("Returning from Close()!\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@ -833,17 +845,29 @@ int listen(int s, int backlog)
|
||||
}
|
||||
}
|
||||
|
||||
socket_internal_t *getWaitingConnectionSocket(int socket)
|
||||
socket_internal_t *getWaitingConnectionSocket(int socket, ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header)
|
||||
{
|
||||
int i;
|
||||
socket_internal_t *current_socket, *listening_socket = getSocket(socket);
|
||||
for (i = 0; i < MAX_SOCKETS; i++)
|
||||
{
|
||||
current_socket = getSocket(i);
|
||||
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))
|
||||
// Connection establishment ACK, Check for 4 touple and state
|
||||
if ((ipv6_header != NULL) && (tcp_header != NULL))
|
||||
{
|
||||
return current_socket;
|
||||
if (is_four_touple(current_socket, ipv6_header, tcp_header) && (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))
|
||||
{
|
||||
return current_socket;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@ -915,7 +939,7 @@ int accept(int s, sockaddr6_t *addr, uint32_t addrlen)
|
||||
socket_internal_t *server_socket = getSocket(s);
|
||||
if (isTCPSocket(s) && (server_socket->socket_values.tcp_control.state == LISTEN))
|
||||
{
|
||||
socket_internal_t *current_queued_socket = getWaitingConnectionSocket(s);
|
||||
socket_internal_t *current_queued_socket = getWaitingConnectionSocket(s, NULL, NULL);
|
||||
if (current_queued_socket != NULL)
|
||||
{
|
||||
return handle_new_tcp_connection(current_queued_socket, server_socket, thread_getpid());
|
||||
@ -924,9 +948,13 @@ int accept(int s, sockaddr6_t *addr, uint32_t addrlen)
|
||||
{
|
||||
// No waiting connections, waiting for message from TCP Layer
|
||||
msg_t msg_recv_client_syn;
|
||||
msg_receive(&msg_recv_client_syn);
|
||||
msg_recv_client_syn.type = UNDEFINED;
|
||||
while (msg_recv_client_syn.type != TCP_SYN)
|
||||
{
|
||||
msg_receive(&msg_recv_client_syn);
|
||||
}
|
||||
|
||||
current_queued_socket = getWaitingConnectionSocket(s);
|
||||
current_queued_socket = getWaitingConnectionSocket(s, NULL, NULL);
|
||||
|
||||
return handle_new_tcp_connection(current_queued_socket, server_socket, thread_getpid());
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@
|
||||
|
||||
#define EPHEMERAL_PORTS 49152
|
||||
|
||||
#define STATIC_MSS 32
|
||||
#define STATIC_MSS 48
|
||||
#define STATIC_WINDOW 1 * STATIC_MSS
|
||||
#define MAX_TCP_BUFFER 1 * STATIC_WINDOW
|
||||
|
||||
@ -162,6 +162,7 @@ typedef struct __attribute__ ((packed)) socket_in_t
|
||||
// TODO: Maybe use ring buffer instead of copying array values each time
|
||||
uint8_t tcp_input_buffer_end;
|
||||
uint8_t tcp_input_buffer[MAX_TCP_BUFFER];
|
||||
mutex_t tcp_buffer_mutex;
|
||||
socket_t socket_values;
|
||||
// socket_t queued_sockets[MAX_QUEUED_SOCKETS];
|
||||
} socket_internal_t;
|
||||
@ -170,11 +171,12 @@ socket_internal_t sockets[MAX_SOCKETS];
|
||||
|
||||
int socket(int domain, int type, int protocol);
|
||||
int connect(int socket, sockaddr6_t *addr, uint32_t addrlen);
|
||||
socket_internal_t *getWaitingConnectionSocket(int socket);
|
||||
socket_internal_t *getWaitingConnectionSocket(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, uint64_t len, int flags, sockaddr6_t *from, uint32_t *fromlen );
|
||||
int32_t sendto( int s, void *msg, uint64_t len, int flags, sockaddr6_t *to, uint32_t tolen);
|
||||
int32_t send(int s, void *msg, uint64_t len, int flags);
|
||||
int32_t recv(int s, void *buf, uint64_t len, int flags);
|
||||
int recv(int s, void *buf, uint64_t len, int flags);
|
||||
int close(int s);
|
||||
int bind(int s, sockaddr6_t *name, int namelen);
|
||||
int listen(int s, int backlog);
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "vtimer.h"
|
||||
#include "tcp_timer.h"
|
||||
#include "tcp.h"
|
||||
#include "in.h"
|
||||
#include "socket.h"
|
||||
@ -61,19 +62,24 @@ uint8_t handle_payload(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_in
|
||||
uint8_t acknowledged_bytes = 0;
|
||||
if (tcp_payload_len > tcp_socket->socket_values.tcp_control.rcv_wnd)
|
||||
{
|
||||
mutex_lock(&tcp_socket->tcp_buffer_mutex);
|
||||
memcpy(tcp_socket->tcp_input_buffer, payload, tcp_socket->socket_values.tcp_control.rcv_wnd);
|
||||
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;
|
||||
mutex_unlock(&tcp_socket->tcp_buffer_mutex, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
mutex_lock(&tcp_socket->tcp_buffer_mutex);
|
||||
memcpy(tcp_socket->tcp_input_buffer, payload, tcp_payload_len);
|
||||
tcp_socket->socket_values.tcp_control.rcv_wnd = 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;
|
||||
mutex_unlock(&tcp_socket->tcp_buffer_mutex, 0);
|
||||
}
|
||||
|
||||
// msg_receive(&m_recv_tcp);
|
||||
// printf("Sending MSG to Receiving Thread!\n");
|
||||
msg_send(&m_send_tcp, tcp_socket->recv_pid, 0);
|
||||
return acknowledged_bytes;
|
||||
}
|
||||
@ -81,15 +87,23 @@ uint8_t handle_payload(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_in
|
||||
void handle_tcp_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_internal_t *tcp_socket)
|
||||
{
|
||||
msg_t m_recv_tcp, m_send_tcp;
|
||||
uint8_t target_pid;
|
||||
|
||||
if (tcp_socket->socket_values.tcp_control.state == LAST_ACK)
|
||||
{
|
||||
target_pid = tcp_socket->recv_pid;
|
||||
close_socket(tcp_socket);
|
||||
msg_send(&m_send_tcp, target_pid, 0);
|
||||
return;
|
||||
}
|
||||
else if (tcp_socket->socket_values.tcp_control.state == CLOSING)
|
||||
{
|
||||
msg_send(&m_send_tcp, tcp_socket->recv_pid, 0);
|
||||
memset(tcp_socket, 0, sizeof(socket_internal_t));
|
||||
msg_send(&m_send_tcp, tcp_socket->send_pid, 0);
|
||||
return;
|
||||
}
|
||||
// TODO: Find better way of handling queued sockets ACK packets
|
||||
else if (getWaitingConnectionSocket(tcp_socket->socket_id) != NULL)
|
||||
else if (getWaitingConnectionSocket(tcp_socket->socket_id, ipv6_header, tcp_header) != NULL)
|
||||
{
|
||||
printf("sending ACK to queued socket!\n");
|
||||
m_send_tcp.content.ptr = (char*)tcp_header;
|
||||
@ -120,7 +134,7 @@ void handle_tcp_syn_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socke
|
||||
{
|
||||
// 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
|
||||
msg_send(&m_send_tcp, tcp_socket->recv_pid, 0);
|
||||
net_msg_send(&m_send_tcp, tcp_socket->recv_pid, 0, TCP_SYN);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -155,15 +169,22 @@ void handle_tcp_fin_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socke
|
||||
ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t*)(&send_buffer));
|
||||
tcp_hdr_t *current_tcp_packet = ((tcp_hdr_t*)(&send_buffer[IPV6_HDR_LEN]));
|
||||
|
||||
current_tcp_socket->tcp_control.state = LAST_ACK;
|
||||
|
||||
set_tcp_cb(¤t_tcp_socket->tcp_control, tcp_header->seq_nr+1, current_tcp_socket->tcp_control.send_wnd, tcp_header->ack_nr,
|
||||
tcp_header->ack_nr, tcp_header->window);
|
||||
tcp_header->ack_nr, tcp_header->window);
|
||||
|
||||
send_tcp(NULL, current_tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0);
|
||||
if (current_tcp_socket->tcp_control.state == FIN_WAIT_1)
|
||||
{
|
||||
current_tcp_socket->tcp_control.state = CLOSING;
|
||||
|
||||
m_send.content.value = CLOSE_CONN;
|
||||
msg_send(&m_send, tcp_socket->recv_pid, 0);
|
||||
send_tcp(NULL, current_tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_tcp_socket->tcp_control.state = LAST_ACK;
|
||||
|
||||
send_tcp(NULL, current_tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_FIN_ACK, 0);
|
||||
}
|
||||
net_msg_send(&m_send, tcp_socket->recv_pid, 0, CLOSE_CONN);
|
||||
}
|
||||
|
||||
void handle_tcp_fin_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_internal_t *tcp_socket)
|
||||
@ -180,8 +201,8 @@ void handle_tcp_fin_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, s
|
||||
tcp_header->ack_nr, tcp_header->window);
|
||||
|
||||
send_tcp(NULL, current_tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
|
||||
memset(tcp_socket, 0, sizeof(socket_internal_t));
|
||||
|
||||
msg_send(&m_send, tcp_socket->send_pid, 0);
|
||||
msg_send(&m_send, tcp_socket->recv_pid, 0);
|
||||
}
|
||||
|
||||
@ -200,13 +221,15 @@ void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
|
||||
// Refresh TCP status values
|
||||
current_tcp_socket->tcp_control.state = ESTABLISHED;
|
||||
|
||||
// printf(" INFOS: TCP Header Seq Nr: %lu, Read Bytes: %u, Both: %lu\n", tcp_header->seq_nr, read_bytes, tcp_header->seq_nr + read_bytes);
|
||||
|
||||
set_tcp_cb(¤t_tcp_socket->tcp_control,
|
||||
tcp_header->seq_nr + read_bytes,
|
||||
current_tcp_socket->tcp_control.rcv_wnd,
|
||||
current_tcp_socket->tcp_control.send_nxt,
|
||||
current_tcp_socket->tcp_control.send_una,
|
||||
current_tcp_socket->tcp_control.send_wnd);
|
||||
|
||||
// printf(" INFOS: %lu\n", current_tcp_socket->tcp_control.rcv_nxt);
|
||||
// Send packet
|
||||
send_tcp(NULL, current_tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ enum tcp_codes
|
||||
UNDEFINED = 0,
|
||||
PACKET_OK = 1,
|
||||
CLOSE_CONN = 2,
|
||||
SEQ_NO_TOO_SMALL = 3,
|
||||
SEQ_NO_TOO_SMALL = 3,
|
||||
ACK_NO_TOO_SMALL = 4,
|
||||
ACK_NO_TOO_BIG = 5
|
||||
};
|
||||
@ -64,7 +64,7 @@ enum tcp_codes
|
||||
#define SET_TCP_FIN_ACK(a) a = ((a & 0x00) | TCP_FIN_ACK)
|
||||
|
||||
// TODO: Probably stack size too high
|
||||
#define TCP_STACK_SIZE 4096
|
||||
#define TCP_STACK_SIZE 3072
|
||||
|
||||
#include "sys/net/sixlowpan/sixlowip.h"
|
||||
//
|
||||
|
||||
@ -113,8 +113,6 @@ void tcp_general_timer(void)
|
||||
while (1)
|
||||
{
|
||||
check_sockets();
|
||||
// cur_time = vtimer_now();
|
||||
// printf("Time Seconds: %li uSeconds: %li\n", cur_time.seconds, cur_time.microseconds);
|
||||
vtimer_set_wakeup(&tcp_vtimer, interval, tcp_timer_pid);
|
||||
thread_sleep();
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
|
||||
// TODO: Probably stack size too high
|
||||
#define UDP_STACK_SIZE 4096
|
||||
#define UDP_STACK_SIZE 3072
|
||||
|
||||
#include "sys/net/sixlowpan/sixlowip.h"
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include "sys/net/net_help/msg_help.h"
|
||||
#include "sys/net/sixlowpan/rpl/rpl.h"
|
||||
|
||||
uint8_t ip_send_buffer[BUFFER_SIZE];
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
msg_t msg_queue[IP_PKT_RECV_BUF_SIZE];
|
||||
struct ipv6_hdr_t* ipv6_buf;
|
||||
@ -24,10 +25,14 @@ uint8_t iface_addr_list_count = 0;
|
||||
int udp_packet_handler_pid = 0;
|
||||
int tcp_packet_handler_pid = 0;
|
||||
int rpl_process_pid = 0;
|
||||
//uint8_t *udp_packet_buffer;
|
||||
//uint8_t *tcp_packet_buffer;
|
||||
|
||||
//mutex_t buf_mutex;
|
||||
struct ipv6_hdr_t* get_ipv6_buf_send(void){
|
||||
return ((struct ipv6_hdr_t*)&(ip_send_buffer[LL_HDR_LEN]));
|
||||
}
|
||||
|
||||
uint8_t * get_payload_buf_send(uint8_t ext_len){
|
||||
return &(ip_send_buffer[LLHDR_IPV6HDR_LEN + ext_len]);
|
||||
}
|
||||
|
||||
struct ipv6_hdr_t* get_ipv6_buf(void){
|
||||
return ((struct ipv6_hdr_t*)&(buffer[LL_HDR_LEN]));
|
||||
@ -46,8 +51,18 @@ void sixlowpan_bootstrapping(void){
|
||||
init_rtr_sol(OPT_SLLAO);
|
||||
}
|
||||
|
||||
void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, uint8_t next_header){
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, uint8_t next_header, void *tcp_socket){
|
||||
uint8_t *p_ptr;
|
||||
if (next_header == IPPROTO_TCP)
|
||||
{
|
||||
p_ptr = get_payload_buf_send(ipv6_ext_hdr_len);
|
||||
ipv6_buf = get_ipv6_buf_send();
|
||||
}
|
||||
else
|
||||
{
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
p_ptr = get_payload_buf(ipv6_ext_hdr_len);
|
||||
}
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
packet_length = 0;
|
||||
|
||||
@ -61,15 +76,13 @@ void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, uint8_t
|
||||
memcpy(&(ipv6_buf->destaddr), addr, 16);
|
||||
ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
|
||||
uint8_t *p_ptr = get_payload_buf(ipv6_ext_hdr_len);
|
||||
|
||||
memcpy(p_ptr,payload,p_len);
|
||||
|
||||
packet_length = IPV6_HDR_LEN + p_len;
|
||||
|
||||
#ifdef MODULE_DESTINY
|
||||
if (next_header == IPPROTO_TCP) {
|
||||
print_tcp_status(OUT_PACKET, ipv6_buf, (tcp_hdr_t *)(payload));
|
||||
// print_tcp_status(OUT_PACKET, ipv6_buf, (tcp_hdr_t *)(payload), (socket_t *)tcp_socket);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -122,14 +135,15 @@ int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr) {
|
||||
}
|
||||
|
||||
void ipv6_process(void){
|
||||
msg_t m_recv_lowpan;
|
||||
msg_t m_recv, m_send;
|
||||
msg_init_queue(msg_queue, IP_PKT_RECV_BUF_SIZE);
|
||||
|
||||
while(1){
|
||||
msg_receive(&m_recv);
|
||||
msg_receive(&m_recv_lowpan);
|
||||
|
||||
//ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = (struct ipv6_hdr_t*) m_recv.content.ptr;
|
||||
ipv6_buf = (struct ipv6_hdr_t*) m_recv_lowpan.content.ptr;
|
||||
|
||||
/* identifiy packet */
|
||||
nextheader = &ipv6_buf->nextheader;
|
||||
@ -161,7 +175,7 @@ void ipv6_process(void){
|
||||
}
|
||||
case(IPPROTO_UDP):
|
||||
{
|
||||
printf("INFO: UDP Packet received.\n");
|
||||
// printf("INFO: UDP Packet received.\n");
|
||||
|
||||
if (udp_packet_handler_pid != 0)
|
||||
{
|
||||
|
||||
@ -129,6 +129,7 @@ extern iface_t iface;
|
||||
struct icmpv6_hdr_t* get_icmpv6_buf(uint8_t ext_len);
|
||||
struct ipv6_hdr_t* get_ipv6_buf(void);
|
||||
uint8_t * get_payload_buf(uint8_t ext_len);
|
||||
uint8_t * get_payload_buf_send(uint8_t ext_len);
|
||||
|
||||
int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr);
|
||||
void ipv6_init_iface_as_router(void);
|
||||
@ -139,7 +140,7 @@ void ipv6_set_all_nds_mcast_addr(ipv6_addr_t *ipaddr);
|
||||
void ipv6_set_loaddr(ipv6_addr_t *ipaddr);
|
||||
void ipv6_set_sol_node_mcast_addr(ipv6_addr_t *addr_in, ipv6_addr_t *addr_out);
|
||||
void sixlowpan_bootstrapping(void);
|
||||
void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, uint8_t next_header);
|
||||
void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, uint8_t next_header, void *tcp_socket);
|
||||
void ipv6_print_addr(ipv6_addr_t *ipaddr);
|
||||
void ipv6_process(void);
|
||||
void ipv6_get_saddr(ipv6_addr_t *src, ipv6_addr_t *dst);
|
||||
|
||||
@ -1,26 +1,26 @@
|
||||
/* 6LoWPAN MAC header file */
|
||||
|
||||
#ifndef SIXLOWMAC_H
|
||||
#define SIXLOWMAC_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "sixlowip.h"
|
||||
#include "radio/radio.h"
|
||||
#include <transceiver.h>
|
||||
|
||||
#define RADIO_STACK_SIZE 3072
|
||||
#define RADIO_RCV_BUF_SIZE 64
|
||||
#define RADIO_SND_BUF_SIZE 100
|
||||
#define RADIO_SENDING_DELAY 1000
|
||||
|
||||
uint8_t get_radio_address(void);
|
||||
void set_radio_address(uint8_t addr);
|
||||
void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload,
|
||||
uint8_t length, uint8_t mcast);
|
||||
void init_802154_long_addr(ieee_802154_long_t *laddr);
|
||||
void init_802154_short_addr(ieee_802154_short_t *saddr);
|
||||
void sixlowmac_init(transceiver_type_t type);
|
||||
ieee_802154_long_t* mac_get_eui(ipv6_addr_t *ipaddr);
|
||||
|
||||
#endif /* SIXLOWMAC_H*/
|
||||
/* 6LoWPAN MAC header file */
|
||||
|
||||
#ifndef SIXLOWMAC_H
|
||||
#define SIXLOWMAC_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "sixlowip.h"
|
||||
#include "radio/radio.h"
|
||||
#include <transceiver.h>
|
||||
|
||||
#define RADIO_STACK_SIZE 512
|
||||
#define RADIO_RCV_BUF_SIZE 64
|
||||
#define RADIO_SND_BUF_SIZE 100
|
||||
#define RADIO_SENDING_DELAY 1000
|
||||
|
||||
uint8_t get_radio_address(void);
|
||||
void set_radio_address(uint8_t addr);
|
||||
void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload,
|
||||
uint8_t length, uint8_t mcast);
|
||||
void init_802154_long_addr(ieee_802154_long_t *laddr);
|
||||
void init_802154_short_addr(ieee_802154_short_t *saddr);
|
||||
void sixlowmac_init(transceiver_type_t type);
|
||||
ieee_802154_long_t* mac_get_eui(ipv6_addr_t *ipaddr);
|
||||
|
||||
#endif /* SIXLOWMAC_H*/
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "sixlownd.h"
|
||||
#include "transceiver.h"
|
||||
#include "ieee802154_frame.h"
|
||||
#include "sys/net/destiny/in.h"
|
||||
|
||||
uint16_t packet_length;
|
||||
uint8_t packet_dispatch;
|
||||
@ -57,10 +58,11 @@ void lowpan_context_auto_remove(void);
|
||||
|
||||
/* deliver packet to mac*/
|
||||
void lowpan_init(ieee_802154_long_t *addr, uint8_t *data){
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
uint8_t mcast = 0;
|
||||
|
||||
memcpy(&laddr.uint8[0], &addr->uint8[0], 8);
|
||||
ipv6_buf = (ipv6_hdr_t *) data;
|
||||
|
||||
memcpy(&laddr.uint8[0], &addr->uint8[0], 8);
|
||||
|
||||
if(ipv6_prefix_mcast_match(&ipv6_buf->destaddr)){
|
||||
/* send broadcast */
|
||||
@ -68,7 +70,7 @@ void lowpan_init(ieee_802154_long_t *addr, uint8_t *data){
|
||||
}
|
||||
|
||||
//#ifdef LOWPAN_IPHC
|
||||
lowpan_iphc_encoding(&laddr);
|
||||
lowpan_iphc_encoding(&laddr, ipv6_buf);
|
||||
data = &comp_buf[0];
|
||||
packet_length = comp_len;
|
||||
|
||||
@ -506,8 +508,9 @@ void lowpan_ipv6_set_dispatch(uint8_t *data){
|
||||
}
|
||||
|
||||
/* draft-ietf-6lowpan-hc-13#section-3.1 */
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest){
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra){
|
||||
ipv6_buf = ipv6_buf_extra;
|
||||
|
||||
uint16_t payload_length = ipv6_buf->length;
|
||||
uint8_t lowpan_iphc[2];
|
||||
uint8_t *ipv6_hdr_fields = &comp_buf[2];
|
||||
@ -767,7 +770,15 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest){
|
||||
comp_buf[0] = lowpan_iphc[0];
|
||||
comp_buf[1] = lowpan_iphc[1];
|
||||
|
||||
uint8_t *ptr = get_payload_buf(ipv6_ext_hdr_len);
|
||||
uint8_t *ptr;
|
||||
if (ipv6_buf->nextheader == IPPROTO_TCP)
|
||||
{
|
||||
ptr = get_payload_buf_send(ipv6_ext_hdr_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = get_payload_buf(ipv6_ext_hdr_len);
|
||||
}
|
||||
|
||||
memcpy(&ipv6_hdr_fields[hdr_pos],ptr,ipv6_buf->length);
|
||||
|
||||
|
||||
@ -1,83 +1,83 @@
|
||||
#ifndef SIXLOWPAN_H
|
||||
#define SIXLOWPAN_H
|
||||
|
||||
#define IP_PROCESS_STACKSIZE 3072
|
||||
#define NC_STACKSIZE 512
|
||||
#define CON_STACKSIZE 512
|
||||
|
||||
/* fragment size in bytes*/
|
||||
#define FRAG_PART_ONE_HDR_LEN 4
|
||||
#define FRAG_PART_N_HDR_LEN 5
|
||||
|
||||
#define LOWPAN_IPHC_DISPATCH 0x60
|
||||
#define LOWPAN_IPHC_FL_C 0x10
|
||||
#define LOWPAN_IPHC_TC_C 0x08
|
||||
#define LOWPAN_IPHC_CID 0x80
|
||||
#define LOWPAN_IPHC_SAC 0x40
|
||||
#define LOWPAN_IPHC_SAM 0x30
|
||||
#define LOWPAN_IPHC_DAC 0x04
|
||||
#define LOWPAN_IPHC_DAM 0x03
|
||||
#define LOWPAN_IPHC_M 0x08
|
||||
#define LOWPAN_IPHC_NH 0x04
|
||||
#define LOWPAN_IPV6_DISPATCH 0x41
|
||||
#define LOWPAN_CONTEXT_MAX 16
|
||||
|
||||
#define LOWPAN_REAS_BUF_TIMEOUT 60
|
||||
|
||||
#include "transceiver.h"
|
||||
#include "sixlowip.h"
|
||||
#include <vtimer.h>
|
||||
#include <mutex.h>
|
||||
#include <time.h>
|
||||
|
||||
extern mutex_t lowpan_context_mutex;
|
||||
|
||||
typedef struct lowpan_context_t {
|
||||
uint8_t num;
|
||||
ipv6_addr_t prefix;
|
||||
uint8_t length;
|
||||
uint8_t comp;
|
||||
uint16_t lifetime;
|
||||
} lowpan_context_t;
|
||||
|
||||
typedef struct lowpan_interval_list_t {
|
||||
uint8_t start;
|
||||
uint8_t end;
|
||||
struct lowpan_interval_list_t *next;
|
||||
} lowpan_interval_list_t;
|
||||
|
||||
typedef struct lowpan_reas_buf_t {
|
||||
ieee_802154_long_t s_laddr; // Source Address
|
||||
ieee_802154_long_t d_laddr; // Destination Address
|
||||
uint16_t ident_no; // Identification Number
|
||||
time_t timestamp; // Timestamp of last packet fragment
|
||||
uint8_t packet_size; // Size of reassembled packet with possible IPHC header
|
||||
uint8_t current_packet_size; // Additive size of currently already received fragments
|
||||
uint8_t *packet; // Pointer to allocated memory for reassembled packet + 6LoWPAN Dispatch Byte
|
||||
lowpan_interval_list_t *interval_list_head; // Pointer to list of intervals of received packet fragments (if any)
|
||||
struct lowpan_reas_buf_t *next; // Pointer to next reassembly buffer (if any)
|
||||
} lowpan_reas_buf_t;
|
||||
|
||||
extern lowpan_reas_buf_t *head;
|
||||
|
||||
void sixlowpan_init(transceiver_type_t trans, uint8_t r_addr, int as_border);
|
||||
void sixlowpan_adhoc_init(transceiver_type_t trans, ipv6_addr_t *prefix, uint8_t r_addr);
|
||||
void lowpan_init(ieee_802154_long_t *addr, uint8_t *data);
|
||||
void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr,
|
||||
ieee_802154_long_t *d_laddr);
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest);
|
||||
void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
|
||||
ieee_802154_long_t *s_laddr,
|
||||
ieee_802154_long_t *d_laddr);
|
||||
uint8_t lowpan_context_len();
|
||||
lowpan_context_t * lowpan_context_update(
|
||||
uint8_t num, const ipv6_addr_t *prefix,
|
||||
uint8_t length, uint8_t comp,
|
||||
uint16_t lifetime);
|
||||
lowpan_context_t * lowpan_context_get();
|
||||
lowpan_context_t * lowpan_context_lookup(ipv6_addr_t *addr);
|
||||
lowpan_context_t * lowpan_context_num_lookup(uint8_t num);
|
||||
void lowpan_ipv6_set_dispatch(uint8_t *data);
|
||||
void init_reas_bufs(lowpan_reas_buf_t *buf);
|
||||
void printReasBuffers(void);
|
||||
#endif
|
||||
#ifndef SIXLOWPAN_H
|
||||
#define SIXLOWPAN_H
|
||||
|
||||
#define IP_PROCESS_STACKSIZE 3072
|
||||
#define NC_STACKSIZE 512
|
||||
#define CON_STACKSIZE 512
|
||||
|
||||
/* fragment size in bytes*/
|
||||
#define FRAG_PART_ONE_HDR_LEN 4
|
||||
#define FRAG_PART_N_HDR_LEN 5
|
||||
|
||||
#define LOWPAN_IPHC_DISPATCH 0x60
|
||||
#define LOWPAN_IPHC_FL_C 0x10
|
||||
#define LOWPAN_IPHC_TC_C 0x08
|
||||
#define LOWPAN_IPHC_CID 0x80
|
||||
#define LOWPAN_IPHC_SAC 0x40
|
||||
#define LOWPAN_IPHC_SAM 0x30
|
||||
#define LOWPAN_IPHC_DAC 0x04
|
||||
#define LOWPAN_IPHC_DAM 0x03
|
||||
#define LOWPAN_IPHC_M 0x08
|
||||
#define LOWPAN_IPHC_NH 0x04
|
||||
#define LOWPAN_IPV6_DISPATCH 0x41
|
||||
#define LOWPAN_CONTEXT_MAX 16
|
||||
|
||||
#define LOWPAN_REAS_BUF_TIMEOUT 60
|
||||
|
||||
#include "transceiver.h"
|
||||
#include "sixlowip.h"
|
||||
#include <vtimer.h>
|
||||
#include <mutex.h>
|
||||
#include <time.h>
|
||||
|
||||
extern mutex_t lowpan_context_mutex;
|
||||
|
||||
typedef struct lowpan_context_t {
|
||||
uint8_t num;
|
||||
ipv6_addr_t prefix;
|
||||
uint8_t length;
|
||||
uint8_t comp;
|
||||
uint16_t lifetime;
|
||||
} lowpan_context_t;
|
||||
|
||||
typedef struct lowpan_interval_list_t {
|
||||
uint8_t start;
|
||||
uint8_t end;
|
||||
struct lowpan_interval_list_t *next;
|
||||
} lowpan_interval_list_t;
|
||||
|
||||
typedef struct lowpan_reas_buf_t {
|
||||
ieee_802154_long_t s_laddr; // Source Address
|
||||
ieee_802154_long_t d_laddr; // Destination Address
|
||||
uint16_t ident_no; // Identification Number
|
||||
time_t timestamp; // Timestamp of last packet fragment
|
||||
uint8_t packet_size; // Size of reassembled packet with possible IPHC header
|
||||
uint8_t current_packet_size; // Additive size of currently already received fragments
|
||||
uint8_t *packet; // Pointer to allocated memory for reassembled packet + 6LoWPAN Dispatch Byte
|
||||
lowpan_interval_list_t *interval_list_head; // Pointer to list of intervals of received packet fragments (if any)
|
||||
struct lowpan_reas_buf_t *next; // Pointer to next reassembly buffer (if any)
|
||||
} lowpan_reas_buf_t;
|
||||
|
||||
extern lowpan_reas_buf_t *head;
|
||||
|
||||
void sixlowpan_init(transceiver_type_t trans, uint8_t r_addr, int as_border);
|
||||
void sixlowpan_adhoc_init(transceiver_type_t trans, ipv6_addr_t *prefix, uint8_t r_addr);
|
||||
void lowpan_init(ieee_802154_long_t *addr, uint8_t *data);
|
||||
void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr,
|
||||
ieee_802154_long_t *d_laddr);
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra);
|
||||
void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
|
||||
ieee_802154_long_t *s_laddr,
|
||||
ieee_802154_long_t *d_laddr);
|
||||
uint8_t lowpan_context_len();
|
||||
lowpan_context_t * lowpan_context_update(
|
||||
uint8_t num, const ipv6_addr_t *prefix,
|
||||
uint8_t length, uint8_t comp,
|
||||
uint16_t lifetime);
|
||||
lowpan_context_t * lowpan_context_get();
|
||||
lowpan_context_t * lowpan_context_lookup(ipv6_addr_t *addr);
|
||||
lowpan_context_t * lowpan_context_num_lookup(uint8_t num);
|
||||
void lowpan_ipv6_set_dispatch(uint8_t *data);
|
||||
void init_reas_bufs(lowpan_reas_buf_t *buf);
|
||||
void printReasBuffers(void);
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user