Index: uspace/srv/net/tl/tcp/tcp.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp.c	(revision ba1a2fdd0b308082b38db21536f17bf80860ec47)
+++ uspace/srv/net/tl/tcp/tcp.c	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
@@ -28,11 +28,15 @@
 
 /** @addtogroup tcp
- *  @{
+ * @{
  */
 
 /** @file
- *  TCP module implementation.
- *  @see tcp.h
+ * TCP module implementation.
+ * @see tcp.h
  */
+
+#include "tcp.h"
+#include "tcp_header.h"
+#include "tcp_module.h"
 
 #include <assert.h>
@@ -72,8 +76,4 @@
 #include <tl_interface.h>
 
-#include "tcp.h"
-#include "tcp_header.h"
-#include "tcp_module.h"
-
 /** TCP module name. */
 #define NAME	"TCP protocol"
@@ -110,10 +110,11 @@
 
 /** Returns a value indicating whether the value is in the interval respecting
- *  the possible overflow.
+ * the possible overflow.
  *
- *  The high end and/or the value may overflow, be lower than the low value.
- *  @param[in] lower The last value before the interval.
- *  @param[in] value The value to be checked.
- *  @param[in] higher_equal The last value in the interval.
+ * The high end and/or the value may overflow, be lower than the low value.
+ *
+ * @param[in] lower	The last value before the interval.
+ * @param[in] value	The value to be checked.
+ * @param[in] higher_equal The last value in the interval.
  */
 #define IS_IN_INTERVAL_OVERFLOW(lower, value, higher_equal) \
@@ -165,86 +166,71 @@
 };
 
-/** Releases the packet and returns the result.
- *  @param[in] packet The packet queue to be released.
- *  @param[in] result The result to be returned.
- *  @return The result parameter.
- */
-int tcp_release_and_return(packet_t packet, int result);
-
-void tcp_prepare_operation_header(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize,
-    int finalize);
-int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t),
-    socket_core_ref socket, tcp_socket_data_ref socket_data,
-    size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout,
-    int globals_read_only);
-void tcp_free_socket_data(socket_core_ref socket);
-
-int tcp_timeout(void *data);
-
-int tcp_release_after_timeout(void *data);
-
-int tcp_process_packet(device_id_t device_id, packet_t packet,
-    services_t error);
-int tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets,
-    struct sockaddr *addr, socklen_t addrlen);
-int tcp_queue_prepare_packet(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, packet_t packet, size_t data_length);
-int tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
-    packet_t packet, size_t data_length);
-packet_t tcp_get_packets_to_send(socket_core_ref socket,
-    tcp_socket_data_ref socket_data);
-void tcp_send_packets(device_id_t device_id, packet_t packet);
-
-void tcp_process_acknowledgement(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, tcp_header_ref header);
-packet_t tcp_send_prepare_packet(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, packet_t packet, size_t data_length,
-    size_t sequence_number);
-packet_t tcp_prepare_copy(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, packet_t packet, size_t data_length,
-    size_t sequence_number);
-void tcp_retransmit_packet(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, size_t sequence_number);
-int tcp_create_notification_packet(packet_t * packet, socket_core_ref socket,
-    tcp_socket_data_ref socket_data, int synchronize, int finalize);
-void tcp_refresh_socket_data(tcp_socket_data_ref socket_data);
-
-void tcp_initialize_socket_data(tcp_socket_data_ref socket_data);
-
-int tcp_process_listen(socket_core_ref listening_socket,
-    tcp_socket_data_ref listening_socket_data, tcp_header_ref header,
-    packet_t packet, struct sockaddr *src, struct sockaddr *dest,
-    size_t addrlen);
-int tcp_process_syn_sent(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet);
-int tcp_process_syn_received(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet);
-int tcp_process_established(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet,
-    int fragments, size_t total_length);
-int tcp_queue_received_packet(socket_core_ref socket,
-    tcp_socket_data_ref socket_data, packet_t packet, int fragments,
-    size_t total_length);
-
-int tcp_received_msg(device_id_t device_id, packet_t packet,
-    services_t receiver, services_t error);
-int tcp_process_client_messages(ipc_callid_t callid, ipc_call_t call);
-
-int tcp_listen_message(socket_cores_ref local_sockets, int socket_id,
-    int backlog);
-int tcp_connect_message(socket_cores_ref local_sockets, int socket_id,
-    struct sockaddr *addr, socklen_t addrlen);
-int tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id,
-    int flags, size_t * addrlen);
-int tcp_send_message(socket_cores_ref local_sockets, int socket_id,
-    int fragments, size_t * data_fragment_size, int flags);
-int tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
-    int new_socket_id, size_t * data_fragment_size, size_t * addrlen);
-int tcp_close_message(socket_cores_ref local_sockets, int socket_id);
+static int tcp_release_and_return(packet_t, int);
+static void tcp_prepare_operation_header(socket_core_ref, tcp_socket_data_ref,
+    tcp_header_ref, int synchronize, int);
+static int tcp_prepare_timeout(int (*)(void *), socket_core_ref,
+    tcp_socket_data_ref, size_t, tcp_socket_state_t, suseconds_t, int);
+static void tcp_free_socket_data(socket_core_ref);
+
+static int tcp_timeout(void *);
+
+static int tcp_release_after_timeout(void *);
+
+static int tcp_process_packet(device_id_t, packet_t, services_t);
+static int tcp_connect_core(socket_core_ref, socket_cores_ref,
+    struct sockaddr *, socklen_t);
+static int tcp_queue_prepare_packet(socket_core_ref, tcp_socket_data_ref,
+    packet_t, size_t);
+static int tcp_queue_packet(socket_core_ref, tcp_socket_data_ref, packet_t,
+    size_t);
+static packet_t tcp_get_packets_to_send(socket_core_ref, tcp_socket_data_ref);
+static void tcp_send_packets(device_id_t, packet_t);
+
+static void tcp_process_acknowledgement(socket_core_ref, tcp_socket_data_ref,
+    tcp_header_ref);
+static packet_t tcp_send_prepare_packet(socket_core_ref, tcp_socket_data_ref,
+    packet_t, size_t, size_t);
+static packet_t tcp_prepare_copy(socket_core_ref, tcp_socket_data_ref, packet_t,
+    size_t, size_t);
+/* static */ void tcp_retransmit_packet(socket_core_ref, tcp_socket_data_ref,
+    size_t);
+static int tcp_create_notification_packet(packet_t *, socket_core_ref,
+    tcp_socket_data_ref, int, int);
+static void tcp_refresh_socket_data(tcp_socket_data_ref);
+
+static void tcp_initialize_socket_data(tcp_socket_data_ref);
+
+static int tcp_process_listen(socket_core_ref, tcp_socket_data_ref,
+    tcp_header_ref, packet_t, struct sockaddr *, struct sockaddr *, size_t);
+static int tcp_process_syn_sent(socket_core_ref, tcp_socket_data_ref,
+    tcp_header_ref, packet_t);
+static int tcp_process_syn_received(socket_core_ref, tcp_socket_data_ref,
+    tcp_header_ref, packet_t);
+static int tcp_process_established(socket_core_ref, tcp_socket_data_ref,
+    tcp_header_ref, packet_t, int, size_t);
+static int tcp_queue_received_packet(socket_core_ref, tcp_socket_data_ref,
+    packet_t, int, size_t);
+
+static int tcp_received_msg(device_id_t, packet_t, services_t, services_t);
+static int tcp_process_client_messages(ipc_callid_t, ipc_call_t);
+
+static int tcp_listen_message(socket_cores_ref, int, int);
+static int tcp_connect_message(socket_cores_ref, int, struct sockaddr *,
+    socklen_t);
+static int tcp_recvfrom_message(socket_cores_ref, int, int, size_t *);
+static int tcp_send_message(socket_cores_ref, int, int, size_t *, int);
+static int tcp_accept_message(socket_cores_ref, int, int, size_t *, size_t *);
+static int tcp_close_message(socket_cores_ref, int);
 
 /** TCP global data. */
 tcp_globals_t tcp_globals;
 
