UDP bug fixes: after using TCP connection, socket was not deleted

properly
This commit is contained in:
Oliver 2011-11-01 21:04:28 +01:00
parent fecb514293
commit c1b2b10a06
9 changed files with 85 additions and 107 deletions

View File

@ -34,7 +34,7 @@ char tcp_server_stack_buffer[TCP_STACK_SIZE];
uint8_t tcp_cht_pid; uint8_t tcp_cht_pid;
char tcp_cht_stack_buffer[TCP_STACK_SIZE]; char tcp_cht_stack_buffer[TCP_STACK_SIZE];
typedef struct tcp_message_t typedef struct tcp_msg_t
{ {
int node_number; int node_number;
char tcp_string_msg[50]; char tcp_string_msg[50];
@ -49,42 +49,42 @@ void init_tl (char *str)
void tcp_ch(void) void tcp_ch(void)
{ {
msg_t recv_msg; msg_t recv_msg;
struct sockaddr6 stSockAddr; sockaddr6 stSockAddr;
msg_receive(&recv_msg); while (1)
int SocketFD = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
if (-1 == SocketFD)
{ {
printf("cannot create socket"); msg_receive(&recv_msg);
}
memset(&stSockAddr, 0, sizeof(stSockAddr)); int SocketFD = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
if (-1 == SocketFD)
{
printf("cannot create socket");
}
memset(&stSockAddr, 0, sizeof(stSockAddr));
stSockAddr.sin6_family = AF_INET6;
stSockAddr.sin6_port = HTONS(1100);
ipv6_init_address(&stSockAddr.sin6_addr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00, current_message.node_number);
ipv6_print_addr(&stSockAddr.sin6_addr);
if (-1 == connect(SocketFD, &stSockAddr, sizeof(stSockAddr), tcp_cht_pid))
{
printf("connect failed");
close(SocketFD);
}
/* perform read write operations ... */
stSockAddr.sin6_family = AF_INET6;
// TODO: use HTONS and NTOHL, here as well as in socket, udp and tcp api
stSockAddr.sin6_port = HTONS(1100);
// printf("SIN 6 PORT: %i %i\n", stSockAddr.sin6_port, NTOHS(stSockAddr.sin6_port));
printf("Sending %s to node %i!\n", current_message.tcp_string_msg, current_message.node_number);
ipv6_init_address(&stSockAddr.sin6_addr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00, current_message.node_number);
ipv6_print_addr(&stSockAddr.sin6_addr);
if (-1 == connect(SocketFD, &stSockAddr, sizeof(stSockAddr), tcp_cht_pid))
{
printf("connect failed");
close(SocketFD); close(SocketFD);
} }
/* perform read write operations ... */
close(SocketFD);
} }
void init_udp_server(void) void init_udp_server(void)
{ {
struct sockaddr6 sa; sockaddr6 sa;
char buffer_main[256]; char buffer_main[256];
ssize_t recsize; ssize_t recsize;
uint32_t fromlen; uint32_t fromlen;
@ -113,7 +113,7 @@ void init_udp_server(void)
void init_tcp_server(void) void init_tcp_server(void)
{ {
struct sockaddr6 stSockAddr; sockaddr6 stSockAddr;
int SocketFD = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); int SocketFD = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
if(-1 == SocketFD) if(-1 == SocketFD)
@ -272,8 +272,8 @@ void send_packet(char *str){
uint8_t text[20]; uint8_t text[20];
sscanf(str, "send %s", text); sscanf(str, "send %s", text);
struct ipv6_hdr_t *test_ipv6_header = ((struct ipv6_hdr_t*)(&send_buffer)); ipv6_hdr_t *test_ipv6_header = ((ipv6_hdr_t*)(&send_buffer));
struct udp_hdr_t *test_udp_header = ((struct udp_hdr_t*)(&send_buffer[IPV6_HDR_LEN])); udp_hdr_t *test_udp_header = ((udp_hdr_t*)(&send_buffer[IPV6_HDR_LEN]));
uint8_t *payload = &send_buffer[IPV6_HDR_LEN+UDP_HDR_LEN]; uint8_t *payload = &send_buffer[IPV6_HDR_LEN+UDP_HDR_LEN];
ipv6_addr_t ipaddr; ipv6_addr_t ipaddr;
@ -305,7 +305,7 @@ void send_packet(char *str){
void send_udp(char *str) void send_udp(char *str)
{ {
int sock; int sock;
struct sockaddr6 sa; sockaddr6 sa;
ipv6_addr_t ipaddr; ipv6_addr_t ipaddr;
int bytes_sent; int bytes_sent;
int address; int address;

View File

@ -45,14 +45,29 @@ void print_socket(uint8_t socket)
current_socket->foreign_tcp_status.state); current_socket->foreign_tcp_status.state);
} }
socket_internal_t *getSocket(uint8_t s)
{
if (exists_socket(s))
{
return &(sockets[s-1]);
}
else
{
return NULL;
}
}
void print_sockets(void) void print_sockets(void)
{ {
int i; int i;
printf("\n--- Socket list: ---\n"); printf("\n--- Socket list: ---\n");
for (i = 1; i < MAX_SOCKETS+1; i++) for (i = 1; i < MAX_SOCKETS+1; i++)
{ {
print_socket(i); if(getSocket(i) != NULL)
printf("\n----------------------------------------------------------------\n"); {
print_socket(i);
printf("\n----------------------------------------------------------------\n");
}
} }
} }
@ -68,14 +83,6 @@ bool exists_socket(uint8_t socket)
} }
} }
socket_internal_t* getSocket(uint8_t s)
{
if (exists_socket(s))
return &sockets[s-1];
else
return NULL;
}
void close_socket(socket_t *current_socket) void close_socket(socket_t *current_socket)
{ {
memset(current_socket, 0, sizeof(current_socket)); memset(current_socket, 0, sizeof(current_socket));
@ -105,7 +112,7 @@ bool isTCPSocket(uint8_t s)
return false; return false;
} }
int bind_udp_socket(int s, struct sockaddr6 *name, int namelen, uint8_t pid) int bind_udp_socket(int s, sockaddr6 *name, int namelen, uint8_t pid)
{ {
int i; int i;
if (!exists_socket(s)) if (!exists_socket(s))
@ -124,7 +131,7 @@ int bind_udp_socket(int s, struct sockaddr6 *name, int namelen, uint8_t pid)
return 1; return 1;
} }
int bind_tcp_socket(int s, struct sockaddr6 *name, int namelen, uint8_t pid) int bind_tcp_socket(int s, sockaddr6 *name, int namelen, uint8_t pid)
{ {
int i; int i;
if (!exists_socket(s)) if (!exists_socket(s))
@ -156,7 +163,7 @@ int socket(int domain, int type, int protocol)
} }
else else
{ {
struct socket_t *current_socket = &sockets[i-1].in_socket; socket_t *current_socket = &sockets[i-1].in_socket;
sockets[i-1].socket_id = i; sockets[i-1].socket_id = i;
current_socket->domain = domain; current_socket->domain = domain;
current_socket->type = type; current_socket->type = type;
@ -233,9 +240,8 @@ uint16_t get_free_source_port(uint8_t protocol)
return biggest_port + 1; return biggest_port + 1;
} }
int connect(int socket, struct sockaddr6 *addr, uint32_t addrlen, uint8_t tcp_client_thread) int connect(int socket, sockaddr6 *addr, uint32_t addrlen, uint8_t tcp_client_thread)
{ {
printf("------ PORT: %i\n", NTOHS(addr->sin6_port));
// Variables // Variables
socket_t *current_tcp_socket; socket_t *current_tcp_socket;
msg_t msg_from_server, msg_reply_fin; msg_t msg_from_server, msg_reply_fin;
@ -306,10 +312,9 @@ int connect(int socket, struct sockaddr6 *addr, uint32_t addrlen, uint8_t tcp_cl
// wait for SYN ACK // wait for SYN ACK
msg_receive(&msg_from_server); msg_receive(&msg_from_server);
printf("--4--\n");
// Read packet content // Read packet content
tcp_hdr_t *tcp_header = ((struct tcp_hdr_t*)(msg_from_server.content.ptr+IPV6_HDR_LEN)); tcp_hdr_t *tcp_header = ((tcp_hdr_t*)(msg_from_server.content.ptr+IPV6_HDR_LEN));
// Got SYN ACK from Server // Got SYN ACK from Server
// Refresh foreign TCP socket information // Refresh foreign TCP socket information
@ -354,19 +359,19 @@ int32_t recv(int s, void *buf, uint64_t len, int flags)
return -1; return -1;
} }
int32_t recvfrom(int s, void *buf, uint64_t len, int flags, struct sockaddr6 *from, uint32_t *fromlen) int32_t recvfrom(int s, void *buf, uint64_t len, int flags, sockaddr6 *from, uint32_t *fromlen)
{ {
if (isUDPSocket(s)) if (isUDPSocket(s))
{ {
msg_t m_recv, m_send; msg_t m_recv, m_send;
struct ipv6_hdr_t *ipv6_header; ipv6_hdr_t *ipv6_header;
struct udp_hdr_t *udp_header; udp_hdr_t *udp_header;
uint8_t *payload; uint8_t *payload;
uint16_t payload_size = 0; uint16_t payload_size = 0;
msg_receive(&m_recv); msg_receive(&m_recv);
ipv6_header = ((struct ipv6_hdr_t*)&buffer_udp); ipv6_header = ((ipv6_hdr_t*)&buffer_udp);
udp_header = ((struct udp_hdr_t*)(&buffer_udp[IPV6_HDR_LEN])); udp_header = ((udp_hdr_t*)(&buffer_udp[IPV6_HDR_LEN]));
payload = &buffer_udp[IPV6_HDR_LEN+UDP_HDR_LEN]; payload = &buffer_udp[IPV6_HDR_LEN+UDP_HDR_LEN];
memset(buf, 0, len); memset(buf, 0, len);
@ -391,15 +396,14 @@ int32_t recvfrom(int s, void *buf, uint64_t len, int flags, struct sockaddr6 *fr
} }
} }
int32_t sendto(int s, void *msg, uint64_t len, int flags, struct sockaddr6 *to, uint32_t tolen) int32_t sendto(int s, void *msg, uint64_t len, int flags, sockaddr6 *to, uint32_t tolen)
{ {
printf("UDP SENDING, socket ID: %i, isUDPSOCKET: %i, sin6_port is 0: %i\n", getSocket(s)->socket_id, isUDPSocket(s), (getSocket(s)->in_socket.foreign_address.sin6_port == 0));
if (isUDPSocket(s) && (getSocket(s)->in_socket.foreign_address.sin6_port == 0)) if (isUDPSocket(s) && (getSocket(s)->in_socket.foreign_address.sin6_port == 0))
{ {
uint8_t send_buffer[BUFFER_SIZE]; uint8_t send_buffer[BUFFER_SIZE];
struct ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t*)(&send_buffer)); ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t*)(&send_buffer));
struct udp_hdr_t *current_udp_packet = ((udp_hdr_t*)(&send_buffer[IPV6_HDR_LEN])); 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]; uint8_t *payload = &send_buffer[IPV6_HDR_LEN+UDP_HDR_LEN];
ipv6_print_addr(&to->sin6_addr); ipv6_print_addr(&to->sin6_addr);
@ -435,7 +439,7 @@ int close(int s)
if (current_socket != NULL) if (current_socket != NULL)
{ {
// TODO: Kill connection, not just delete socket! // TODO: Kill connection, not just delete socket!
memset(current_socket, 0, sizeof(current_socket)); memset(current_socket, 0, sizeof(socket_internal_t));
return 1; return 1;
} }
@ -445,7 +449,7 @@ int close(int s)
} }
} }
int bind(int s, struct sockaddr6 *name, int namelen, uint8_t pid) int bind(int s, sockaddr6 *name, int namelen, uint8_t pid)
{ {
if (exists_socket(s)) if (exists_socket(s))
{ {
@ -569,12 +573,9 @@ int handle_new_tcp_connection(socket_t *current_queued_socket, socket_internal_t
// Fill SYN ACK TCP packet, still use queued socket for port number until connection is completely established! // Fill SYN ACK TCP packet, still use queued socket for port number until connection is completely established!
// Otherwise the program doesnt return to this function and instead trys to call the new registered thread // Otherwise the program doesnt return to this function and instead trys to call the new registered thread
// which isnt prepared to complete the threeway handshake process! // which isnt prepared to complete the threeway handshake process!
// printf("Queued Socket, foreign source port: %i\n", current_queued_socket->foreign_address.sin6_port);
syn_ack_packet->ack_nr = current_queued_socket->local_tcp_status.seq_nr; syn_ack_packet->ack_nr = current_queued_socket->local_tcp_status.seq_nr;
syn_ack_packet->dataOffset_reserved = 0; syn_ack_packet->dataOffset_reserved = 0;
syn_ack_packet->dst_port = current_queued_socket->foreign_address.sin6_port; syn_ack_packet->dst_port = current_queued_socket->foreign_address.sin6_port;
// printf("FOreign Address!\n");
// ipv6_print_addr(&current_queued_socket->foreign_address.sin6_addr);
SET_TCP_SYN_ACK(syn_ack_packet->reserved_flags); SET_TCP_SYN_ACK(syn_ack_packet->reserved_flags);
syn_ack_packet->seq_nr = current_queued_socket->local_tcp_status.seq_nr; syn_ack_packet->seq_nr = current_queued_socket->local_tcp_status.seq_nr;
syn_ack_packet->src_port = server_socket->in_socket.local_address.sin6_port; syn_ack_packet->src_port = server_socket->in_socket.local_address.sin6_port;
@ -609,16 +610,15 @@ int handle_new_tcp_connection(socket_t *current_queued_socket, socket_internal_t
msg_reply(&msg_recv_client_ack, &msg_send_client_ack); msg_reply(&msg_recv_client_ack, &msg_send_client_ack);
new_socket = socket(current_queued_socket->domain, current_queued_socket->type, current_queued_socket->protocol); new_socket = socket(current_queued_socket->domain, current_queued_socket->type, current_queued_socket->protocol);
printf("new Socket Data: ID: %i, Domain: %i, Type: %i, Protocol: %i\n", new_socket, current_queued_socket->domain, current_queued_socket->type, current_queued_socket->protocol);
current_new_socket = getSocket(new_socket); current_new_socket = getSocket(new_socket);
current_new_socket->pid = pid; current_new_socket->pid = pid;
memcpy(&current_new_socket->in_socket, &current_queued_socket, sizeof(current_queued_socket)); memcpy(&current_new_socket->in_socket, &current_queued_socket, sizeof(socket_t));
close_socket(current_queued_socket); close_socket(current_queued_socket);
return new_socket; return new_socket;
} }
int accept(int s, struct sockaddr6 *addr, uint32_t addrlen, uint8_t pid) int accept(int s, sockaddr6 *addr, uint32_t addrlen, uint8_t pid)
{ {
socket_internal_t *server_socket = getSocket(s); socket_internal_t *server_socket = getSocket(s);
if (isTCPSocket(s) && (server_socket->in_socket.local_tcp_status.state == LISTEN)) if (isTCPSocket(s) && (server_socket->in_socket.local_tcp_status.state == LISTEN))
@ -673,21 +673,12 @@ socket_t *new_tcp_queued_socket(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
current_queued_socket->protocol = IPPROTO_TCP; current_queued_socket->protocol = IPPROTO_TCP;
// Foreign address // Foreign address
memcpy(&current_queued_socket->foreign_address.sin6_addr, (void*) &ipv6_header->srcaddr, sizeof(ipv6_header->srcaddr)); memcpy(&current_queued_socket->foreign_address.sin6_addr, (void*) &ipv6_header->srcaddr, sizeof(ipv6_addr_t));
// printf("Foreign Addr1: ");
// ipv6_print_addr(&ipv6_header->srcaddr);
// printf("Foreign Addr2: ");
// ipv6_print_addr(&current_queued_socket->foreign_address.sin6_addr);
current_queued_socket->foreign_address.sin6_family = AF_INET6; current_queued_socket->foreign_address.sin6_family = AF_INET6;
current_queued_socket->foreign_address.sin6_flowinfo = ipv6_header->flowlabel; current_queued_socket->foreign_address.sin6_flowinfo = ipv6_header->flowlabel;
current_queued_socket->foreign_address.sin6_port = tcp_header->src_port; current_queued_socket->foreign_address.sin6_port = tcp_header->src_port;
// printf("Source Port Foreign: %i\n", current_queued_socket->foreign_address.sin6_port);
// Local address // Local address
memcpy(&current_queued_socket->local_address.sin6_addr, (void*) &ipv6_header->destaddr, sizeof(ipv6_header->destaddr)); memcpy(&current_queued_socket->local_address.sin6_addr, (void*) &ipv6_header->destaddr, sizeof(ipv6_addr_t));
// printf("Local Addr1: ");
// ipv6_print_addr(&ipv6_header->destaddr);
// printf("Local Addr2: ");
// ipv6_print_addr(&current_queued_socket->local_address.sin6_addr);
current_queued_socket->local_address.sin6_family = AF_INET6; current_queued_socket->local_address.sin6_family = AF_INET6;
current_queued_socket->local_address.sin6_flowinfo = 0; current_queued_socket->local_address.sin6_flowinfo = 0;
current_queued_socket->local_address.sin6_port = tcp_header->dst_port; current_queued_socket->local_address.sin6_port = tcp_header->dst_port;

View File

@ -110,7 +110,7 @@
#define EPHEMERAL_PORTS 49152 #define EPHEMERAL_PORTS 49152
typedef struct __attribute__ ((packed)) sockaddr6 typedef struct __attribute__ ((packed)) socka6
{ {
uint8_t sin6_family; /* AF_INET6 */ uint8_t sin6_family; /* AF_INET6 */
uint16_t sin6_port; /* transport layer port # */ uint16_t sin6_port; /* transport layer port # */
@ -118,7 +118,7 @@ typedef struct __attribute__ ((packed)) sockaddr6
ipv6_addr_t sin6_addr; /* IPv6 address */ ipv6_addr_t sin6_addr; /* IPv6 address */
} sockaddr6; } sockaddr6;
typedef struct __attribute__ ((packed)) socket_t typedef struct __attribute__ ((packed)) sock_t
{ {
uint8_t domain; uint8_t domain;
uint8_t type; uint8_t type;
@ -129,7 +129,7 @@ typedef struct __attribute__ ((packed)) socket_t
sockaddr6 foreign_address; sockaddr6 foreign_address;
} socket_t; } socket_t;
typedef struct __attribute__ ((packed)) socket_internal_t typedef struct __attribute__ ((packed)) socket_in_t
{ {
uint8_t socket_id; uint8_t socket_id;
uint8_t pid; uint8_t pid;
@ -140,16 +140,16 @@ typedef struct __attribute__ ((packed)) socket_internal_t
socket_internal_t sockets[MAX_SOCKETS]; socket_internal_t sockets[MAX_SOCKETS];
int socket(int domain, int type, int protocol); int socket(int domain, int type, int protocol);
int connect(int socket, struct sockaddr6 *addr, uint32_t addrlen, uint8_t tcp_client_thread); int connect(int socket, sockaddr6 *addr, uint32_t addrlen, uint8_t tcp_client_thread);
socket_t *getWaitingConnectionSocket(int socket); socket_t *getWaitingConnectionSocket(int socket);
int32_t recvfrom( int s, void *buf, uint64_t len, int flags, struct sockaddr6 *from, uint32_t *fromlen ); int32_t recvfrom( int s, void *buf, uint64_t len, int flags, sockaddr6 *from, uint32_t *fromlen );
int32_t sendto( int s, void *msg, uint64_t len, int flags, struct sockaddr6 *to, uint32_t tolen); int32_t sendto( int s, void *msg, uint64_t len, int flags, sockaddr6 *to, uint32_t tolen);
int32_t send(int s, void *msg, uint64_t len, int flags); int32_t send(int s, void *msg, uint64_t len, int flags);
int32_t recv(int s, void *buf, uint64_t len, int flags); int32_t recv(int s, void *buf, uint64_t len, int flags);
int close(int s); int close(int s);
int bind(int s, struct sockaddr6 *name, int namelen, uint8_t pid); int bind(int s, sockaddr6 *name, int namelen, uint8_t pid);
int listen(int s, int backlog); int listen(int s, int backlog);
int accept(int s, struct sockaddr6 *addr, uint32_t addrlen, uint8_t pid); int accept(int s, sockaddr6 *addr, uint32_t addrlen, uint8_t pid);
int shutdown(int s , int how); int shutdown(int s , int how);
void socket_init(void); void socket_init(void);
socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header); socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header);

View File

@ -46,19 +46,16 @@ uint16_t tcp_csum(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header)
uint16_t len = ipv6_header->length; uint16_t len = ipv6_header->length;
sum = len + IPPROTO_TCP; sum = len + IPPROTO_TCP;
printf("1sum: %i len: %i \n", sum, len);
sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t));
printf("2sum: %i \n", sum);
sum = csum(sum, (uint8_t *)tcp_header, len); sum = csum(sum, (uint8_t *)tcp_header, len);
printf("3sum: %i \n", sum);
return (sum == 0) ? 0xffff : HTONS(sum); return (sum == 0) ? 0xffff : HTONS(sum);
} }
void tcp_packet_handler (void) void tcp_packet_handler (void)
{ {
msg_t m_recv_ip, m_send_ip, m_recv_tcp, m_send_tcp; msg_t m_recv_ip, m_send_ip, m_recv_tcp, m_send_tcp;
struct ipv6_hdr_t *ipv6_header; ipv6_hdr_t *ipv6_header;
struct tcp_hdr_t *tcp_header; tcp_hdr_t *tcp_header;
uint8_t *payload; uint8_t *payload;
socket_internal_t *tcp_socket = NULL; socket_internal_t *tcp_socket = NULL;
uint16_t chksum; uint16_t chksum;
@ -66,17 +63,14 @@ void tcp_packet_handler (void)
while (1) while (1)
{ {
msg_receive(&m_recv_ip); msg_receive(&m_recv_ip);
ipv6_header = ((struct ipv6_hdr_t*)&buffer_tcp); ipv6_header = ((ipv6_hdr_t*)&buffer_tcp);
tcp_header = ((struct tcp_hdr_t*)(&buffer_tcp[IPV6_HDR_LEN])); tcp_header = ((tcp_hdr_t*)(&buffer_tcp[IPV6_HDR_LEN]));
payload = &buffer_tcp[IPV6_HDR_LEN+TCP_HDR_LEN]; payload = &buffer_tcp[IPV6_HDR_LEN+TCP_HDR_LEN];
printf("IPv6 Length Field: %i\n", ipv6_header->length);
prinTCPHeader(tcp_header); prinTCPHeader(tcp_header);
//printArrayRange_tcp((uint8_t *) tcp_header, TCP_HDR_LEN);
chksum = tcp_csum(ipv6_header, tcp_header); chksum = tcp_csum(ipv6_header, tcp_header);
printf("Checksum is %x!\n", chksum); printf("Checksum is %x!\n", chksum);
tcp_socket = get_tcp_socket(ipv6_header, tcp_header); tcp_socket = get_tcp_socket(ipv6_header, tcp_header);
printf("TCP_SOCKET: %s\n",((tcp_socket == NULL)?"NULL":"FOUND"));
if ((chksum == 0xffff) && (tcp_socket != NULL)) if ((chksum == 0xffff) && (tcp_socket != NULL))
{ {
@ -111,11 +105,9 @@ void tcp_packet_handler (void)
printf("SYN Bit set!\n"); printf("SYN Bit set!\n");
if (tcp_socket->in_socket.local_tcp_status.state == LISTEN) if (tcp_socket->in_socket.local_tcp_status.state == LISTEN)
{ {
printf("IN1\n");
socket_t *new_socket = new_tcp_queued_socket(ipv6_header, tcp_header, tcp_socket); socket_t *new_socket = new_tcp_queued_socket(ipv6_header, tcp_header, tcp_socket);
if (new_socket != NULL) if (new_socket != NULL)
{ {
printf("IN2\n");
// notify socket function accept(..) that a new connection request has arrived // 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 // 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->pid, 0); msg_send(&m_send_tcp, tcp_socket->pid, 0);
@ -134,14 +126,11 @@ void tcp_packet_handler (void)
case TCP_SYN_ACK: case TCP_SYN_ACK:
{ {
// only SYN and ACK Bit set, complete three way handshake when socket in state SYN_SENT // only SYN and ACK Bit set, complete three way handshake when socket in state SYN_SENT
printf("--1--\n");
if (tcp_socket->in_socket.local_tcp_status.state == SYN_SENT) if (tcp_socket->in_socket.local_tcp_status.state == SYN_SENT)
{ {
printf("--2-- PID: %i\n",tcp_socket->pid);
m_send_tcp.content.ptr = (char*)buffer; m_send_tcp.content.ptr = (char*)buffer;
m_send_tcp.content.value = IPV6_HDR_LEN + ipv6_header->length; m_send_tcp.content.value = IPV6_HDR_LEN + ipv6_header->length;
msg_send_receive(&m_recv_tcp, &m_send_tcp, tcp_socket->pid); msg_send_receive(&m_recv_tcp, &m_send_tcp, tcp_socket->pid);
printf("--3--\n");
} }
else else
{ {

View File

@ -58,7 +58,7 @@ enum tcp_states
#include "sys/net/sixlowpan/sixlowip.h" #include "sys/net/sixlowpan/sixlowip.h"
typedef struct __attribute__ ((packed)) tcp_socket_status_t typedef struct __attribute__ ((packed)) tcp_so_sta_t
{ {
uint32_t ack_nr; uint32_t ack_nr;
uint32_t seq_nr; uint32_t seq_nr;
@ -67,7 +67,7 @@ typedef struct __attribute__ ((packed)) tcp_socket_status_t
uint8_t state; uint8_t state;
} tcp_socket_status_t; } tcp_socket_status_t;
typedef struct __attribute__ ((packed)) tcp_hdr_t typedef struct __attribute__ ((packed)) tcp_h_t
{ {
uint16_t src_port; uint16_t src_port;
uint16_t dst_port; uint16_t dst_port;

View File

@ -35,8 +35,8 @@ uint16_t udp_csum(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header)
void udp_packet_handler(void) void udp_packet_handler(void)
{ {
msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp; msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp;
struct ipv6_hdr_t *ipv6_header; ipv6_hdr_t *ipv6_header;
struct udp_hdr_t *udp_header; udp_hdr_t *udp_header;
uint8_t *payload; uint8_t *payload;
socket_internal_t *udp_socket = NULL; socket_internal_t *udp_socket = NULL;
uint16_t chksum; uint16_t chksum;
@ -45,8 +45,8 @@ void udp_packet_handler(void)
{ {
msg_receive(&m_recv_ip); msg_receive(&m_recv_ip);
printf("Inside UDP handler!\n"); printf("Inside UDP handler!\n");
ipv6_header = ((struct ipv6_hdr_t*)&buffer_udp); ipv6_header = ((ipv6_hdr_t*)&buffer_udp);
udp_header = ((struct udp_hdr_t*)(&buffer_udp[IPV6_HDR_LEN])); udp_header = ((udp_hdr_t*)(&buffer_udp[IPV6_HDR_LEN]));
payload = &buffer_udp[IPV6_HDR_LEN+UDP_HDR_LEN]; payload = &buffer_udp[IPV6_HDR_LEN+UDP_HDR_LEN];
chksum = udp_csum(ipv6_header, udp_header); chksum = udp_csum(ipv6_header, udp_header);

View File

@ -16,7 +16,7 @@
#include "sys/net/sixlowpan/sixlowip.h" #include "sys/net/sixlowpan/sixlowip.h"
typedef struct __attribute__ ((packed)) udp_hdr_t{ typedef struct __attribute__ ((packed)) udp_h_t{
uint16_t src_port; uint16_t src_port;
uint16_t dst_port; uint16_t dst_port;
uint16_t length; uint16_t length;

View File

@ -62,7 +62,6 @@ void serial_reader_f(void) {
while(1) { while(1) {
posix_open(uart0_handler_pid, 0); posix_open(uart0_handler_pid, 0);
bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE); bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE);
printf("GOT PACKET FROM RS232!\n");
if (bytes < 0) { if (bytes < 0) {
switch (bytes) { switch (bytes) {
case (-SIXLOWERROR_ARRAYFULL):{ case (-SIXLOWERROR_ARRAYFULL):{

View File

@ -131,7 +131,6 @@ void ipv6_process(void){
if (tcp_packet_handler_pid != 0) if (tcp_packet_handler_pid != 0)
{ {
printf("IPV6 Header Length: %i\n", ipv6_buf->length);
memcpy(tcp_packet_buffer, (char*) ipv6_buf, IPV6_HDR_LEN+ipv6_buf->length); memcpy(tcp_packet_buffer, (char*) ipv6_buf, IPV6_HDR_LEN+ipv6_buf->length);
msg_send_receive(&m_send, &m_recv, tcp_packet_handler_pid); msg_send_receive(&m_send, &m_recv, tcp_packet_handler_pid);
} }