Index: uspace/srv/net/net/net.c
===================================================================
--- uspace/srv/net/net/net.c	(revision 14f1db0aaed5208d5e8340c816ca6e555f81f67e)
+++ uspace/srv/net/net/net.c	(revision 1bfd3d3b2991b8f2df4cff87d9723059528b9bd1)
@@ -36,4 +36,6 @@
  */
 
+#include "net.h"
+
 #include <async.h>
 #include <ctype.h>
@@ -46,40 +48,35 @@
 #include <ipc/ipc.h>
 #include <ipc/services.h>
-
-#include <net_err.h>
-#include <net_messages.h>
-#include <net_modules.h>
+#include <ipc/net.h>
+#include <ipc/net_net.h>
+#include <ipc/il.h>
+
+#include <net/modules.h>
+#include <net/packet.h>
+#include <net/device.h>
+
 #include <adt/char_map.h>
 #include <adt/generic_char_map.h>
 #include <adt/measured_strings.h>
 #include <adt/module_map.h>
-#include <packet/packet.h>
-#include <il_messages.h>
+
 #include <netif_remote.h>
-#include <net_device.h>
 #include <nil_interface.h>
 #include <net_interface.h>
 #include <ip_interface.h>
-#include <net_net_messages.h>
-
-#include "net.h"
-
-/** Networking module name.
- *
- */
+
+/** Networking module name. */
 #define NAME  "net"
 
-/** File read buffer size.
- *
- */
+/** File read buffer size. */
 #define BUFFER_SIZE  256
 
-/** Networking module global data.
- *
- */
+/** Networking module global data. */
 net_globals_t net_globals;
 
 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
 DEVICE_MAP_IMPLEMENT(netifs, netif_t);
