diff --git a/projects/tlayer/main.c b/projects/tlayer/main.c index 15d88df6dc..885557ab02 100644 --- a/projects/tlayer/main.c +++ b/projects/tlayer/main.c @@ -228,7 +228,7 @@ void send_tcp_thread (void) { printf("Could not send %s!\n", current_message.tcp_string_msg); } - printf("Finished sending!\n"); +// printf("Finished sending!\n"); msg_reply(&recv_msg, &send_msg); } } diff --git a/sys/net/destiny/destiny.h b/sys/net/destiny/destiny.h index 7a793e488c..3b42e105e5 100644 --- a/sys/net/destiny/destiny.h +++ b/sys/net/destiny/destiny.h @@ -8,7 +8,7 @@ #ifndef DESTINY_H_ #define DESTINY_H_ -#define TCP_HC +//#define TCP_HC void init_transport_layer(void); diff --git a/sys/net/destiny/socket.c b/sys/net/destiny/socket.c index b2a7201e73..f667d4eb02 100644 --- a/sys/net/destiny/socket.c +++ b/sys/net/destiny/socket.c @@ -396,8 +396,9 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, i { socket_t *current_tcp_socket = ¤t_socket->socket_values; uint8_t header_length = TCP_HDR_LEN/4; - if (IS_TCP_SYN(current_tcp_packet->reserved_flags) || IS_TCP_SYN_ACK(current_tcp_packet->reserved_flags)) + if (IS_TCP_SYN(flags) || IS_TCP_SYN_ACK(flags)) { + printf("Sending with MSS Option! flags: %u\n", flags); tcp_mss_option_t current_mss_option; header_length += sizeof(tcp_mss_option_t)/4; @@ -422,6 +423,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, i uint16_t compressed_size; compressed_size = compress_tcp_packet(current_socket, (uint8_t *) current_tcp_packet, temp_ipv6_header, flags, payload_length); +// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+compressed_size, "Outgoing2"); if (compressed_size == 0) { // Error in compressing tcp packet header @@ -611,7 +613,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags) while (recv_msg.type != TCP_ACK) { // Add packet data - printf("Send Window: %u, MSS: %u\n", current_tcp_socket->tcp_control.send_wnd, current_tcp_socket->tcp_control.mss); +// printf("Send Window: %u, MSS: %u\n", current_tcp_socket->tcp_control.send_wnd, current_tcp_socket->tcp_control.mss); if (current_tcp_socket->tcp_control.send_wnd > current_tcp_socket->tcp_control.mss) { // Window size > Maximum Segment Size @@ -648,7 +650,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags) current_tcp_socket->tcp_control.send_nxt += sent_bytes; current_tcp_socket->tcp_control.send_wnd -= sent_bytes; - printf("Sent bytes: %li\n", sent_bytes); +// printf("Sent bytes: %li\n", sent_bytes); if (send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, 0, sent_bytes) != 1) { // Error while sending tcp data @@ -665,13 +667,13 @@ int32_t send(int s, void *msg, uint64_t len, int flags) // Remember current time current_tcp_socket->tcp_control.last_packet_time = vtimer_now(); - printf("Waiting for Message in send()!\n"); +// printf("Waiting for Message in send()!\n"); net_msg_receive(&recv_msg); switch (recv_msg.type) { case TCP_ACK: { - printf("Got ACK in send()!\n"); +// printf("Got ACK in send()!\n"); tcp_hdr_t *tcp_header = ((tcp_hdr_t*)(recv_msg.content.ptr)); if ((current_tcp_socket->tcp_control.send_nxt == tcp_header->ack_nr) && (total_sent_bytes == len)) { @@ -679,7 +681,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags) 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("Everything sent, returning!\n"); +// printf("Everything sent, returning!\n"); #ifdef TCP_HC current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; #endif diff --git a/sys/net/destiny/socket.h b/sys/net/destiny/socket.h index d1b1f8d2b3..677d19d5ac 100644 --- a/sys/net/destiny/socket.h +++ b/sys/net/destiny/socket.h @@ -14,7 +14,7 @@ #include "in.h" #include "sys/net/sixlowpan/sixlowip.h" -#define TCP_HC +//#define TCP_HC /* * Types diff --git a/sys/net/destiny/tcp.c b/sys/net/destiny/tcp.c index ddca23aada..94d2f2aace 100644 --- a/sys/net/destiny/tcp.c +++ b/sys/net/destiny/tcp.c @@ -123,7 +123,7 @@ void handle_tcp_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socke { if (check_tcp_consistency(&tcp_socket->socket_values, tcp_header) == PACKET_OK) { - printf("Packet consistency OK!\n"); +// printf("Packet consistency OK!\n"); m_send_tcp.content.ptr = (char*)tcp_header; net_msg_send(&m_send_tcp, tcp_socket->send_pid, 0, TCP_ACK); return; @@ -232,9 +232,7 @@ void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, if (tcp_payload_len > 0) { -#ifdef TCP_HC - current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; -#endif + if (check_tcp_consistency(current_tcp_socket, tcp_header) == PACKET_OK) { read_bytes = handle_payload(ipv6_header, tcp_header, tcp_socket, payload); @@ -248,14 +246,21 @@ void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, current_tcp_socket->tcp_control.send_nxt, current_tcp_socket->tcp_control.send_una, current_tcp_socket->tcp_control.send_wnd); + // Send packet block_continue_thread(); +#ifdef TCP_HC + current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER; +#endif send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0); } // ACK packet probably got lost else { block_continue_thread(); +#ifdef TCP_HC + current_tcp_socket->tcp_control.tcp_context.hc_type = MOSTLY_COMPRESSED_HEADER; +#endif send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0); } } @@ -276,7 +281,7 @@ void tcp_packet_handler (void) ipv6_header = ((ipv6_hdr_t*)m_recv_ip.content.ptr); tcp_header = ((tcp_hdr_t*)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); - printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN+ipv6_header->length, "Incoming"); +// printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN+ipv6_header->length, "Incoming"); #ifdef TCP_HC tcp_socket = decompress_tcp_packet(ipv6_header); #else @@ -288,7 +293,7 @@ void tcp_packet_handler (void) payload = (uint8_t*)(m_recv_ip.content.ptr + IPV6_HDR_LEN + tcp_header->dataOffset_reserved*4); - print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values); +// print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values); if ((chksum == 0xffff) && (tcp_socket != NULL)) { @@ -351,7 +356,7 @@ void tcp_packet_handler (void) { printf("Wrong checksum (%x) or no corresponding socket found!\n", chksum); // printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN+ipv6_header->length, "Incoming"); -// print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values); + print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values); } msg_reply(&m_recv_ip, &m_send_ip); diff --git a/sys/net/destiny/tcp.h b/sys/net/destiny/tcp.h index 9afad78089..ef1e6e3ef8 100644 --- a/sys/net/destiny/tcp.h +++ b/sys/net/destiny/tcp.h @@ -8,7 +8,7 @@ #ifndef TCP_H_ #define TCP_H_ -#define TCP_HC +//#define TCP_HC #define TCP_HDR_LEN 20 @@ -57,12 +57,12 @@ enum tcp_codes #define REMOVE_RESERVED 0xFC -#define IS_TCP_ACK(a) ((a & TCP_ACK) > 0) // Test for ACK flag only, ignore URG und PSH flag -#define IS_TCP_RST(a) ((a & TCP_RST) > 0) -#define IS_TCP_SYN(a) ((a & TCP_SYN) > 0) -#define IS_TCP_SYN_ACK(a) ((a & TCP_SYN_ACK) > 0) -#define IS_TCP_FIN(a) ((a & TCP_FIN) > 0) -#define IS_TCP_FIN_ACK(a) ((a & TCP_FIN_ACK) > 0) +#define IS_TCP_ACK(a) ((a & TCP_ACK) == TCP_ACK) // Test for ACK flag only, ignore URG und PSH flag +#define IS_TCP_RST(a) ((a & TCP_RST) == TCP_RST) +#define IS_TCP_SYN(a) ((a & TCP_SYN) == TCP_SYN) +#define IS_TCP_SYN_ACK(a) ((a & TCP_SYN_ACK) == TCP_SYN_ACK) +#define IS_TCP_FIN(a) ((a & TCP_FIN) == TCP_FIN) +#define IS_TCP_FIN_ACK(a) ((a & TCP_FIN_ACK) == TCP_FIN_ACK) #define SET_TCP_ACK(a) a = ((a & 0x00) | TCP_ACK) #define SET_TCP_RST(a) a = ((a & 0x00) | TCP_RST) diff --git a/sys/net/destiny/tcp_hc.c b/sys/net/destiny/tcp_hc.c index bf7f845e8f..dee67df658 100644 --- a/sys/net/destiny/tcp_hc.c +++ b/sys/net/destiny/tcp_hc.c @@ -58,7 +58,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current tcp_cb_t *tcp_cb = ¤t_tcp_socket->tcp_control; tcp_hdr_t full_tcp_header; uint16_t packet_size = 0; - +// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Outgoing"); // Connection establisment phase, use FULL_HEADER TCP if (tcp_cb->state != ESTABLISHED) { @@ -80,10 +80,11 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current // Update the tcp context fields update_tcp_hc_context(false, current_socket, (tcp_hdr_t *)(current_tcp_packet+3)); - print_tcp_status(OUT_PACKET, temp_ipv6_header, (tcp_hdr_t *)(current_tcp_packet+3), current_tcp_socket); +// print_tcp_status(OUT_PACKET, temp_ipv6_header, (tcp_hdr_t *)(current_tcp_packet+3), current_tcp_socket); // Convert TCP packet to network byte order switch_tcp_packet_byte_order((tcp_hdr_t *)(current_tcp_packet+3)); +// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Outgoing1"); return packet_size; } @@ -275,7 +276,10 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current packet_size += payload_length; update_tcp_hc_context(false, current_socket, &full_tcp_header); - print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket); +// print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket); + +// printf("packet Size2: %u\n", packet_size); + return packet_size; } // Check for header compression type: MOSTLY_COMPRESSED_HEADER @@ -369,10 +373,11 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current // Adding TCP payload length to TCP_HC header length packet_size += payload_length; - printf("TCP Payload length: %u\n", payload_length); +// printf("packet Size2: %u\n", packet_size); update_tcp_hc_context(false, current_socket, &full_tcp_header); - print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket); +// print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket); +// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Outgoing3"); return packet_size; } return 0; @@ -384,7 +389,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header) uint16_t tcp_hc_header; socket_internal_t *current_socket = NULL; uint16_t packet_size = 0; - +// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Incoming"); // Full header TCP segment if (*(((uint8_t *)temp_ipv6_header)+IPV6_HDR_LEN) == 0x01) { @@ -599,7 +604,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header) // Set IPV6 header length temp_ipv6_header->length = temp_ipv6_header->length - packet_size + TCP_HDR_LEN; - +// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Incoming"); return current_socket; } } diff --git a/sys/net/destiny/tcp_hc.h b/sys/net/destiny/tcp_hc.h index 33eabe8d84..52f7fb2003 100644 --- a/sys/net/destiny/tcp_hc.h +++ b/sys/net/destiny/tcp_hc.h @@ -8,7 +8,7 @@ #ifndef TCP_HC_H_ #define TCP_HC_H_ -#define TCP_HC +//#define TCP_HC #include "tcp.h" #include "sys/net/sixlowpan/sixlowip.h" diff --git a/sys/net/destiny/tcp_timer.c b/sys/net/destiny/tcp_timer.c index 0a0699dec6..f977ef376d 100644 --- a/sys/net/destiny/tcp_timer.c +++ b/sys/net/destiny/tcp_timer.c @@ -48,7 +48,8 @@ void handle_established(socket_internal_t *current_socket) msg_t send; uint32_t current_timeout = TCP_ACK_TIMEOUT; uint8_t i; - if (current_socket->socket_values.tcp_control.send_nxt > current_socket->socket_values.tcp_control.send_una) + if ((current_socket->socket_values.tcp_control.send_nxt > current_socket->socket_values.tcp_control.send_una) && + (thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED)) { for(i = 0; i < current_socket->socket_values.tcp_control.no_of_retry; i++) { @@ -64,7 +65,10 @@ void handle_established(socket_internal_t *current_socket) { current_socket->socket_values.tcp_control.no_of_retry++; net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY); - printf("GOT NO ACK YET, %i. RETRY!\n", current_socket->socket_values.tcp_control.no_of_retry); + printf("GOT NO ACK YET, %i. RETRY! Now: %lu Before: %lu, Diff: %lu, Cur Timeout: %lu\n", current_socket->socket_values.tcp_control.no_of_retry, + vtimer_now().microseconds, current_socket->socket_values.tcp_control.last_packet_time.microseconds, + vtimer_now().microseconds - current_socket->socket_values.tcp_control.last_packet_time.microseconds, + current_timeout); } } } diff --git a/sys/net/net_help/net_help.c b/sys/net/net_help/net_help.c index 5666d6e90d..5d008e0eb9 100644 --- a/sys/net/net_help/net_help.c +++ b/sys/net/net_help/net_help.c @@ -19,7 +19,7 @@ void printArrayRange(uint8_t *array, uint16_t len, char *str) { printf("%#x ", *(array+i)); } - printf("\n--------------------------\n"); + printf("\n-----------%u-------------\n", len); } uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len)