Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3900 → Rev 3901

/branches/network/uspace/srv/net/networking/networking.c
52,6 → 52,8
#include "../structures/char_map.h"
#include "../structures/generic_char_map.h"
#include "../structures/measured_strings.h"
#include "../structures/packet/packet.h"
#include "../structures/packet/packet_server.h"
 
#include "../il/ip/ip_messages.h"
#include "../netif/device.h"
68,6 → 70,8
 
#endif
 
#define NAME "Networking"
 
#define LO_NAME "lo"
#define LO_FILENAME "/sbin/lo"
#define DP8390_ISA_NAME "dp8390_isa"
77,6 → 81,9
#define IP_NAME "ip"
#define IP_FILENAME "/sbin/ip"
 
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call )
#define IPC_GET_COUNT( call ) ( int ) IPC_GET_ARG2( * call )
 
typedef struct module_struct module_t;
typedef module_t * module_ref;
 
140,12 → 147,14
measured_strings_t configuration;
};
 
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 );
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_start_module( async_client_conn_t client_connection );
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 networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
//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 );
161,6 → 170,10
 
GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t )
 
void networking_print_name( void ){
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 ){
ERROR_DECLARE;
 
182,63 → 195,46
return EOK;
}
 
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ){
ipc_callid_t callid;
ipc_call_t call;
ipcarg_t arg1, arg2, arg3;
int res;
 
/*
* 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 );
 
while( true ){
callid = async_get_call( & call );
arg1 = 0;
arg2 = 0;
arg3 = 0;
// printf( "\nNET-%d got %d on %x from %x", fibril_get_id(), IPC_GET_METHOD( call ), call.in_phone_hash, callid );
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
#ifdef NETWORKING_module
//TODO map to *_message
if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
return ip_message( callid, call, answer, answer_count );
/* }else if( IS_NET_ARP_MESSAGE( call )){
res = arp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
return arp_message( callid, call, answer, answer_count );
*//* }else if( IS_NET_RARP_MESSAGE( call )){
res = rarp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
return rarp_message( callid, call, answer, answer_count );
*//* }else if( IS_NET_ICMP_MESSAGE( call )){
res = icmp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
return icmp_message( callid, call, answer, answer_count );
*//* }else if( IS_NET_UDP_MESSAGE( call )){
res = udp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
return udp_message( callid, call, answer, answer_count );
*/ }else if( IS_NET_TCP_MESSAGE( call )){
res = tcp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
return tcp_message( callid, call, answer, answer_count );
/* }else if( IS_NET_SOCKET_MESSAGE( call )){
res = socket_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
return socket_message( callid, call, answer, answer_count );
*//* }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 );
return ethernet_message( callid, call, answer, answer_count );
*/ }else{
#endif
res = networking_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
if( IS_NET_PACKET_MESSAGE( call )){
return packet_server_message( callid, call, answer, answer_count );
}else{
return net_message( callid, call, answer, answer_count );
}
#ifdef NETWORKING_module
}
#endif
ipc_answer_2( callid, res, arg1, arg2 );
}
}
 
int main( int argc, char * argv[] ){
int networking_start_module( async_client_conn_t client_connection ){
ERROR_DECLARE;
 
ipcarg_t phonehash;
 
printf("\nTask %d - HelenOS Networking subsystem", task_get_id());
 
async_set_client_connection( client_connection );
ERROR_PROPAGATE( networking_initialize());
ERROR_PROPAGATE( REGISTER_ME( SERVICE_NETWORKING, & phonehash ));
 
ERROR_PROPAGATE( pm_init());
async_manager();
 
return EOK;
300,7 → 296,8
return EOK;
}
 
int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
//TODO as ip.c
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
ERROR_DECLARE;
 
measured_string_ref strings;
310,25 → 307,23
measured_strings_ref configuration;
netif_ref netif;
 
switch( method ){
* answer_count = 0;
switch( IPC_GET_METHOD( * call )){
case IPC_M_PHONE_HUNGUP:
return EOK;
case NET_NET_DEVICE:
// TODO configure, register
// arg1 = netif id
printf( "\nNetworking: new netif %d", arg1 );
printf( "\nNetworking: new netif %d", IPC_GET_DEVICE( call ));
return EOK;
case NET_NET_GET_DEVICE_CONF:
// arg1 = netif id
// arg2 = count
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg2 ));
netif = netifs_find( & networking_globals.netifs, arg1 );
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
netif = netifs_find( & networking_globals.netifs, IPC_GET_DEVICE( call ));
if( netif ){
configuration = & netif->configuration;
}else{
configuration = NULL;
}
for( index = 0; index < arg2; ++ index ){
for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
setting = measured_strings_find( configuration, strings[ index ].value, 0 );
if( ! setting ){
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
343,13 → 338,13
}
// strings should not contain received data anymore
free( data );
ERROR_CODE = measured_strings_reply( strings, arg2 );
ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
free( strings );
return ERROR_CODE;
case NET_NET_GET_CONF:
// arg1 = count
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg1 ));
for( index = 0; index < arg1; ++ index ){
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
if( setting ){
strings[ index ].length = setting->length;
361,7 → 356,7
}
// strings should not contain received data anymore
free( data );
ERROR_CODE = measured_strings_reply( strings, arg1 );
ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
free( strings );
return ERROR_CODE;
case NET_NET_STARTUP:
/branches/network/uspace/srv/net/networking/Makefile
26,6 → 26,8
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
NAME = networking
 
## Setup toolchain
#
 
39,14 → 41,19
## Sources
#
 
OUTPUT = networking
OUTPUT = $(NAME)
SOURCES = \
networking.c \
$(NAME).c \
../module.c \
../modules.c \
../structures/char_map.c \
../structures/measured_strings.c
../structures/measured_strings.c \
../structures/packet/packet.c \
../structures/packet/packet_server.c
# ../self_test.c
 
DEFS += -D $(NAME)_message=module_message -D $(NAME)_start_module=module_start -D $(NAME)_print_name=module_print_name
 
DEFS += -D NETWORKING_$(NETWORKING)
 
ifeq ($(NETWORKING), module)