35,6 → 35,7 |
|
#include <async.h> |
#include <ctype.h> |
#include <ddi.h> |
#include <errno.h> |
#include <malloc.h> |
#include <stdio.h> |
75,12 → 76,20 |
#define LO_NAME "lo" |
#define LO_FILENAME "/srv/lo" |
#define DP8390_NAME "dp8390" |
#define DP8390_FILENAME "/srv/dp8380" |
#define ETHERNET_NAME "ethernet" |
#define ETHERNET_FILENAME "/srv/ethernet" |
#define DP8390_FILENAME "/srv/dp8390" |
#define ETHERNET_NAME "ethernet" |
#define ETHERNET_FILENAME "/srv/eth" |
#define IP_NAME "ip" |
#define IP_FILENAME "/srv/ip" |
|
#define CONF_NAME "NAME" |
#define CONF_NETIF "NETIF" |
#define CONF_NIL "NIL" |
#define CONF_IL "IL" |
#define CONF_IRQ "IRQ" |
#define CONF_IO "IO" |
#define CONF_MTU "MTU" |
|
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_COUNT( call ) ( int ) IPC_GET_ARG2( * call ) |
|
101,10 → 110,10 |
struct module_struct{ |
task_id_t task_id; |
services_t service; |
int phone; |
int usage; |
const char * name; |
const char * filename; |
int phone; |
int usage; |
char * name; |
char * filename; |
}; |
|
/** A present network interface device. |
148,7 → 157,7 |
}; |
|
void networking_print_name( void ); |
int add_module( module_ref * module, modules_ref modules, const char const * name, const char const * filename, services_t service, task_id_t task_id ); |
int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id ); |
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name ); |
int networking_start_module( async_client_conn_t client_connection ); |
int networking_initialize( void ); |
157,7 → 166,7 |
//int parse_line( measured_strings_ref configuration, char * line ); |
int add_configuration( measured_strings_ref configuration, const char * name, const char * value ); |
int read_configuration( void ); |
task_id_t spawn( const char * const fname ); |
task_id_t spawn( char * fname ); |
int startup( void ); |
device_id_t generate_new_device_id( void ); |
|
173,7 → 182,7 |
printf( NAME ); |
} |
|
int add_module( module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id ){ |
int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id ){ |
ERROR_DECLARE; |
|
module_ref tmp_module; |
266,7 → 275,7 |
if( ! task_id ) return EINVAL; |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id )); |
// if( ! spawn( "/srv/udp" )) return EINVAL; |
if( ! spawn( "/srv/tcp" )) return EINVAL; |
// if( ! spawn( "/srv/tcp" )) return EINVAL; |
// if( ! spawn( "/srv/socket" )) return EINVAL; |
// not always necesssary |
// if( ! spawn( "/srv/arp" )) return EINVAL; |
432,32 → 441,51 |
} |
|
device_id_t generate_new_device_id( void ){ |
return netifs_count( & networking_globals.netifs ) + 1; |
return device_assign_devno(); |
} |
|
int read_configuration( void ){ |
ERROR_DECLARE; |
|
netif_ref netif; |
netif_ref netif; |
measured_string_ref setting; |
services_t internet_service; |
int index; |
services_t internet_service; |
int index; |
int irq; |
int io; |
int mtu; |
|
// read general configuration |
ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" )); |
ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "MTU", "1500" )); |
|
// read network interfaces configuration |
|
// static loopback initialization |
// printf( "\nloopback initialization" ); |
netif = ( netif_ref ) malloc( sizeof( netif_t )); |
if( ! netif ) return ENOMEM; |
netif->id = generate_new_device_id(); |
ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); |
if( ERROR_OCCURRED( add_configuration( & netif->configuration, "NAME", LO_NAME )) |
if( ERROR_OCCURRED( add_configuration( & netif->configuration, "NAME", "eth0" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IL", IP_NAME )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IRQ", "9" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IO", "300" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.5" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "ARP", "ARP" ))){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
/* if( ERROR_OCCURRED( add_configuration( & netif->configuration, "NAME", LO_NAME )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "NETIF", LO_NAME )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IL", IP_NAME )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "MTU", "1500" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )) |
|| ERROR_OCCURRED( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ))){ |
465,50 → 493,46 |
free( netif ); |
return ERROR_CODE; |
} |
// mandatory name |
// printf( "\n\tname" ); |
setting = measured_strings_find( & netif->configuration, "NAME", 0 ); |
*/ // mandatory name |
setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 ); |
if( ! setting ){ |
printf( "\nThe name is missing" ); |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
netif->name = setting->value; |
// printf( " %s OK", netif->name ); |
// mandatory netif |
// printf( "\n\tnetif" ); |
setting = measured_strings_find( & netif->configuration, "NETIF", 0 ); |
setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 ); |
if( ! setting ){ |
// printf( " unknown" ); |
printf( "\nThe network interface driver is missing" ); |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
// printf( " find %s in %d?", setting->value, modules_count( & networking_globals.modules )); |
netif->driver = modules_find( & networking_globals.modules, setting->value, 0 ); |
if( ! netif->driver ){ |
// printf( " not found" ); |
printf( "\nThe network interface driver is unknown" ); |
// TODO register the unknown one |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
// printf( " found" ); |
if( ! netif->driver->task_id ){ |
netif->driver->task_id = spawn( netif->driver->filename ); |
if( ! netif->driver->task_id ){ |
printf( "\nFailed to start the network interface driver" ); |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
} |
// printf( " OK" ); |
// optional link layer |
// printf( "\n\tlink layer" ); |
setting = measured_strings_find( & netif->configuration, "NIL", 0 ); |
// optional network interface layer |
setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 ); |
if( setting ){ |
netif->nil = modules_find( & networking_globals.modules, setting->value, 0 ); |
if( ! netif->nil ){ |
printf( "\nThe network interface layer is unknown" ); |
// TODO register the unknown one |
-- netif->driver->usage; |
measured_strings_destroy( & netif->configuration ); |
518,6 → 542,7 |
if( ! netif->nil->task_id ){ |
netif->nil->task_id = spawn( netif->nil->filename ); |
if( ! netif->nil->task_id ){ |
printf( "\nFailed to start the network interface layer" ); |
-- netif->driver->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
528,9 → 553,9 |
netif->nil = NULL; |
} |
// mandatory internet layer |
// printf( "\n\tinternet layer" ); |
setting = measured_strings_find( & netif->configuration, "IL", 0 ); |
setting = measured_strings_find( & netif->configuration, CONF_IL, 0 ); |
if( ! setting ){ |
printf( "\nThe internet layer is missing" ); |
-- netif->driver->usage; |
-- netif->nil->usage; |
measured_strings_destroy( & netif->configuration ); |
537,9 → 562,9 |
free( netif ); |
return EINVAL; |
} |
// printf( " set %s", setting->value ); |
netif->il = modules_find( & networking_globals.modules, setting->value, 0 ); |
if( ! netif->il ){ |
printf( "\nThe internet layer is unknown" ); |
// TODO register the unknown one |
-- netif->driver->usage; |
-- netif->nil->usage; |
547,10 → 572,10 |
free( netif ); |
return EINVAL; |
} |
// printf( " found" ); |
if( ! netif->il->task_id ){ |
netif->il->task_id = spawn( netif->il->filename ); |
if( ! netif->il->task_id ){ |
printf( "\nFailed to start the internet layer" ); |
-- netif->driver->usage; |
-- netif->nil->usage; |
measured_strings_destroy( & netif->configuration ); |
561,37 → 586,39 |
index = netifs_add( & networking_globals.netifs, netif->id, netif ); |
if( index < 0 ){ |
free( netif ); |
return ERROR_CODE; |
return index; |
} |
if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index ))){ |
netifs_exclude_index( & networking_globals.netifs, index ); |
return ERROR_CODE; |
} |
// printf( "\nloopback OK" ); |
// end of the static loopback initialization |
// startup the loopback interface |
if( ! netif->driver->phone ){ |
// printf( " connect?" ); |
netif->driver->phone = connect_to_service( netif->driver->service ); |
} |
// printf( " connected" ); |
// TODO io, irq |
ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, 0, 0 )); |
setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 ); |
irq = setting ? strtol( setting->value, NULL, 10 ) : 0; |
setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); |
io = setting ? strtol( setting->value, NULL, 16 ) : 0; |
ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, irq, io )); |
++ netif->driver->usage; |
if( netif->nil ){ |
if( ! netif->nil->phone ){ |
netif->nil->phone = connect_to_service( netif->nil->service ); |
} |
ERROR_PROPAGATE( async_req_2_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service )); |
setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); |
if( ! setting ){ |
setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 ); |
} |
mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service, mtu )); |
++ netif->nil->usage; |
internet_service = netif->nil->service; |
// printf( " OK" ); |
}else{ |
internet_service = netif->driver->service; |
// printf( " none" ); |
} |
if( ! netif->il->phone ){ |
// printf( " connect" ); |
netif->il->phone = connect_to_service( netif->il->service ); |
} |
// TODO IL_BUNDLE |
599,18 → 626,25 |
++ netif->il->usage; |
// TODO startup? |
ERROR_PROPAGATE( async_req_1_0( netif->driver->phone, NET_NETIF_START, netif->id )); |
// printf( "\n LO OK" ); |
printf( "\nNew network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name ); |
return EOK; |
} |
|
task_id_t spawn( const char * const fname ){ |
char * const argv[ 2 ] = { fname, NULL }; |
task_id_t spawn( char * fname ){ |
char * argv[ 2 ]; |
// char * argv[ 4 ]; |
task_id_t res; |
|
// printf( "Spawning %s\n", fname ); |
// argv[ 0 ] = fname; |
// argv[ 1 ] = NULL; |
argv[ 0 ] = fname; |
argv[ 1 ] = NULL; |
res = task_spawn( fname, argv ); |
/* argv[ 0 ] = "/app/trace"; |
argv[ 1 ] = "+ti"; |
argv[ 2 ] = fname; |
argv[ 3 ] = NULL; |
res = task_spawn( "/app/trace", argv ); |
*/ |
if( res != 0 ){ |
/* Success */ |
usleep( 50000 ); |