Index: uspace/srv/net/net/net.c
===================================================================
--- uspace/srv/net/net/net.c	(revision aadf01ebd2c032bc8dd43a6e06ae5715e6c2710f)
+++ uspace/srv/net/net/net.c	(revision 60ab6c32bdd1487d23ce71b9720e1b79f4c121ed)
@@ -66,11 +66,20 @@
 #include "net_messages.h"
 
+/** File read buffer size.
+ */
+#define BUFFER_SIZE	256
+
 /** Networking module name.
  */
 #define NAME	"Networking"
 
-/** File read buffer size.
- */
-#define BUFFER_SIZE	256
+/** Networking module global data.
+ */
+net_globals_t	net_globals;
+
+/** Generates new system-unique device identifier.
+ *  @returns The system-unique devic identifier.
+ */
+device_id_t generate_new_device_id(void);
 
 /** Prints the module name.
@@ -88,7 +97,20 @@
 int module_start(async_client_conn_t client_connection);
 
-/** \todo
- */
-int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
+/** Returns the configured values.
+ *  The network interface configuration is searched first.
+ *  @param[in] netif_conf The network interface configuration setting.
+ *  @param[out] configuration The found configured values.
+ *  @param[in] count The desired settings count.
+ *  @param[out] data The found configuration settings data.
+ *  @returns EOK.
+ */
+int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
+
+/** Initializes the networking 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 net_initialize(async_client_conn_t client_connection);
 
 /** \todo
@@ -101,4 +123,16 @@
  */
 int read_configuration(void);
+
+/** \todo
+ */
+int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
+
+/** Reads the network interface specific configuration.
+ *  @param[in] name The network interface name.
+ *  @param[in,out] netif The network interface structure.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the add_configuration() function.
+ */
+int read_netif_configuration(const char * name, netif_ref netif);
 
 /** Starts the network interface according to its configuration.
@@ -126,41 +160,28 @@
 int startup(void);
 
-/** Generates new system-unique device identifier.
- *  @returns The system-unique devic identifier.
- */
-device_id_t generate_new_device_id(void);
-
-/** Returns the configured values.
- *  The network interface configuration is searched first.
- *  @param[in] netif_conf The network interface configuration setting.
- *  @param[out] configuration The found configured values.
- *  @param[in] count The desired settings count.
- *  @param[out] data The found configuration settings data.
- *  @returns EOK.
- */
-int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
-
-/** Initializes the networking 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 net_initialize(async_client_conn_t client_connection);
-
-/** Reads the network interface specific configuration.
- *  @param[in] name The network interface name.
- *  @param[in,out] netif The network interface structure.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the add_configuration() function.
- */
-int read_netif_configuration(const char * name, netif_ref netif);
-
-/** Networking module global data.
- */
-net_globals_t	net_globals;
+GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
 
 DEVICE_MAP_IMPLEMENT(netifs, netif_t)
 
-GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
+int add_configuration(measured_strings_ref configuration, const char * name, const char * value){
+	ERROR_DECLARE;
+
+	measured_string_ref setting;
+
+	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))){
+		free(setting);
+		return ERROR_CODE;
+	}
+	return EOK;
+}
+
+device_id_t generate_new_device_id(void){
+	return device_assign_devno();
+}
 
 void module_print_name(void){
@@ -187,43 +208,9 @@
 }
 
-int net_initialize(async_client_conn_t client_connection){
-	ERROR_DECLARE;
-
-	netifs_initialize(&net_globals.netifs);
-	char_map_initialize(&net_globals.netif_names);
-	modules_initialize(&net_globals.modules);
-	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));
-
-	// build specific initialization
-	return net_initialize_build(client_connection);
-}
-
-int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
-	netif_ref netif;
-
-	if(!(configuration && (count > 0))){
-		return EINVAL;
-	}
-	netif = netifs_find(&net_globals.netifs, device_id);
-	if(netif){
-		return net_get_conf(&netif->configuration, * configuration, count, data);
-	}else{
-		return net_get_conf(NULL, * configuration, count, data);
-	}
-}
-
-int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
-	if(!(configuration && (count > 0))){
-		return EINVAL;
-	}
-	return net_get_conf(NULL, * configuration, count, data);
+int net_connect_module(services_t service){
+	return EOK;
+}
+
+void net_free_settings(measured_string_ref settings, char * data){
 }
 
@@ -235,4 +222,5 @@
 		*data = NULL;
 	}
+
 	for(index = 0; index < count; ++ index){
 		setting = measured_strings_find(netif_conf, configuration[index].value, 0);
@@ -251,9 +239,45 @@
 }
 
-void net_free_settings(measured_string_ref settings, char * data){
-}
-
-int net_connect_module(services_t service){
-	return EOK;
+int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
+	if(!(configuration && (count > 0))){
+		return EINVAL;
+	}
+
+	return net_get_conf(NULL, * configuration, count, data);
+}
+
+int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
+	netif_ref netif;
+
+	if(!(configuration && (count > 0))){
+		return EINVAL;
+	}
+
+	netif = netifs_find(&net_globals.netifs, device_id);
+	if(netif){
+		return net_get_conf(&netif->configuration, * configuration, count, data);
+	}else{
+		return net_get_conf(NULL, * configuration, count, data);
+	}
+}
+
+int net_initialize(async_client_conn_t client_connection){
+	ERROR_DECLARE;
+
+	netifs_initialize(&net_globals.netifs);
+	char_map_initialize(&net_globals.netif_names);
+	modules_initialize(&net_globals.modules);
+	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));
+
+	// build specific initialization
+	return net_initialize_build(client_connection);
 }
 
