Index: uspace/srv/net/tl/icmp/icmp.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp.c	(revision 797b704b28bced20e17a9eb959845c20363ce662)
+++ uspace/srv/net/tl/icmp/icmp.c	(revision 5f635ca5f17ad0cfb38319aa99fcff04ca83851a)
@@ -35,7 +35,4 @@
  * @see icmp.h
  */
-
-#include "icmp.h"
-#include "icmp_module.h"
 
 #include <async.h>
@@ -72,10 +69,12 @@
 #include <ip_interface.h>
 #include <net_interface.h>
-#include <tl_interface.h>
-#include <tl_local.h>
+#include <tl_remote.h>
+#include <tl_skel.h>
 #include <icmp_header.h>
 
+#include "icmp.h"
+
 /** ICMP module name. */
-#define NAME	"ICMP protocol"
+#define NAME  "icmp"
 
 /** Default ICMP error reporting. */
@@ -394,78 +393,4 @@
 }
 
-/** Initializes the ICMP module.
- *
- * @param[in] client_connection The client connection processing function. The
- *			module skeleton propagates its own one.
- * @return		EOK on success.
- * @return		ENOMEM if there is not enough memory left.
- */
-int icmp_initialize(async_client_conn_t client_connection)
-{
-	measured_string_t names[] = {
-		{
-			(uint8_t *) "ICMP_ERROR_REPORTING",
-			20
-		},
-		{
-			(uint8_t *) "ICMP_ECHO_REPLYING",
-			18
-		}
-	};
-	measured_string_t *configuration;
-	size_t count = sizeof(names) / sizeof(measured_string_t);
-	uint8_t *data;
-	int rc;
-
-	fibril_rwlock_initialize(&icmp_globals.lock);
-	fibril_rwlock_write_lock(&icmp_globals.lock);
-	icmp_replies_initialize(&icmp_globals.replies);
-	icmp_echo_data_initialize(&icmp_globals.echo_data);
-	
-	icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,
-	    SERVICE_ICMP, client_connection);
-	if (icmp_globals.ip_phone < 0) {
-		fibril_rwlock_write_unlock(&icmp_globals.lock);
-		return icmp_globals.ip_phone;
-	}
-	
-	rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
-	    &icmp_globals.packet_dimension);
-	if (rc != EOK) {
-		fibril_rwlock_write_unlock(&icmp_globals.lock);
-		return rc;
-	}
-
-	icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;
-	icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;
-
-	icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING;
-	icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING;
-
-	/* Get configuration */
-	configuration = &names[0];
-	rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
-	    &data);
-	if (rc != EOK) {
-		fibril_rwlock_write_unlock(&icmp_globals.lock);
-		return rc;
-	}
-	
-	if (configuration) {
-		if (configuration[0].value) {
-			icmp_globals.error_reporting =
-			    (configuration[0].value[0] == 'y');
-		}
-		if (configuration[1].value) {
-			icmp_globals.echo_replying =
-			    (configuration[1].value[0] == 'y');
-		}
-		net_free_settings(configuration, data);
-	}
-
-	fibril_rwlock_write_unlock(&icmp_globals.lock);
-	return EOK;
-}
-
 /** Tries to set the pending reply result as the received message type.
  *
@@ -667,4 +592,110 @@
 		return icmp_release_and_return(packet, rc);
 
+	return EOK;
+}
+
+/** Process IPC messages from the IP module
+ *
+ * @param[in]     iid   Message identifier.
+ * @param[in,out] icall Message parameters.
+ *
+ */
+static void icmp_receiver(ipc_callid_t iid, ipc_call_t *icall)
+{
+	packet_t *packet;
+	int rc;
+	
+	while (true) {
+		switch (IPC_GET_IMETHOD(*icall)) {
+		case NET_TL_RECEIVED:
+			rc = packet_translate_remote(icmp_globals.net_phone, &packet,
+			    IPC_GET_PACKET(*icall));
+			if (rc == EOK)
+				rc = icmp_received_msg_local(IPC_GET_DEVICE(*icall), packet,
+				    SERVICE_ICMP, IPC_GET_ERROR(*icall));
+			
+			ipc_answer_0(iid, (sysarg_t) rc);
+			break;
+		default:
+			ipc_answer_0(iid, (sysarg_t) ENOTSUP);
+		}
+		
+		iid = async_get_call(icall);
+	}
+}
+
+/** Initialize the ICMP module.
+ *
+ * @param[in] net_phone Network module phone.
+ *
+ * @return EOK on success.
+ * @return ENOMEM if there is not enough memory left.
+ *
+ */
+int tl_initialize(int net_phone)
+{
+	measured_string_t names[] = {
+		{
+			(uint8_t *) "ICMP_ERROR_REPORTING",
+			20
+		},
+		{
+			(uint8_t *) "ICMP_ECHO_REPLYING",
+			18
+		}
+	};
+	measured_string_t *configuration;
+	size_t count = sizeof(names) / sizeof(measured_string_t);
+	uint8_t *data;
+	
+	fibril_rwlock_initialize(&icmp_globals.lock);
+	fibril_rwlock_write_lock(&icmp_globals.lock);
+	icmp_replies_initialize(&icmp_globals.replies);
+	icmp_echo_data_initialize(&icmp_globals.echo_data);
+	
+	icmp_globals.net_phone = net_phone;
+	
+	icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,
+	    SERVICE_ICMP, icmp_receiver);
+	if (icmp_globals.ip_phone < 0) {
+		fibril_rwlock_write_unlock(&icmp_globals.lock);
+		return icmp_globals.ip_phone;
+	}
+	
+	int rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
+	    &icmp_globals.packet_dimension);
+	if (rc != EOK) {
+		fibril_rwlock_write_unlock(&icmp_globals.lock);
+		return rc;
+	}
+	
+	icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;
+	icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;
+	
+	icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING;
+	icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING;
+	
+	/* Get configuration */
+	configuration = &names[0];
+	rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
+	    &data);
+	if (rc != EOK) {
+		fibril_rwlock_write_unlock(&icmp_globals.lock);
+		return rc;
+	}
+	
+	if (configuration) {
+		if (configuration[0].value) {
+			icmp_globals.error_reporting =
+			    (configuration[0].value[0] == 'y');
+		}
+		if (configuration[1].value) {
+			icmp_globals.echo_replying =
+			    (configuration[1].value[0] == 'y');
+		}
+		net_free_settings(configuration, data);
+	}
+	
+	fibril_rwlock_write_unlock(&icmp_globals.lock);
 	return EOK;
 }