+/** Initializes the TCP module.
+ *
+ * @param[in] client_connection The client connection processing function. The
+ *			module skeleton propagates its own one.
+ * @returns		EOK on success.
+ * @returns		ENOMEM if there is not enough memory left.
+ */
 int tcp_initialize(async_client_conn_t client_connection)
 {
@@ -314,23 +300,20 @@
 	size_t addrlen;
 
-	if (error) {
-		switch (error) {
-		case SERVICE_ICMP:
-			// process error
-			result = icmp_client_process_packet(packet, &type,
-			    &code, NULL, NULL);
-			if (result < 0)
-				return tcp_release_and_return(packet, result);
-
-			length = (size_t) result;
-			if (ERROR_OCCURRED(packet_trim(packet, length, 0))) {
-				return tcp_release_and_return(packet,
-				    ERROR_CODE);
-			}
-			break;
-
-		default:
-			return tcp_release_and_return(packet, ENOTSUP);
-		}
+	switch (error) {
+	case SERVICE_NONE:
+		break;
+	case SERVICE_ICMP:
+		// process error
+		result = icmp_client_process_packet(packet, &type, &code, NULL,
+		    NULL);
+		if (result < 0)
+			return tcp_release_and_return(packet, result);
+
+		length = (size_t) result;
+		if (ERROR_OCCURRED(packet_trim(packet, length, 0)))
+			return tcp_release_and_return(packet, ERROR_CODE);
+		break;
+	default:
+		return tcp_release_and_return(packet, ENOTSUP);
 	}
 
@@ -379,14 +362,14 @@
 		    ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING,
 		    0);
-		if (!socket) {
-			if (tl_prepare_icmp_packet(tcp_globals.net_phone,
-			    tcp_globals.icmp_phone, packet, error) == EOK) {
-				icmp_destination_unreachable_msg(
-				    tcp_globals.icmp_phone, ICMP_PORT_UNREACH,
-				    0, packet);
-			}
-			return EADDRNOTAVAIL;
-		}
-	}
+	}
+	if (!socket) {
+		if (tl_prepare_icmp_packet(tcp_globals.net_phone,
+		    tcp_globals.icmp_phone, packet, error) == EOK) {
+			icmp_destination_unreachable_msg(tcp_globals.icmp_phone,
+			    ICMP_PORT_UNREACH, 0, packet);
+		}
+		return EADDRNOTAVAIL;
+	}
+
 	printf("socket id %d\n", socket->socket_id);
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
@@ -402,5 +385,5 @@
 	total_length = 0;
 	do {
-		++fragments;
+		fragments++;
 		length = packet_get_data_length(next_packet);
 		if (length <= 0)
@@ -421,8 +404,7 @@
 
 	if (error)
-		goto error;
+		goto has_error_service;
 	
 	if (socket_data->state == TCP_SOCKET_LISTEN) {
-
 		if (socket_data->pseudo_header) {
 			free(socket_data->pseudo_header);
@@ -464,5 +446,5 @@
 	}
 
-error:
+has_error_service:
 	fibril_rwlock_read_unlock(&tcp_globals.lock);
 
@@ -507,6 +489,5 @@
 int
 tcp_process_established(socket_core_ref socket, tcp_socket_data_ref socket_data,
-    tcp_header_ref header, packet_t packet, int fragments,
-    size_t total_length)
+    tcp_header_ref header, packet_t packet, int fragments, size_t total_length)
 {
 	ERROR_DECLARE;
@@ -684,7 +665,7 @@
 					continue;
 					// at least partly following data?
-				} else if (IS_IN_INTERVAL_OVERFLOW(
-				    sequence_number, socket_data->next_incoming,
-				    new_sequence_number)) {
+				}
+				if (IS_IN_INTERVAL_OVERFLOW(sequence_number,
+				    socket_data->next_incoming, new_sequence_number)) {
 					if (socket_data->next_incoming <
 					    new_sequence_number) {
@@ -961,5 +942,5 @@
 	listening_socket = socket_port_find(&tcp_globals.sockets,
 	    listening_port, SOCKET_MAP_KEY_LISTENING, 0);
-	if ((!listening_socket) ||
+	if (!listening_socket ||
 	    (listening_socket->socket_id != listening_socket_id)) {
 		fibril_rwlock_write_unlock(&tcp_globals.lock);
@@ -1191,5 +1172,5 @@
 	if (number == socket_data->expected) {
 		// increase the counter
-		++socket_data->expected_count;
+		socket_data->expected_count++;
 		if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) {
 			socket_data->expected_count = 1;
@@ -1200,6 +1181,20 @@
 }
 
-int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call,
-    ipc_call_t * answer, int *answer_count)
+/** Processes the TCP message.
+ *
+ * @param[in] callid	The message identifier.
+ * @param[in] call	The message parameters.
+ * @param[out] answer	The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer in the
+ *			answer parameter.
+ * @returns		EOK on success.
+ * @returns		ENOTSUP if the message is not known.
+ *
+ * @see tcp_interface.h
+ * @see IS_NET_TCP_MESSAGE()
+ */
+int
+tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
 {
 	ERROR_DECLARE;
@@ -1521,5 +1516,5 @@
 	socket = socket_port_find(&tcp_globals.sockets, timeout->port,
 	    timeout->key, timeout->key_length);
-	if (!(socket && (socket->socket_id == timeout->socket_id)))
+	if (!socket || (socket->socket_id != timeout->socket_id))
 		goto out;
 	
@@ -1532,5 +1527,5 @@
 	if (timeout->sequence_number) {
 		// increase the timeout counter;
-		++socket_data->timeout_count;
+		socket_data->timeout_count++;
 		if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) {
 			// TODO release as connection lost
@@ -1744,11 +1739,8 @@
 	    ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data,
 	    0, TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false))) {
-
 		socket_data->addr = NULL;
 		socket_data->addrlen = 0;
 		fibril_rwlock_write_lock(&tcp_globals.lock);
-
 	} else {
-
 		packet = tcp_get_packets_to_send(socket, socket_data);
 		if (packet) {
@@ -1876,5 +1868,5 @@
 		packet = pq_next(packet);
 		// overflow occurred ?
-		if ((!packet) &&
+		if (!packet &&
 		    (socket_data->last_outgoing > socket_data->next_outgoing)) {
 			printf("gpts overflow\n");
@@ -2044,5 +2036,5 @@
 int
 tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
-    size_t * addrlen)
+    size_t *addrlen)
 {
 	ERROR_DECLARE;
@@ -2099,5 +2091,5 @@
 int
 tcp_send_message(socket_cores_ref local_sockets, int socket_id, int fragments,
-    size_t * data_fragment_size, int flags)
+    size_t *data_fragment_size, int flags)
 {
 	ERROR_DECLARE;
@@ -2138,5 +2130,5 @@
 	    packet_dimension->content : socket_data->data_fragment_size);
 
-	for (index = 0; index < fragments; ++index) {
+	for (index = 0; index < fragments; index++) {
 		// read the data fragment
 		result = tl_socket_read_packet_data(tcp_globals.net_phone,
@@ -2235,5 +2227,5 @@
 
 int
-tcp_create_notification_packet(packet_t * packet, socket_core_ref socket,
+tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
     tcp_socket_data_ref socket_data, int synchronize, int finalize)
 {
@@ -2271,5 +2263,5 @@
 int
 tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
-    int new_socket_id, size_t * data_fragment_size, size_t * addrlen)
+    int new_socket_id, size_t *data_fragment_size, size_t *addrlen)
 {
 	ERROR_DECLARE;
@@ -2373,4 +2365,10 @@
 }
 
+/** Releases the packet and returns the result.
+ *
+ * @param[in] packet	The packet queue to be released.
+ * @param[in] result	The result to be returned.
+ * @return		The result parameter.
+ */
 int tcp_release_and_return(packet_t packet, int result)
 {
@@ -2381,6 +2379,6 @@
 /** Default thread for new connections.
  *
- *  @param[in] iid The initial message identifier.
- *  @param[in] icall The initial message call structure.
+ * @param[in] iid	The initial message identifier.
+ * @param[in] icall	The initial message call structure.
  *
  */
@@ -2397,23 +2395,18 @@
 		int answer_count;
 
-		/*
-		   Clear the answer structure 
-		 */
+		/* Clear the answer structure */
 		refresh_answer(&answer, &answer_count);
 
-		/*
-		   Fetch the next message 
-		 */
+		/* Fetch the next message */
 		ipc_call_t call;
 		ipc_callid_t callid = async_get_call(&call);
 
-		/*
-		   Process the message 
-		 */
+		/* Process the message */
 		int res = tl_module_message_standalone(callid, &call, &answer,
 		    &answer_count);
 
 		/*
-		   End if said to either by the message or the processing result 
+		 * End if told to either by the message or the processing
+		 * result.
 		 */
 		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) ||
@@ -2430,10 +2423,7 @@
 /** Starts the module.
  *
- *  @param argc The count of the command line arguments. Ignored parameter.
- *  @param argv The command line parameters. Ignored parameter.
- *
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module start function.
- *
+ * @returns		EOK on success.
+ * @returns		Other error codes as defined for each specific module
+ *			start function.
  */
 int
Index: uspace/srv/net/tl/tcp/tcp.h
===================================================================
--- uspace/srv/net/tl/tcp/tcp.h	(revision ba1a2fdd0b308082b38db21536f17bf80860ec47)
+++ uspace/srv/net/tl/tcp/tcp.h	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
@@ -28,13 +28,13 @@
 
 /** @addtogroup tcp
- *  @{
+ * @{
  */
 
 /** @file
- *  TCP module.
- */
-
-#ifndef __NET_TCP_H__
-#define __NET_TCP_H__
+ * TCP module.
+ */
+
+#ifndef NET_TCP_H_
+#define NET_TCP_H_
 
 #include <fibril_synch.h>
@@ -46,246 +46,271 @@
 
 /** Type definition of the TCP global data.
- *  @see tcp_globals
- */
-typedef struct tcp_globals	tcp_globals_t;
+ * @see tcp_globals
+ */
+typedef struct tcp_globals tcp_globals_t;
 
 /** Type definition of the TCP socket specific data.
- *  @see tcp_socket_data
- */
-typedef struct tcp_socket_data	tcp_socket_data_t;
+ * @see tcp_socket_data
+ */
+typedef struct tcp_socket_data tcp_socket_data_t;
 
 /** Type definition of the TCP socket specific data pointer.
- *  @see tcp_socket_data
- */
-typedef tcp_socket_data_t *	tcp_socket_data_ref;
+ * @see tcp_socket_data
+ */
+typedef tcp_socket_data_t *tcp_socket_data_ref;
 
 /** Type definition of the TCP operation data.
- *  @see tcp_operation
- */
-typedef struct tcp_operation	tcp_operation_t;
+ * @see tcp_operation
+ */
+typedef struct tcp_operation tcp_operation_t;
 
 /** Type definition of the TCP operation data pointer.
- *  @see tcp_operation
- */
-typedef tcp_operation_t *	tcp_operation_ref;
+ * @see tcp_operation
+ */
+typedef tcp_operation_t *tcp_operation_ref;
 
 /** TCP socket state type definition.
- *  @see tcp_socket_state
- */
-typedef enum tcp_socket_state	tcp_socket_state_t;
-
-/** TCP socket state.
- */
-enum tcp_socket_state{
+ * @see tcp_socket_state
+ */
+typedef enum tcp_socket_state tcp_socket_state_t;
+
+/** TCP socket state. */
+enum tcp_socket_state {
 	/** Initial.
-	 *  Not connected or bound.
+	 *
+	 * Not connected or bound.
 	 */
 	TCP_SOCKET_INITIAL,
+	
 	/** Listening.
-	 *  Awaiting a connection request from another TCP layer.
-	 *  When SYN is received a new bound socket in the TCP_SOCKET_SYN_RECEIVED state should be created.
+	 *
+	 * Awaiting a connection request from another TCP layer.
+	 * When SYN is received a new bound socket in the
+	 * TCP_SOCKET_SYN_RECEIVED state should be created.
 	 */
 	TCP_SOCKET_LISTEN,
+	
 	/** Connecting issued.
-	 *  A~SYN has been sent, and TCP is awaiting the response SYN.
-	 *  Should continue to the TCP_SOCKET_ESTABLISHED state.
+	 *
+	 * A SYN has been sent, and TCP is awaiting the response SYN.
+	 * Should continue to the TCP_SOCKET_ESTABLISHED state.
 	 */
 	TCP_SOCKET_SYN_SENT,
+	
 	/** Connecting received.
-	 *  A~SYN has been received, a~SYN has been sent, and TCP is awaiting an ACK.
-	 *  Should continue to the TCP_SOCKET_ESTABLISHED state.
+	 *
+	 * A SYN has been received, a SYN has been sent, and TCP is awaiting an
+	 * ACK. Should continue to the TCP_SOCKET_ESTABLISHED state.
 	 */
 	TCP_SOCKET_SYN_RECEIVED,
+	
 	/** Connected.
-	 *  The three-way handshake has been completed.
+	 *
+	 * The three-way handshake has been completed.
 	 */
 	TCP_SOCKET_ESTABLISHED,
+	
 	/** Closing started.
-	 *  The local application has issued a~CLOSE.
-	 *  TCP has sent a~FIN, and is awaiting an ACK or a~FIN.
-	 *  Should continue to the TCP_SOCKET_FIN_WAIT_2 state when an ACK is received.
-	 *  Should continue to the TCP_SOCKET_CLOSING state when a~FIN is received.
+	 *
+	 * The local application has issued a CLOSE.
+	 * TCP has sent a FIN, and is awaiting an ACK or a FIN.
+	 * Should continue to the TCP_SOCKET_FIN_WAIT_2 state when an ACK is
+	 * received.
+	 * Should continue to the TCP_SOCKET_CLOSING state when a FIN is
+	 * received.
 	 */
 	TCP_SOCKET_FIN_WAIT_1,
+	
 	/** Closing confirmed.
-	 *  A~FIN has been sent, and an ACK received.
-	 *  TCP is awaiting a~FIN from the remote TCP layer.
-	 *  Should continue to the TCP_SOCKET_CLOSING state.
+	 *
+	 * A FIN has been sent, and an ACK received.
+	 * TCP is awaiting a~FIN from the remote TCP layer.
+	 * Should continue to the TCP_SOCKET_CLOSING state.
 	 */
 	TCP_SOCKET_FIN_WAIT_2,
+	
 	/** Closing.
-	 *  A FIN has been sent, a FIN has been received, and an ACK has been sent.
-	 *  TCP is awaiting an ACK for the FIN that was sent.
-	 *  Should continue to the TCP_SOCKET_TIME_WAIT state.
+	 *
+	 * A FIN has been sent, a FIN has been received, and an ACK has been
+	 * sent.
+	 * TCP is awaiting an ACK for the FIN that was sent.
+	 * Should continue to the TCP_SOCKET_TIME_WAIT state.
 	 */
 	TCP_SOCKET_CLOSING,
+	
 	/** Closing received.
-	 *  TCP has received a~FIN, and has sent an ACK.
-	 *  It is awaiting a~close request from the local application before sending a~FIN.
-	 *  Should continue to the TCP_SOCKET_SOCKET_LAST_ACK state.
+	 *
+	 * TCP has received a FIN, and has sent an ACK.
+	 * It is awaiting a close request from the local application before
+	 * sending a FIN.
+	 * Should continue to the TCP_SOCKET_SOCKET_LAST_ACK state.
 	 */
 	TCP_SOCKET_CLOSE_WAIT,
-	/** 
-	 *  A~FIN has been received, and an ACK and a~FIN have been sent.
-	 *  TCP is awaiting an ACK.
-	 *  Should continue to the TCP_SOCKET_TIME_WAIT state.
+	
+	/**
+	 * A FIN has been received, and an ACK and a FIN have been sent.
+	 * TCP is awaiting an ACK.
+	 * Should continue to the TCP_SOCKET_TIME_WAIT state.
 	 */
 	TCP_SOCKET_LAST_ACK,
+	
 	/** Closing finished.
-	 *  FINs have been received and ACK’d, and TCP is waiting two MSLs to remove the connection from the table.
+	 *
+	 * FINs have been received and ACK’d, and TCP is waiting two MSLs to
+	 * remove the connection from the table.
 	 */
 	TCP_SOCKET_TIME_WAIT,
+	
 	/** Closed.
-	 *  Imaginary, this indicates that a~connection has been removed from the connection table.
+	 *
+	 * Imaginary, this indicates that a connection has been removed from
+	 * the connection table.
 	 */
 	TCP_SOCKET_CLOSED
 };
 
-/** TCP operation data.
- */
-struct tcp_operation{
-	/** Operation result.
-	 */
+/** TCP operation data. */
+struct tcp_operation {
+	/** Operation result. */
 	int result;
-	/** Safety lock.
-	 */
+	/** Safety lock. */
 	fibril_mutex_t mutex;
-	/** Operation result signaling.
-	 */
+	/** Operation result signaling. */
 	fibril_condvar_t condvar;
 };
 
-/** TCP socket specific data.
- */
-struct tcp_socket_data{
-	/** TCP socket state.
-	 */
+/** TCP socket specific data. */
+struct tcp_socket_data {
+	/** TCP socket state. */
 	tcp_socket_state_t state;
-	/** Data fragment size.
-	 *  Sending optimalization.
+	
+	/**
+	 * Data fragment size.
+	 * Sending optimalization.
 	 */
 	size_t data_fragment_size;
-	/** Device identifier.
-	 */
+	
+	/** Device identifier. */
 	device_id_t device_id;
-	/** Listening backlog.
-	 *  The maximal number of connected but not yet accepted sockets.
+	
+	/**
+	 * Listening backlog.
+	 * The maximal number of connected but not yet accepted sockets.
 	 */
 	int backlog;
-//	/** Segment size.
-//	 */
-//	size_t			segment_size;
-	/** Parent listening socket identifier.
-	 *  Set if this socket is an accepted one.
+	
+//	/** Segment size. */
+//	size_t segment_size;
+
+	/**
+	 * Parent listening socket identifier.
+	 * Set if this socket is an accepted one.
 	 */
 	int listening_socket_id;
-	/** Treshold size in bytes.
-	 */
+	
+	/** Treshold size in bytes. */
 	size_t treshold;
-	/** Window size in bytes.
-	 */
+	/** Window size in bytes. */
 	size_t window;
-	/** Acknowledgement timeout.
-	 */
+	/** Acknowledgement timeout. */
 	suseconds_t timeout;
-	/** Last acknowledged byte.
-	 */
+	/** Last acknowledged byte. */
 	uint32_t acknowledged;
-	/** Next incoming sequence number.
-	 */
+	/** Next incoming sequence number. */
 	uint32_t next_incoming;
-	/** Incoming FIN.
-	 */
+	/** Incoming FIN. */
 	uint32_t fin_incoming;
-	/** Next outgoing sequence number.
-	 */
+	/** Next outgoing sequence number. */
 	uint32_t next_outgoing;
-	/** Last outgoing sequence number.
-	 */
+	/** Last outgoing sequence number. */
 	uint32_t last_outgoing;
-	/** Outgoing FIN.
-	 */
+	/** Outgoing FIN. */
 	uint32_t fin_outgoing;
-	/** Expected sequence number by the remote host.
-	 *  The sequence number the other host expects.
-	 *  The notification is sent only upon a packet reecival.
+	
+	/**
+	 * Expected sequence number by the remote host.
+	 * The sequence number the other host expects.
+	 * The notification is sent only upon a packet reecival.
 	 */
 	uint32_t expected;
-	/** Expected sequence number counter.
-	 *  Counts the number of received notifications for the same sequence number.
+	
+	/**
+	 * Expected sequence number counter.
+	 * Counts the number of received notifications for the same sequence
+	 * number.
 	 */
 	int expected_count;
+	
 	/** Incoming packet queue.
-	 *  Packets are buffered until received in the right order.
-	 *  The packets are excluded after successfully read.
-	 *  Packets are sorted by their starting byte.
-	 *  Packets metric is set as their data length.
+	 *
+	 * Packets are buffered until received in the right order.
+	 * The packets are excluded after successfully read.
+	 * Packets are sorted by their starting byte.
+	 * Packets metric is set as their data length.
 	 */
 	packet_t incoming;
+	
 	/** Outgoing packet queue.
-	 *  Packets are buffered until acknowledged by the remote host in the right order.
-	 *  The packets are excluded after acknowledged.
-	 *  Packets are sorted by their starting byte.
-	 *  Packets metric is set as their data length.
+	 *
+	 * Packets are buffered until acknowledged by the remote host in the
+	 * right order.
+	 * The packets are excluded after acknowledged.
+	 * Packets are sorted by their starting byte.
+	 * Packets metric is set as their data length.
 	 */
 	packet_t outgoing;
-	/** IP pseudo header.
-	 */
+	
+	/** IP pseudo header. */
 	void *pseudo_header;
-	/** IP pseudo header length.
-	 */
+	/** IP pseudo header length. */
 	size_t headerlen;
-	/** Remote host address.
-	 */
-	struct sockaddr * addr;
-	/** Remote host address length.
-	 */
+	/** Remote host address. */
+	struct sockaddr *addr;
+	/** Remote host address length. */
 	socklen_t addrlen;
-	/** Remote host port.
-	 */
+	/** Remote host port. */
 	uint16_t dest_port;
-	/** Parent local sockets.
-	 */
+	/** Parent local sockets. */
 	socket_cores_ref local_sockets;
+	
 	/** Local sockets safety lock.
-	 *  May be locked for writing while holding the global lock for reading when changing the local sockets only.
-	 *  The global lock may to be locked only before locking the local lock.
-	 *  The global lock may be locked more weakly than the local lock.
-	 *  The global lock may be released before releasing the local lock.
-	 *  @see tcp_globals:lock
-	 */
-	fibril_rwlock_t * local_lock;
-	/** Pending operation data.
-	 */
+	 *
+	 * May be locked for writing while holding the global lock for reading
+	 * when changing the local sockets only.
+	 * The global lock may be locked only before locking the local lock.
+	 * The global lock may be locked more weakly than the local lock.
+	 * The global lock may be released before releasing the local lock.
+	 * @see tcp_globals:lock
+	 */
+	fibril_rwlock_t *local_lock;
+	
+	/** Pending operation data. */
 	tcp_operation_t operation;
-	/** Timeouts in a row counter.
-	 *  If TCP_MAX_TIMEOUTS is reached, the connection is lost.
+	
+	/**
+	 * Timeouts in a row counter.
+	 * If TCP_MAX_TIMEOUTS is reached, the connection is lost.
 	 */
 	int timeout_count;
 };
 
-/** TCP global data.
- */
-struct	tcp_globals{
-	/** Networking module phone.
-	 */
+/** TCP global data. */
+struct tcp_globals {
+	/** Networking module phone. */
 	int net_phone;
-	/** IP module phone.
-	 */
+	/** IP module phone. */
 	int ip_phone;
-	/** ICMP module phone.
-	 */
+	/** ICMP module phone. */
 	int icmp_phone;
-	/** Last used free port.
-	 */
+	/** Last used free port. */
 	int last_used_port;
-	/** Active sockets.
-	 */
+	/** Active sockets. */
 	socket_ports_t sockets;
-	/** Device packet dimensions.
-	 */
+	/** Device packet dimensions. */
 	packet_dimensions_t dimensions;
-	/** Safety lock.
-	 *  Write lock is used only for adding or removing socket ports.
+	
+	/**
+	 * Safety lock.
+	 * Write lock is used only for adding or removing socket ports.
 	 */
 	fibril_rwlock_t lock;
@@ -296,3 +321,2 @@
 /** @}
  */
-
Index: uspace/srv/net/tl/tcp/tcp_header.h
===================================================================
--- uspace/srv/net/tl/tcp/tcp_header.h	(revision ba1a2fdd0b308082b38db21536f17bf80860ec47)
+++ uspace/srv/net/tl/tcp/tcp_header.h	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
@@ -28,194 +28,113 @@
 
 /** @addtogroup tcp
- *  @{
+ * @{
  */
 
 /** @file
- *  TCP header definition.
- *  Based on the RFC~793.
+ * TCP header definition.
+ * Based on the RFC 793.
  */
 
-#ifndef __NET_TCP_HEADER_H__
-#define __NET_TCP_HEADER_H__
+#ifndef NET_TCP_HEADER_H_
+#define NET_TCP_HEADER_H_
 
 #include <sys/types.h>
 
-/** TCP header size in bytes.
- */
-#define TCP_HEADER_SIZE			sizeof(tcp_header_t)
+/** TCP header size in bytes. */
+#define TCP_HEADER_SIZE				sizeof(tcp_header_t)
 
 /** Returns the actual TCP header length in bytes.
- *  @param[in] header The TCP packet header.
+ * @param[in] header The TCP packet header.
  */
-#define TCP_HEADER_LENGTH(header)		((header)->header_length * 4u)
+#define TCP_HEADER_LENGTH(header)		((header)->header_length * 4U)
 
 /** Returns the TCP header length.
- *  @param[in] length The TCP header length in bytes.
+ * @param[in] length The TCP header length in bytes.
  */
-#define TCP_COMPUTE_HEADER_LENGTH(length)		((uint8_t) ((length) / 4u))
+#define TCP_COMPUTE_HEADER_LENGTH(length)	((uint8_t) ((length) / 4U))
 
 /** Type definition of the transmission datagram header.
- *  @see tcp_header
+ * @see tcp_header
  */
-typedef struct tcp_header	tcp_header_t;
+typedef struct tcp_header tcp_header_t;
 
 /** Type definition of the transmission datagram header pointer.
- *  @see tcp_header
+ * @see tcp_header
  */
-typedef tcp_header_t *		tcp_header_ref;
+typedef tcp_header_t *tcp_header_ref;
 
 /** Type definition of the transmission datagram header option.
- *  @see tcp_option
+ * @see tcp_option
  */
-typedef struct tcp_option	tcp_option_t;
+typedef struct tcp_option tcp_option_t;
 
 /** Type definition of the transmission datagram header option pointer.
- *  @see tcp_option
+ * @see tcp_option
  */
-typedef tcp_option_t *		tcp_option_ref;
+typedef tcp_option_t *tcp_option_ref;
 
-/** Type definition of the Maximum segment size TCP option.
- *  @see ...
- */
-typedef struct tcp_max_segment_size_option	tcp_max_segment_size_option_t;
+/** Type definition of the Maximum segment size TCP option. */
+typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
 
 /** Type definition of the Maximum segment size TCP option pointer.
- *  @see tcp_max_segment_size_option
+ * @see tcp_max_segment_size_option
  */
-typedef tcp_max_segment_size_option_t *		tcp_max_segment_size_option_ref;
+typedef tcp_max_segment_size_option_t *tcp_max_segment_size_option_ref;
 
-/** Transmission datagram header.
- */
-struct tcp_header{
-	/** The source port number.
-	 */
+/** Transmission datagram header. */
+struct tcp_header {
 	uint16_t source_port;
-	/** The destination port number.
-	 */
 	uint16_t destination_port;
-	/** The sequence number of the first data octet in this segment (except when SYN is present).
-	 *  If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.
-	 */
 	uint32_t sequence_number;
-	/** If the ACK control bit is set this field contains the value of the next sequence number the sender of the segment is expecting to receive.
-	 *  Once a~connection is established this is always sent.
-	 *  @see acknowledge
-	 */
 	uint32_t acknowledgement_number;
+	
 #ifdef ARCH_IS_BIG_ENDIAN
-	/** The number of 32~bit words in the TCP Header.
-	 *  This indicates where the data begins.
-	 *  The TCP header (even one including options) is an integral number of 32~bits long.
-	 */
 	uint8_t header_length:4;
-	/** Four bits reserved for future use.
-	 *  Must be zero.
-	 */
 	uint8_t reserved1:4;
 #else
-	/** Four bits reserved for future use.
-	 *  Must be zero.
-	 */
 	uint8_t reserved1:4;
-	/** The number of 32~bit words in the TCP Header.
-	 *  This indicates where the data begins.
-	 *  The TCP header (even one including options) is an integral number of 32~bits long.
-	 */
 	uint8_t header_length:4;
 #endif
+
 #ifdef ARCH_IS_BIG_ENDIAN
-	/** Two bits reserved for future use.
-	 *  Must be zero.
-	 */
 	uint8_t reserved2:2;
-	/** Urgent Pointer field significant.
-	 *  @see tcp_header:urgent_pointer
-	 */
 	uint8_t urgent:1;
-	/** Acknowledgment field significant
-	 *  @see tcp_header:acknowledgement_number
-	 */
 	uint8_t acknowledge:1;
-	/** Push function.
-	 */
 	uint8_t push:1;
-	/** Reset the connection.
-	 */
 	uint8_t reset:1;
-	/** Synchronize the sequence numbers.
-	 */
 	uint8_t synchronize:1;
-	/** No more data from the sender.
-	 */
 	uint8_t finalize:1;
 #else
-	/** No more data from the sender.
-	 */
 	uint8_t finalize:1;
-	/** Synchronize the sequence numbers.
-	 */
 	uint8_t synchronize:1;
-	/** Reset the connection.
-	 */
 	uint8_t reset:1;
-	/** Push function.
-	 */
 	uint8_t push:1;
-	/** Acknowledgment field significant.
-	 *  @see tcp_header:acknowledgement_number
-	 */
 	uint8_t acknowledge:1;
-	/** Urgent Pointer field significant.
-	 *  @see tcp_header:urgent_pointer
-	 */
 	uint8_t urgent:1;
-	/** Two bits reserved for future use.
-	 *  Must be zero.
-	 */
 	uint8_t reserved2:2;
 #endif
-	/** The number of data octets beginning with the one indicated in the acknowledgment field which the sender of this segment is willing to accept.
-	 *  @see tcp_header:acknowledge
-	 */
+
 	uint16_t window;
-	/** The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header and text.
-	 *  If a~segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a~16~bit word for checksum purposes.
-	 *  The pad is not transmitted as part of the segment.
-	 *  While computing the checksum, the checksum field itself is replaced with zeros.
-	 *  The checksum also coves a~pseudo header conceptually.
-	 *  The pseudo header conceptually prefixed to the TCP header contains the source address, the destination address, the protocol, and the TCP length.
-	 *  This information gives protection against misrouted datagrams.
-	 *  If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic).
-	 */
 	uint16_t checksum;
-	/** This field communicates the current value of the urgent pointer as a~positive offset from the sequence number in this segment.
-	 *  The urgent pointer points to the sequence number of the octet following the urgent data.
-	 *  This field is only be interpreted in segments with the URG control bit set.
-	 *  @see tcp_header:urgent
-	 */
 	uint16_t urgent_pointer;
 } __attribute__ ((packed));
 
-/** Transmission datagram header option.
- */
-struct tcp_option{
-	/** Option type.
-	 */
+/** Transmission datagram header option. */
+struct tcp_option {
+	/** Option type. */
 	uint8_t type;
-	/** Option length.
-	 */
+	/** Option length. */
 	uint8_t length;
 };
 
-/** Maximum segment size TCP option.
- */
-struct tcp_max_segment_size_option{
+/** Maximum segment size TCP option. */
+struct tcp_max_segment_size_option {
 	/** TCP option.
-	 *  @see TCPOPT_MAX_SEGMENT_SIZE
-	 *  @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
+	 * @see TCPOPT_MAX_SEGMENT_SIZE
+	 * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
 	 */
 	tcp_option_t option;
-	/** Maximum segment size in bytes.
-	 */
+	
+	/** Maximum segment size in bytes. */
 	uint16_t max_segment_size;
 } __attribute__ ((packed));
Index: uspace/srv/net/tl/tcp/tcp_module.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp_module.c	(revision ba1a2fdd0b308082b38db21536f17bf80860ec47)
+++ uspace/srv/net/tl/tcp/tcp_module.c	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
@@ -28,13 +28,17 @@
 
 /** @addtogroup tcp
- *  @{
+ * @{
  */
 
 /** @file
- *  TCP standalone module implementation.
- *  Contains skeleton module functions mapping.
- *  The functions are used by the module skeleton as module specific entry points.
- *  @see module.c
+ * TCP standalone module implementation.
+ * Contains skeleton module functions mapping.
+ * The functions are used by the module skeleton as module specific entry
+ * points.
+ * @see module.c
  */
+
+#include "tcp.h"
+#include "tcp_module.h"
 
 #include <async.h>
@@ -46,24 +50,13 @@
 #include <net/ip_protocols.h>
 #include <net/modules.h>
-
 #include <net/packet.h>
 #include <net_interface.h>
+
 #include <ip_interface.h>
 #include <tl_local.h>
 
-#include "tcp.h"
-#include "tcp_module.h"
+/** TCP module global data. */
+extern tcp_globals_t tcp_globals;
 
-/** TCP module global data.
- */
-extern tcp_globals_t	tcp_globals;
-
-/** Starts the TCP module.
- *  Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on successful module termination.
- *  @returns Other error codes as defined for the tcp_initialize() function.
- *  @returns Other error codes as defined for the REGISTER_ME() macro function.
- */
 int tl_module_start_standalone(async_client_conn_t client_connection)
 {
@@ -75,6 +68,6 @@
 	
 	ipcarg_t phonehash;
-	if (ERROR_OCCURRED(tcp_initialize(client_connection))
-	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_TCP, &phonehash))) {
+	if (ERROR_OCCURRED(tcp_initialize(client_connection)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_TCP, &phonehash))) {
 		pm_destroy();
 		return ERROR_CODE;
@@ -87,13 +80,8 @@
 }
 
-/** Processes the TCP message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the tcp_message() function.
- */
-int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int
+tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
 	return tcp_message_standalone(callid, call, answer, answer_count);
 }
Index: uspace/srv/net/tl/tcp/tcp_module.h
===================================================================
--- uspace/srv/net/tl/tcp/tcp_module.h	(revision ba1a2fdd0b308082b38db21536f17bf80860ec47)
+++ uspace/srv/net/tl/tcp/tcp_module.h	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
@@ -28,36 +28,21 @@
 
 /** @addtogroup tcp
- *  @{
+ * @{
  */
 
 /** @file
- *  TCP module functions.
- *  The functions are used as TCP module entry points.
+ * TCP module functions.
+ * The functions are used as TCP module entry points.
  */
 
-#ifndef __NET_TCP_MODULE_H__
-#define __NET_TCP_MODULE_H__
+#ifndef NET_TCP_MODULE_H_
+#define NET_TCP_MODULE_H_
 
 #include <async.h>
 #include <ipc/ipc.h>
 
-/** Initializes the TCP module.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-extern int tcp_initialize(async_client_conn_t client_connection);
-
-/** Processes the TCP message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @see tcp_interface.h
- *  @see IS_NET_TCP_MESSAGE()
- */
-extern int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+extern int tcp_initialize(async_client_conn_t);
+extern int tcp_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *,
+    int *);
 
 #endif