+
+static int startup(void);
 
 /** Add the configured setting to the configuration map.
@@ -89,23 +86,23 @@
  * @param[in] value         The setting value.
  *
- * @returns EOK on success.
- * @returns ENOMEM if there is not enough memory left.
- *
- */
-int add_configuration(measured_strings_ref configuration, const char *name,
+ * @return EOK on success.
+ * @return ENOMEM if there is not enough memory left.
+ *
+ */
+int add_configuration(measured_strings_t *configuration, const char *name,
     const char *value)
 {
-	ERROR_DECLARE;
-	
-	measured_string_ref setting =
+	int rc;
+	
+	measured_string_t *setting =
 	    measured_string_create_bulk(value, 0);
-	
 	if (!setting)
 		return ENOMEM;
 	
 	/* Add the configuration setting */
-	if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
+	rc = measured_strings_add(configuration, name, 0, setting);
+	if (rc != EOK) {
 		free(setting);
-		return ERROR_CODE;
+		return rc;
 	}
 	
@@ -115,6 +112,5 @@
 /** Generate new system-unique device identifier.
  *
- * @returns The system-unique devic identifier.
- *
+ * @return		The system-unique devic identifier.
  */
 static device_id_t generate_new_device_id(void)
@@ -123,7 +119,7 @@
 }
 
-static int parse_line(measured_strings_ref configuration, char *line)
-{
-	ERROR_DECLARE;
+static int parse_line(measured_strings_t *configuration, char *line)
+{
+	int rc;
 	
 	/* From the beginning */
@@ -169,5 +165,5 @@
 	
 	/* Create a bulk measured string till the end */
-	measured_string_ref setting =
+	measured_string_t *setting =
 	    measured_string_create_bulk(value, 0);
 	if (!setting)
@@ -175,7 +171,8 @@
 	
 	/* Add the configuration setting */
-	if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
+	rc = measured_strings_add(configuration, name, 0, setting);
+	if (rc != EOK) {
 		free(setting);
-		return ERROR_CODE;
+		return rc;
 	}
 	
@@ -184,8 +181,6 @@
 
 static int read_configuration_file(const char *directory, const char *filename,
-    measured_strings_ref configuration)
-{
-	ERROR_DECLARE;
-	
+    measured_strings_t *configuration)
+{
 	printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename);
 	
@@ -206,26 +201,26 @@
 	unsigned int line_number = 0;
 	size_t index = 0;
-	while ((!ferror(cfg)) && (!feof(cfg))) {
+	while (!ferror(cfg) && !feof(cfg)) {
 		int read = fgetc(cfg);
 		if ((read > 0) && (read != '\n') && (read != '\r')) {
 			if (index >= BUFFER_SIZE) {
 				line[BUFFER_SIZE - 1] = '\0';
-				fprintf(stderr, "%s: Configuration line %u too long: %s\n",
-				    NAME, line_number, line);
+				fprintf(stderr, "%s: Configuration line %u too "
+				    "long: %s\n", NAME, line_number, line);
 				
 				/* No space left in the line buffer */
 				return EOVERFLOW;
-			} else {
-				/* Append the character */
-				line[index] = (char) read;
-				index++;
 			}
+			/* Append the character */
+			line[index] = (char) read;
+			index++;
 		} else {
 			/* On error or new line */
 			line[index] = '\0';
 			line_number++;
-			if (ERROR_OCCURRED(parse_line(configuration, line)))
-				fprintf(stderr, "%s: Configuration error on line %u: %s\n",
-				    NAME, line_number, line);
+			if (parse_line(configuration, line) != EOK) {
+				fprintf(stderr, "%s: Configuration error on "
+				    "line %u: %s\n", NAME, line_number, line);
+			}
 			
 			index = 0;
@@ -242,6 +237,6 @@
  * @param[in,out] netif The network interface structure.
  *
- * @returns EOK on success.
- * @returns Other error codes as defined for the add_configuration() function.
+ * @return EOK on success.
+ * @return Other error codes as defined for the add_configuration() function.
  *
  */
@@ -253,6 +248,6 @@
 /** Read the networking subsystem global configuration.
  *
- * @returns EOK on success.
- * @returns Other error codes as defined for the add_configuration() function.
+ * @return EOK on success.
+ * @return Other error codes as defined for the add_configuration() function.
  *
  */
@@ -269,11 +264,11 @@
  *                              its own one.
  *
- * @returns EOK on success.
- * @returns ENOMEM if there is not enough memory left.
+ * @return EOK on success.
+ * @return ENOMEM if there is not enough memory left.
  *
  */
 static int net_initialize(async_client_conn_t client_connection)
 {
-	ERROR_DECLARE;
+	int rc;
 	
 	netifs_initialize(&net_globals.netifs);
@@ -282,17 +277,25 @@
 	measured_strings_initialize(&net_globals.configuration);
 	
-	// TODO: dynamic configuration
-	ERROR_PROPAGATE(read_configuration());
-	
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
-	    LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
-	    DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
-	    ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0,
-	    connect_to_service));
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
-	    NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0,
-	    connect_to_service));
+	/* TODO: dynamic configuration */
+	rc = read_configuration();
+	if (rc != EOK)
+		return rc;
+	
+	rc = add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME,
+	    SERVICE_LO, 0, connect_to_service);
+	if (rc != EOK)
+		return rc;
+	rc = add_module(NULL, &net_globals.modules, DP8390_NAME,
+	    DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service);
+	if (rc != EOK)
+		return rc;
+	rc = add_module(NULL, &net_globals.modules, ETHERNET_NAME,
+	    ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
+	if (rc != EOK)
+		return rc;
+	rc = add_module(NULL, &net_globals.modules, NILDUMMY_NAME,
+	    NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
+	if (rc != EOK)
+		return rc;
 	
 	/* Build specific initialization */
@@ -312,28 +315,38 @@
  *                              its own one.
  *
- * @returns EOK on successful module termination.
- * @returns Other error codes as defined for the net_initialize() function.
- * @returns Other error codes as defined for the REGISTER_ME() macro function.
+ * @return EOK on successful module termination.
+ * @return Other error codes as defined for the net_initialize() function.
+ * @return Other error codes as defined for the REGISTER_ME() macro function.
  *
  */
 static int net_module_start(async_client_conn_t client_connection)
 {
-	ERROR_DECLARE;
+	ipcarg_t phonehash;
+	int rc;
 	
 	async_set_client_connection(client_connection);
-	ERROR_PROPAGATE(pm_init());
-	
-	ipcarg_t phonehash;
-	
-	if (ERROR_OCCURRED(net_initialize(client_connection))
-	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){
-		pm_destroy();
-		return ERROR_CODE;
-	}
-	
+	rc = pm_init();
+	if (rc != EOK)
+		return rc;
+	
+	
+	rc = net_initialize(client_connection);
+	if (rc != EOK)
+		goto out;
+	
+	rc = REGISTER_ME(SERVICE_NETWORKING, &phonehash);
+	if (rc != EOK)
+		goto out;
+	
+	rc = startup();
+	if (rc != EOK)
+		goto out;
+	
+	task_retval(0);
 	async_manager();
-	
+
+out:
 	pm_destroy();
-	return EOK;
+	return rc;
 }
 
@@ -341,5 +354,5 @@
  *
  * The network interface configuration is searched first.
- &
+ *
  * @param[in]  netif_conf    The network interface configuration setting.
  * @param[out] configuration The found configured values.
@@ -347,9 +360,9 @@
  * @param[out] data          The found configuration settings data.
  *
- * @returns EOK.
- *
- */
-static int net_get_conf(measured_strings_ref netif_conf,
-    measured_string_ref configuration, size_t count, char **data)
+ * @return EOK.
+ *
+ */
+static int net_get_conf(measured_strings_t *netif_conf,
+    measured_string_t *configuration, size_t count, char **data)
 {
 	if (data)
@@ -358,5 +371,5 @@
 	size_t index;
 	for (index = 0; index < count; index++) {
-		measured_string_ref setting =
+		measured_string_t *setting =
 		    measured_strings_find(netif_conf, configuration[index].value, 0);
 		if (!setting)
@@ -376,8 +389,8 @@
 }
 
-int net_get_conf_req(int net_phone, measured_string_ref *configuration,
+int net_get_conf_req(int net_phone, measured_string_t **configuration,
     size_t count, char **data)
 {
-	if (!(configuration && (count > 0)))
+	if (!configuration || (count <= 0))
 		return EINVAL;
 	
@@ -386,5 +399,5 @@
 
 int net_get_device_conf_req(int net_phone, device_id_t device_id,
-    measured_string_ref *configuration, size_t count, char **data)
+    measured_string_t **configuration, size_t count, char **data)
 {
 	if ((!configuration) || (count == 0))
@@ -398,5 +411,5 @@
 }
 
-void net_free_settings(measured_string_ref settings, char *data)
+void net_free_settings(measured_string_t *settings, char *data)
 {
 }
@@ -409,19 +422,19 @@
  * @param[in] netif The network interface specific data.
  *
- * @returns EOK on success.
- * @returns EINVAL if there are some settings missing.
- * @returns ENOENT if the internet protocol module is not known.
- * @returns Other error codes as defined for the netif_probe_req() function.
- * @returns Other error codes as defined for the nil_device_req() function.
- * @returns Other error codes as defined for the needed internet layer
- *          registering function.
+ * @return EOK on success.
+ * @return EINVAL if there are some settings missing.
+ * @return ENOENT if the internet protocol module is not known.
+ * @return Other error codes as defined for the netif_probe_req() function.
+ * @return Other error codes as defined for the nil_device_req() function.
+ * @return Other error codes as defined for the needed internet layer
+ *         registering function.
  *
  */
 static int start_device(netif_t *netif)
 {
-	ERROR_DECLARE;
+	int rc;
 	
 	/* Mandatory netif */
-	measured_string_ref setting =
+	measured_string_t *setting =
 	    measured_strings_find(&netif->configuration, CONF_NETIF, 0);
 	
@@ -461,5 +474,7 @@
 	int io = setting ? strtol(setting->value, NULL, 16) : 0;
 	
-	ERROR_PROPAGATE(netif_probe_req_remote(netif->driver->phone, netif->id, irq, io));
+	rc = netif_probe_req_remote(netif->driver->phone, netif->id, irq, io);
+	if (rc != EOK)
+		return rc;
 	
 	/* Network interface layer startup */
@@ -473,6 +488,8 @@
 		int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
 		
-		ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu,
-		    netif->driver->service));
+		rc = nil_device_req(netif->nil->phone, netif->id, mtu,
+		    netif->driver->service);
+		if (rc != EOK)
+			return rc;
 		
 		internet_service = netif->nil->service;
@@ -482,35 +499,38 @@
 	/* Inter-network layer startup */
 	switch (netif->il->service) {
-		case SERVICE_IP:
-			ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id,
-			    internet_service));
-			break;
-		default:
-			return ENOENT;
-	}
-	
-	ERROR_PROPAGATE(netif_start_req_remote(netif->driver->phone, netif->id));
-	return EOK;
+	case SERVICE_IP:
+		rc = ip_device_req(netif->il->phone, netif->id,
+		    internet_service);
+		if (rc != EOK)
+			return rc;
+		break;
+	default:
+		return ENOENT;
+	}
+	
+	return netif_start_req_remote(netif->driver->phone, netif->id);
 }
 
 /** Read the configuration and start all network interfaces.
  *
- * @returns EOK on success.
- * @returns EXDEV if there is no available system-unique device identifier.
- * @returns EINVAL if any of the network interface names are not configured.
- * @returns ENOMEM if there is not enough memory left.
- * @returns Other error codes as defined for the read_configuration()
- *          function.
- * @returns Other error codes as defined for the read_netif_configuration()
- *          function.
- * @returns Other error codes as defined for the start_device() function.
+ * @return EOK on success.
+ * @return EXDEV if there is no available system-unique device identifier.
+ * @return EINVAL if any of the network interface names are not configured.
+ * @return ENOMEM if there is not enough memory left.
+ * @return Other error codes as defined for the read_configuration()
+ *         function.
+ * @return Other error codes as defined for the read_netif_configuration()
+ *         function.
+ * @return Other error codes as defined for the start_device() function.
  *
  */
 static int startup(void)
 {
-	ERROR_DECLARE;
-	
-	const char *conf_files[] = {"lo", "ne2k"};
+	const char *conf_files[] = {
+		"lo",
+		"ne2k"
+	};
 	size_t count = sizeof(conf_files) / sizeof(char *);
+	int rc;
 	
 	size_t i;
@@ -524,15 +544,18 @@
 			return EXDEV;
 		
-		ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
+		rc = measured_strings_initialize(&netif->configuration);
+		if (rc != EOK)
+			return rc;
 		
 		/* Read configuration files */
-		if (ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))) {
+		rc = read_netif_configuration(conf_files[i], netif);
+		if (rc != EOK) {
 			measured_strings_destroy(&netif->configuration);
 			free(netif);
-			return ERROR_CODE;
+			return rc;
 		}
 		
 		/* Mandatory name */
-		measured_string_ref setting =
+		measured_string_t *setting =
 		    measured_strings_find(&netif->configuration, CONF_NAME, 0);
 		if (!setting) {
@@ -556,9 +579,17 @@
 		 * and needed modules.
 		 */
-		if ((ERROR_OCCURRED(char_map_add(&net_globals.netif_names,
-		    netif->name, 0, index))) || (ERROR_OCCURRED(start_device(netif)))) {
+		rc = char_map_add(&net_globals.netif_names, netif->name, 0,
+		    index);
+		if (rc != EOK) {
 			measured_strings_destroy(&netif->configuration);
 			netifs_exclude_index(&net_globals.netifs, index);
-			return ERROR_CODE;
+			return rc;
+		}
+		
+		rc = start_device(netif);
+		if (rc != EOK) {
+			measured_strings_destroy(&netif->configuration);
+			netifs_exclude_index(&net_globals.netifs, index);
+			return rc;
 		}
 		
@@ -586,6 +617,6 @@
  *                          in the answer parameter.
  *
- * @returns EOK on success.
- * @returns ENOTSUP if the message is not known.
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
  *
  * @see net_interface.h
@@ -596,39 +627,43 @@
     int *answer_count)
 {
-	ERROR_DECLARE;
-	
-	measured_string_ref strings;
+	measured_string_t *strings;
 	char *data;
+	int rc;
 	
 	*answer_count = 0;
 	switch (IPC_GET_METHOD(*call)) {
-		case IPC_M_PHONE_HUNGUP:
-			return EOK;
-		case NET_NET_GET_DEVICE_CONF:
-			ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
-			    IPC_GET_COUNT(call)));
-			net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings,
-			    IPC_GET_COUNT(call), NULL);
-			
-			/* Strings should not contain received data anymore */
-			free(data);
-			
-			ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
-			free(strings);
-			return ERROR_CODE;
-		case NET_NET_GET_CONF:
-			ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
-			    IPC_GET_COUNT(call)));
-			net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
-			
-			/* Strings should not contain received data anymore */
-			free(data);
-			
-			ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
-			free(strings);
-			return ERROR_CODE;
-		case NET_NET_STARTUP:
-			return startup();
-	}
+	case IPC_M_PHONE_HUNGUP:
+		return EOK;
+	case NET_NET_GET_DEVICE_CONF:
+		rc = measured_strings_receive(&strings, &data,
+		    IPC_GET_COUNT(call));
+		if (rc != EOK)
+			return rc;
+		net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings,
+		    IPC_GET_COUNT(call), NULL);
+		
+		/* Strings should not contain received data anymore */
+		free(data);
+		
+		rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
+		free(strings);
+		return rc;
+	case NET_NET_GET_CONF:
+		rc = measured_strings_receive(&strings, &data,
+		    IPC_GET_COUNT(call));
+		if (rc != EOK)
+			return rc;
+		net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
+		
+		/* Strings should not contain received data anymore */
+		free(data);
+		
+		rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
+		free(strings);
+		return rc;
+	case NET_NET_STARTUP:
+		return startup();
+	}
+	
 	return ENOTSUP;
 }
@@ -661,5 +696,5 @@
 		int res = net_module_message(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) || (res == EHANGUP))
 			return;
@@ -672,9 +707,10 @@
 int main(int argc, char *argv[])
 {
-	ERROR_DECLARE;
-	
-	if (ERROR_OCCURRED(net_module_start(net_client_connection))) {
-		fprintf(stderr, "%s: net_module_start error %i\n", NAME, ERROR_CODE);
-		return ERROR_CODE;
+	int rc;
+	
+	rc = net_module_start(net_client_connection);
+	if (rc != EOK) {
+		fprintf(stderr, "%s: net_module_start error %i\n", NAME, rc);
+		return rc;
 	}
 	