@@ -288,4 +312,73 @@
 	}
 	return ENOTSUP;
+}
+
+int parse_line(measured_strings_ref configuration, char * line){
+	ERROR_DECLARE;
+
+	measured_string_ref setting;
+	char * name;
+	char * value;
+
+	// from the beginning
+	name = line;
+
+	// skip comments and blank lines
+	if((*name == '#') || (*name == '\0')){
+		return EOK;
+	}
+	// skip spaces
+	while(isspace(*name)){
+		++ name;
+	}
+
+	// remember the name start
+	value = name;
+	// skip the name
+	while(isalnum(*value) || (*value == '_')){
+		// make uppercase
+//		*value = toupper(*value);
+		++ value;
+	}
+
+	if(*value == '='){
+		// terminate the name
+		*value = '\0';
+	}else{
+		// terminate the name
+		*value = '\0';
+		// skip until '='
+		++ value;
+		while((*value) && (*value != '=')){
+			++ value;
+		}
+		// not found?
+		if(*value != '='){
+			return EINVAL;
+		}
+	}
+
+	++ value;
+	// skip spaces
+	while(isspace(*value)){
+		++ value;
+	}
+	// create a bulk measured string till the end
+	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))){
+		free(setting);
+		return ERROR_CODE;
+	}
+	return EOK;
+}
+
+int read_configuration(void){
+	// read the general configuration file
+	return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
 }
 
@@ -341,94 +434,4 @@
 }
 
-int parse_line(measured_strings_ref configuration, char * line){
-	ERROR_DECLARE;
-
-	measured_string_ref setting;
-	char * name;
-	char * value;
-
-	// from the beginning
-	name = line;
-
-	// skip comments and blank lines
-	if((*name == '#') || (*name == '\0')){
-		return EOK;
-	}
-	// skip spaces
-	while(isspace(*name)){
-		++ name;
-	}
-
-	// remember the name start
-	value = name;
-	// skip the name
-	while(isalnum(*value) || (*value == '_')){
-		// make uppercase
-//		*value = toupper(*value);
-		++ value;
-	}
-
-	if(*value == '='){
-		// terminate the name
-		*value = '\0';
-	}else{
-		// terminate the name
-		*value = '\0';
-		// skip until '='
-		++ value;
-		while((*value) && (*value != '=')){
-			++ value;
-		}
-		// not found?
-		if(*value != '='){
-			return EINVAL;
-		}
-	}
-
-	++ value;
-	// skip spaces
-	while(isspace(*value)){
-		++ value;
-	}
-	// create a bulk measured string till the end
-	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))){
-		free(setting);
-		return ERROR_CODE;
-	}
-	return EOK;
-}
-
-int add_configuration(measured_strings_ref configuration, const char * name, const char * value){
-	ERROR_DECLARE;
-
-	measured_string_ref setting;
-
-	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))){
-		free(setting);
-		return ERROR_CODE;
-	}
-	return EOK;
-}
-
-device_id_t generate_new_device_id(void){
-	return device_assign_devno();
-}
-
-int read_configuration(void){
-	// read the general configuration file
-	return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
-}
-
 int read_netif_configuration(const char * name, netif_ref netif){
 	// read the netif configuration file
@@ -452,4 +455,5 @@
 		return EINVAL;
 	}
+
 	// optional network interface layer
 	setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
@@ -463,4 +467,5 @@
 		netif->nil = NULL;
 	}
+
 	// mandatory internet layer
 	setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
@@ -470,6 +475,6 @@
 		return EINVAL;
 	}
-	// end of the static loopback initialization
-	// startup the loopback interface
+
+	// hardware configuration
 	setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
 	irq = setting ? strtol(setting->value, NULL, 10) : 0;
@@ -477,4 +482,6 @@
 	io = setting ? strtol(setting->value, NULL, 16) : 0;
 	ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io));
+
+	// network interface layer startup
 	if(netif->nil){
 		setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
@@ -488,4 +495,6 @@
 		internet_service = netif->driver->service;
 	}
+
+	// inter-network layer startup
 	switch(netif->il->service){
 		case SERVICE_IP:
@@ -525,4 +534,5 @@
 		}
 		ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
+
 		// read configuration files
 		if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){
@@ -531,4 +541,5 @@
 			return ERROR_CODE;
 		}
+
 		// mandatory name
 		setting = measured_strings_find(&netif->configuration, CONF_NAME, 0);
@@ -540,4 +551,5 @@
 		}
 		netif->name = setting->value;
+
 		// add to the netifs map
 		index = netifs_add(&net_globals.netifs, netif->id, netif);
@@ -547,4 +559,5 @@
 			return index;
 		}
+
 		// add to the netif names map
 		if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))
@@ -555,4 +568,5 @@
 			return ERROR_CODE;
 		}
+
 		// increment modules' usage
 		++ netif->driver->usage;
