Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3845 → Rev 3846

/branches/network/uspace/srv/net/networking/networking.c
39,11 → 39,10
#include <malloc.h>
#include <stdio.h>
#include <task.h>
//#include <thread.h>
#include <unistd.h>
 
#include <ipc/ipc.h>
#include <ipc/services.h>
//#include <sys/mman.h>
 
#include "../char_map.h"
#include "../err.h"
53,15 → 52,21
#include "../modules.h"
//#include "../self_test.h"
 
#include "../netif/netif_device_id_type.h"
#include "../ip/ip_messages.h"
#include "../netif/device.h"
 
#ifdef NETWORKING_module
#if IP_BUNDLE
 
#include "../ip/ip.h"
#include "../tcp/tcp.h"
#include "../ip/ip_module.h"
 
#endif
 
#if TCP_BUNDLE
 
#include "../tcp/tcp_module.h"
 
#endif
 
#define LO_NAME "lo"
#define LO_FILENAME "/sbin/lo"
#define DP8390_ISA_NAME "dp8390_isa"
99,16 → 104,16
struct netif{
/** A system-unique network interface identifier.
*/
netif_device_id_t id;
device_id_t id;
/** A serving network interface driver module index.
*/
module_ref driver_module;
module_ref driver;
/** A serving link layer module index.
*/
module_ref link_layer_module;
module_ref nil;
/** A serving internet layer module index.
*/
module_ref internet_layer_module;
module_ref il;
/** A system-unique network interface name.
*/
char * name;
138,7 → 143,6
static void client_connection( ipc_callid_t iid, ipc_call_t * icall );
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name );
int main( int argc, char * argv[] );
int networking_call( ipc_callid_t callid );
int networking_initialize( void );
int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
//int parse_line( measured_strings_ref configuration, char * line );
146,7 → 150,7
int read_configuration( void );
task_id_t spawn( const char * fname );
int startup( void );
netif_device_id_t generate_new_device_id( void );
device_id_t generate_new_device_id( void );
 
static networking_globals_t networking_globals;
 