@@ -893,89 +924,24 @@
  * @see IS_NET_ICMP_MESSAGE()
  */
-int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+int tl_module_message	(ipc_callid_t callid, ipc_call_t *call,
     ipc_call_t *answer, size_t *answer_count)
 {
-	packet_t *packet;
-	int rc;
-
 	*answer_count = 0;
 	switch (IPC_GET_IMETHOD(*call)) {
-	case NET_TL_RECEIVED:
-		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(*call));
-		if (rc != EOK)
-			return rc;
-		return icmp_received_msg_local(IPC_GET_DEVICE(*call), packet,
-		    SERVICE_ICMP, IPC_GET_ERROR(*call));
-	
 	case NET_ICMP_INIT:
 		return icmp_process_client_messages(callid, *call);
-	
 	default:
 		return icmp_process_message(call);
 	}
-
+	
 	return ENOTSUP;
 }
 
-
-/** Default thread for new connections.
- *
- * @param[in] iid The initial message identifier.
- * @param[in] icall The initial message call structure.
- *
- */
-static void tl_client_connection(ipc_callid_t iid, ipc_call_t *icall)
-{
-	/*
-	 * Accept the connection
-	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
-	 */
-	ipc_answer_0(iid, EOK);
-	
-	while (true) {
-		ipc_call_t answer;
-		size_t answer_count;
-		
-		/* Clear the answer structure */
-		refresh_answer(&answer, &answer_count);
-		
-		/* Fetch the next message */
-		ipc_call_t call;
-		ipc_callid_t callid = async_get_call(&call);
-		
-		/* Process the message */
-		int res = tl_module_message_standalone(callid, &call, &answer,
-		    &answer_count);
-		
-		/*
-		 * End if told to either by the message or the processing
-		 * result.
-		 */
-		if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||
-		    (res == EHANGUP))
-			return;
-		
-		/* Answer the message */
-		answer_call(callid, res, &answer, answer_count);
-	}
-}
-
-/** Starts the module.
- *
- * @return		EOK on success.
- * @return		Other error codes as defined for each specific module
- *			start function.
- */
 int main(int argc, char *argv[])
 {
-	int rc;
-	
 	/* Start the module */
-	rc = tl_module_start_standalone(tl_client_connection);
-	return rc;
+	return tl_module_start(SERVICE_ICMP);
 }
 
 /** @}
  */
-