169,7 → 173,7
tmp_module->name = name;
tmp_module->filename = filename;
tmp_module->service = service;
if( ERROR_OCCURED( modules_add( modules, tmp_module->name, tmp_module ))){
if( ERROR_OCCURED( modules_add( modules, tmp_module->name, 0, tmp_module ))){
free( tmp_module );
return ERROR_CODE;
}
183,7 → 187,10
ipcarg_t arg1, arg2, arg3;
int res;
 
/* Accept the connection */
/*
* Accept the connection
* - Answer the first IPC_M_CONNECT_ME_TO call.
*/
// printf( "\nNET-%d got %d on %x from %x", fibril_get_id(), IPC_GET_METHOD( * icall ), icall->in_phone_hash, iid );
ipc_answer_0( iid, EOK );
 
195,51 → 202,24
// printf( "\nNET-%d got %d on %x from %x", fibril_get_id(), IPC_GET_METHOD( call ), call.in_phone_hash, callid );
#ifdef NETWORKING_module
if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
res = ip_call( callid );
if( res == EOK ){
res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
/* }else if( IS_NET_ARP_MESSAGE( call )){
res = arp_call( callid );
if( res == EOK ){
res = arp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = arp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
*//* }else if( IS_NET_RARP_MESSAGE( call )){
res = rarp_call( callid );
if( res == EOK ){
res = rarp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = rarp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
*//* }else if( IS_NET_ICMP_MESSAGE( call )){
res = icmp_call( callid );
if( res == EOK ){
res = icmp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = icmp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
*//* }else if( IS_NET_UDP_MESSAGE( call )){
res = udp_call( callid );
if( res == EOK ){
res = udp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = udp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
*/ }else if( IS_NET_TCP_MESSAGE( call )){
res = tcp_call( callid );
if( res == EOK ){
res = tcp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = tcp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
/* }else if( IS_NET_SOCKET_MESSAGE( call )){
res = socket_call( callid );
if( res == EOK ){
res = socket_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
*//* }else if( IS_NET_LL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){
res = ethernet_call( callid );
if( res == EOK ){
res = ethernet_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = socket_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
*//* }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){
res = ethernet_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
*/ }else{
#endif
res = networking_call( callid );
if( res == EOK ){
res = networking_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
}
res = networking_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
#ifdef NETWORKING_module
}
#endif
248,13 → 228,18
}
 
int main( int argc, char * argv[] ){
ERROR_DECLARE;
 
ipcarg_t phonehash;
 
printf("\nTask %d - HelenOS Networking subsystem", task_get_id());
 
return start_service( SERVICE_NETWORKING, NULL, NULL, client_connection, networking_initialize );
}
async_set_client_connection( client_connection );
ERROR_PROPAGATE( networking_initialize());
ERROR_PROPAGATE( REGISTER_ME( SERVICE_NETWORKING, & phonehash ));
 
int networking_call( ipc_callid_t callid ){
async_manager();
 
return EOK;
}
 
327,12 → 312,12
switch( method ){
case IPC_M_PHONE_HUNGUP:
return EOK;
case NET_NETWORKING_DEVICE:
case NET_NET_DEVICE:
// TODO configure, register
// arg1 = netif id
printf( "\nNetworking: new netif %d", arg1 );
return EOK;
case NET_NETWORKING_GET_DEVICE_CONFIGURATION:
case NET_NET_GET_DEVICE_CONF:
// arg1 = netif id
// arg2 = count
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg2 ));
343,9 → 328,9
configuration = NULL;
}
for( index = 0; index < arg2; ++ index ){
setting = measured_strings_find( configuration, strings[ index ].value );
setting = measured_strings_find( configuration, strings[ index ].value, 0 );
if( ! setting ){
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value );
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
}
if( setting ){
strings[ index ].length = setting->length;
360,11 → 345,11
ERROR_CODE = measured_strings_reply( strings, arg2 );
free( strings );
return ERROR_CODE;
case NET_NETWORKING_GET_CONFIGURATION:
case NET_NET_GET_CONF:
// arg1 = count
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg1 ));
for( index = 0; index < arg1; ++ index ){
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value );
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
if( setting ){
strings[ index ].length = setting->length;
strings[ index ].value = setting->value;
378,7 → 363,7
ERROR_CODE = measured_strings_reply( strings, arg1 );
free( strings );
return ERROR_CODE;
case NET_NETWORKING_STARTUP:
case NET_NET_STARTUP:
return startup();
}
return ENOTSUP;
423,7 → 408,7
setting = measured_string_create_bulk( value, -1 );
if( ! setting ) return ENOMEM;
// add the configuration setting
if( ERROR_OCCURED( measured_strings_add( configuration, name, setting ))){
if( ERROR_OCCURED( measured_strings_add( configuration, name, 0, setting ))){
free( setting );
return ERROR_CODE;
}
439,7 → 424,7
setting = measured_string_create_bulk( value, 0 );
if( ! setting ) return ENOMEM;
// add the configuration setting
if( ERROR_OCCURED( measured_strings_add( configuration, name, setting ))){
if( ERROR_OCCURED( measured_strings_add( configuration, name, 0, setting ))){
free( setting );
return ERROR_CODE;
}
446,7 → 431,7
return EOK;
}
 
netif_device_id_t generate_new_device_id( void ){
device_id_t generate_new_device_id( void ){
return netifs_count( & networking_globals.netifs ) + 1;
}
 
482,7 → 467,7
}
// mandatory name
// printf( "\n\tname" );
setting = measured_strings_find( & netif->configuration, "NAME" );
setting = measured_strings_find( & netif->configuration, "NAME", 0 );
if( ! setting ){
measured_strings_destroy( & netif->configuration );
free( netif );
492,7 → 477,7
// printf( " %s OK", netif->name );
// mandatory netif
// printf( "\n\tnetif" );
setting = measured_strings_find( & netif->configuration, "NETIF" );
setting = measured_strings_find( & netif->configuration, "NETIF", 0 );
if( ! setting ){
// printf( " unknown" );
measured_strings_destroy( & netif->configuration );
500,8 → 485,8
return EINVAL;
}
// printf( " find %s in %d?", setting->value, modules_count( & networking_globals.modules ));
netif->driver_module = modules_find( & networking_globals.modules, setting->value );
if( ! netif->driver_module ){
netif->driver = modules_find( & networking_globals.modules, setting->value, 0 );
if( ! netif->driver ){
// printf( " not found" );
// TODO register the unknown one
measured_strings_destroy( & netif->configuration );
509,9 → 494,9
return EINVAL;
}
// printf( " found" );
if( ! netif->driver_module->task_id ){
netif->driver_module->task_id = spawn( netif->driver_module->filename );
if( ! netif->driver_module->task_id ){
if( ! netif->driver->task_id ){
netif->driver->task_id = spawn( netif->driver->filename );
if( ! netif->driver->task_id ){
measured_strings_destroy( & netif->configuration );
free( netif );
return EINVAL;
520,20 → 505,20
// printf( " OK" );
// optional link layer
// printf( "\n\tlink layer" );
setting = measured_strings_find( & netif->configuration, "LL" );
setting = measured_strings_find( & netif->configuration, "NIL", 0 );
if( setting ){
netif->link_layer_module = modules_find( & networking_globals.modules, setting->value );
if( ! netif->link_layer_module ){
netif->nil = modules_find( & networking_globals.modules, setting->value, 0 );
if( ! netif->nil ){
// TODO register the unknown one
-- netif->driver_module->usage;
-- netif->driver->usage;
measured_strings_destroy( & netif->configuration );
free( netif );
return EINVAL;
}
if( ! netif->link_layer_module->task_id ){
netif->link_layer_module->task_id = spawn( netif->link_layer_module->filename );
if( ! netif->link_layer_module->task_id ){
-- netif->driver_module->usage;
if( ! netif->nil->task_id ){
netif->nil->task_id = spawn( netif->nil->filename );
if( ! netif->nil->task_id ){
-- netif->driver->usage;
measured_strings_destroy( & netif->configuration );
free( netif );
return EINVAL;
540,34 → 525,34
}
}
}else{
netif->link_layer_module = NULL;
netif->nil = NULL;
}
// mandatory internet layer
// printf( "\n\tinternet layer" );
setting = measured_strings_find( & netif->configuration, "IL" );
setting = measured_strings_find( & netif->configuration, "IL", 0 );
if( ! setting ){
-- netif->driver_module->usage;
-- netif->link_layer_module->usage;
-- netif->driver->usage;
-- netif->nil->usage;
measured_strings_destroy( & netif->configuration );
free( netif );
return EINVAL;
}
// printf( " set %s", setting->value );
netif->internet_layer_module = modules_find( & networking_globals.modules, setting->value );
if( ! netif->internet_layer_module ){
netif->il = modules_find( & networking_globals.modules, setting->value, 0 );
if( ! netif->il ){
// TODO register the unknown one
-- netif->driver_module->usage;
-- netif->link_layer_module->usage;
-- netif->driver->usage;
-- netif->nil->usage;
measured_strings_destroy( & netif->configuration );
free( netif );
return EINVAL;
}
// printf( " found" );
if( ! netif->internet_layer_module->task_id ){
netif->internet_layer_module->task_id = spawn( netif->internet_layer_module->filename );
if( ! netif->internet_layer_module->task_id ){
-- netif->driver_module->usage;
-- netif->link_layer_module->usage;
if( ! netif->il->task_id ){
netif->il->task_id = spawn( netif->il->filename );
if( ! netif->il->task_id ){
-- netif->driver->usage;
-- netif->nil->usage;
measured_strings_destroy( & netif->configuration );
free( netif );
return EINVAL;
578,7 → 563,7
free( netif );
return ERROR_CODE;
}
if( ERROR_OCCURED( char_map_add( & networking_globals.netif_names, netif->name, index ))){
if( ERROR_OCCURED( char_map_add( & networking_globals.netif_names, netif->name, 0, index ))){
netifs_exclude_index( & networking_globals.netifs, index );
return ERROR_CODE;
}
585,32 → 570,35
// printf( "\nloopback OK" );
// end of the static loopback initialization
// startup the loopback interface
if( ! netif->driver_module->phone ){
if( ! netif->driver->phone ){
// printf( " connect?" );
netif->driver_module->phone = connect_to_service( netif->driver_module->service );
netif->driver->phone = connect_to_service( netif->driver->service );
}
// printf( " connected" );
ERROR_PROPAGATE( async_req_1_0( netif->driver_module->phone, NET_NETIF_PROBE, netif->id ));
++ netif->driver_module->usage;
if( netif->link_layer_module ){
if( ! netif->link_layer_module->phone ){
netif->link_layer_module->phone = connect_to_service( netif->link_layer_module->service );
// TODO io, irq
ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, 0, 0 ));
++ 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->link_layer_module->phone, NET_LL_DEVICE, netif->id, netif->driver_module->service ));
++ netif->link_layer_module->usage;
internet_service = netif->link_layer_module->service;
ERROR_PROPAGATE( async_req_2_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service ));
++ netif->nil->usage;
internet_service = netif->nil->service;
// printf( " OK" );
}else{
internet_service = netif->driver_module->service;
internet_service = netif->driver->service;
// printf( " none" );
}
if( ! netif->internet_layer_module->phone ){
if( ! netif->il->phone ){
// printf( " connect" );
netif->internet_layer_module->phone = connect_to_service( netif->internet_layer_module->service );
netif->il->phone = connect_to_service( netif->il->service );
}
ERROR_PROPAGATE( async_req_2_0( netif->internet_layer_module->phone, NET_IL_DEVICE, netif->id, internet_service ));
++ netif->internet_layer_module->usage;
ERROR_PROPAGATE( async_req_1_0( netif->driver_module->phone, NET_NETIF_START, netif->id ));
// TODO IL_BUNDLE
ERROR_PROPAGATE( async_req_2_0( netif->il->phone, NET_IL_DEVICE, netif->id, internet_service ));
++ netif->il->usage;
// TODO startup?
ERROR_PROPAGATE( async_req_1_0( netif->driver->phone, NET_NETIF_START, netif->id ));
// printf( "\n LO OK" );
return EOK;
}