/branches/network/uspace/srv/net/tcp/tcp.c |
---|
53,14 → 53,14 |
int tcp_initialize( void ){ |
ERROR_DECLARE; |
ipcarg_t arg1, arg2; |
/* ipcarg_t arg1, arg2; |
// printf( "TCP - testing to send IP:\t" ); |
// ERROR_PROPAGATE( ip_message( NET_IP_ECHO, 12, 34, NULL, & arg1, & arg2, NULL )); |
// if(( arg1 != 12 ) || ( arg2 != 34 )) return EINVAL; |
// printf( "OK\n" ); |
// ERROR_PROPAGATE( ip_message( NET_IP_TCP_REGISTER, NULL, NULL, NULL, NULL, NULL, NULL )); |
printf( "\nTCP - testing to send IP:\t" ); |
ERROR_PROPAGATE( ip_message( NET_IP_ECHO, 12, 34, NULL, & arg1, & arg2, NULL )); |
if(( arg1 != 12 ) || ( arg2 != 34 )) return EINVAL; |
printf( "OK\n" ); |
*/ |
ERROR_PROPAGATE( ip_message( NET_IP_TCP_REGISTER, SERVICE_TCP, NULL, NULL, NULL, NULL, NULL )); |
return EOK; |
} |
70,7 → 70,6 |
int tcp_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
switch( method ){ |
// case IPC_M_CONNECT_ME_TO: |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
} |
/branches/network/uspace/srv/net/tcp/tcp.h |
---|
49,7 → 49,7 |
typedef struct tcp_globals tcp_globals_t; |
struct tcp_globals{ |
struct tcp_globals{ |
int ip_phone; |
int networking_phone; |
}; |
/branches/network/uspace/srv/net/networking/networking.c |
---|
184,6 → 184,7 |
int res; |
/* Accept the connection */ |
// 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 ){ |
191,6 → 192,7 |
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 ); |
#ifdef NETWORKING_module |
if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){ |
res = ip_call( callid ); |
247,7 → 249,7 |
int main( int argc, char * argv[] ){ |
printf("\nTask %d - Networking: HelenOS Networking subsystem\n", task_get_id()); |
printf("\nTask %d - HelenOS Networking subsystem", task_get_id()); |
return start_service( SERVICE_NETWORKING, NULL, NULL, client_connection, networking_initialize ); |
} |
322,9 → 324,7 |
measured_strings_ref configuration; |
netif_ref netif; |
// printf( "\nNetworking message: %d\n", method ); |
switch( method ){ |
// case IPC_M_CONNECT_ME_TO: |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NETWORKING_DEVICE: |
456,6 → 456,7 |
netif_ref netif; |
measured_string_ref setting; |
services_t internet_service; |
int index; |
// read general configuration |
ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" )); |
463,24 → 464,24 |
// read network interfaces configuration |
// static loopback initialization |
printf( "\nloopback 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_OCCURED( add_configuration( & netif->configuration, "NAME", LO_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "NETIF", LO_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IL", IP_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "NETMASK", "255.255.255.255" )) |
){ |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "NETIF", LO_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IL", IP_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "MTU", "1500" )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ))){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
// mandatory name |
printf( "\n\tname" ); |
// printf( "\n\tname" ); |
setting = measured_strings_find( & netif->configuration, "NAME" ); |
if( ! setting ){ |
measured_strings_destroy( & netif->configuration ); |
488,12 → 489,12 |
return EINVAL; |
} |
netif->name = setting->value; |
printf( " %s OK", netif->name ); |
// printf( " %s OK", netif->name ); |
// mandatory netif |
printf( "\n\tnetif" ); |
// printf( "\n\tnetif" ); |
setting = measured_strings_find( & netif->configuration, "NETIF" ); |
if( ! setting ){ |
printf( " unknown" ); |
// printf( " unknown" ); |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
501,13 → 502,13 |
// 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 ){ |
printf( " not found" ); |
// printf( " not found" ); |
// TODO register the unknown one |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
printf( " found" ); |
// printf( " found" ); |
if( ! netif->driver_module->task_id ){ |
netif->driver_module->task_id = spawn( netif->driver_module->filename ); |
if( ! netif->driver_module->task_id ){ |
516,20 → 517,9 |
return EINVAL; |
} |
} |
if( ! netif->driver_module->phone ){ |
printf( " connect?" ); |
netif->driver_module->phone = connect_to_service( netif->driver_module->service ); |
} |
printf( " connected" ); |
if( ERROR_OCCURED( ipc_call_sync_1_0( netif->driver_module->phone, NET_NETIF_PROBE, netif->id ))){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
++ netif->driver_module->usage; |
printf( " OK" ); |
// printf( " OK" ); |
// optional link layer |
printf( "\n\tlink layer" ); |
// printf( "\n\tlink layer" ); |
setting = measured_strings_find( & netif->configuration, "LL" ); |
if( setting ){ |
netif->link_layer_module = modules_find( & networking_globals.modules, setting->value ); |
549,24 → 539,11 |
return EINVAL; |
} |
} |
if( ! netif->link_layer_module->phone ){ |
netif->link_layer_module->phone = connect_to_service( netif->link_layer_module->service ); |
} |
if( ERROR_OCCURED( ipc_call_sync_2_0( netif->link_layer_module->phone, NET_LL_DEVICE, netif->id, netif->driver_module->service ))){ |
-- netif->driver_module->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
++ netif->link_layer_module->usage; |
internet_service = netif->link_layer_module->service; |
printf( " OK" ); |
}else{ |
internet_service = netif->driver_module->service; |
printf( " none" ); |
netif->link_layer_module = NULL; |
} |
// mandatory internet layer |
printf( "\n\tinternet layer" ); |
// printf( "\n\tinternet layer" ); |
setting = measured_strings_find( & netif->configuration, "IL" ); |
if( ! setting ){ |
-- netif->driver_module->usage; |
575,7 → 552,7 |
free( netif ); |
return EINVAL; |
} |
printf( " set %s", setting->value ); |
// printf( " set %s", setting->value ); |
netif->internet_layer_module = modules_find( & networking_globals.modules, setting->value ); |
if( ! netif->internet_layer_module ){ |
// TODO register the unknown one |
585,7 → 562,7 |
free( netif ); |
return EINVAL; |
} |
printf( " found" ); |
// 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 ){ |
596,23 → 573,45 |
return EINVAL; |
} |
} |
if( ! netif->internet_layer_module->phone ){ |
printf( " connect" ); |
netif->internet_layer_module->phone = connect_to_service( netif->internet_layer_module->service ); |
} |
if( ERROR_OCCURED( ipc_call_sync_2_0( netif->internet_layer_module->phone, NET_IL_DEVICE, netif->id, internet_service ))){ |
measured_strings_destroy( & netif->configuration ); |
index = netifs_add( & networking_globals.netifs, netif->id, netif ); |
if( index < 0 ){ |
free( netif ); |
return ERROR_CODE; |
} |
++ netif->internet_layer_module->usage; |
printf( " OK" ); |
if( ERROR_OCCURED( netifs_add( & networking_globals.netifs, netif->id, netif ))){ |
free( netif ); |
if( ERROR_OCCURED( char_map_add( & networking_globals.netif_names, netif->name, index ))){ |
netifs_exclude_index( & networking_globals.netifs, index ); |
return ERROR_CODE; |
} |
printf( "\nloopback OK" ); |
// end of static loopback initialization |
// printf( "\nloopback OK" ); |
// end of the static loopback initialization |
// startup the loopback interface |
if( ! netif->driver_module->phone ){ |
// printf( " connect?" ); |
netif->driver_module->phone = connect_to_service( netif->driver_module->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 ); |
} |
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; |
// printf( " OK" ); |
}else{ |
internet_service = netif->driver_module->service; |
// printf( " none" ); |
} |
if( ! netif->internet_layer_module->phone ){ |
// printf( " connect" ); |
netif->internet_layer_module->phone = connect_to_service( netif->internet_layer_module->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 )); |
// printf( "\n LO OK" ); |
return EOK; |
} |
/branches/network/uspace/srv/net/modules.c |
---|
42,14 → 42,13 |
#define MODULE_WAIT_TIME 10000 |
int connect_to_service( services_t need ){ |
int phone; |
ipcarg_t phone; |
int res; |
phone = ipc_connect_me_to( PHONE_NS, need, 0, 0 ); |
if( phone < 0 ){ |
do{ |
usleep( MODULE_WAIT_TIME ); |
phone = ipc_connect_me_to( PHONE_NS, need, 0, 0 ); |
}while( phone < 0 ); |
res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, & phone ); |
while(( res < 0 ) || ( phone < 0 )){ |
usleep( MODULE_WAIT_TIME ); |
res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, & phone ); |
} |
return phone; |
} |
/branches/network/uspace/srv/net/messages.h |
---|
109,12 → 109,12 |
NET_NETWORKING_GET_DEVICE_CONFIGURATION, |
NET_NETWORKING_STARTUP, |
NET_LL_DEVICE = NET_LL_FIRST, |
NET_LL_DEVICE_STATUS_CHANGED, |
NET_LL_DEVICE_STATE_CHANGED, |
NET_LL_MTU_CHANGED, |
NET_LL_RECEIVED, |
NET_LL_REGISTER, |
NET_IL_DEVICE = NET_IL_FIRST, |
NET_IL_DEVICE_STATUS_CHANGED, |
NET_IL_DEVICE_STATE_CHANGED, |
NET_IP_CONFIGURATION_DHCP = NET_IP_FIRST, |
NET_IP_CONFIGURATION_STATIC, |
NET_IP_ECHO, |
/branches/network/uspace/srv/net/measured_strings.c |
---|
36,6 → 36,7 |
#include <errno.h> |
#include <malloc.h> |
#include <stdio.h> |
#include <string.h> |
#include <unistd.h> |
#include <ipc/ipc.h> |
69,17 → 70,14 |
char * next; |
ipc_callid_t callid; |
if(( ! strings ) || ( !( * data )) || ( count <= 0 )){ |
if(( ! strings ) || ( ! data ) || ( count <= 0 )){ |
return EINVAL; |
} |
lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
if( ! lengths ) return ENOMEM; |
if( ERROR_OCCURED( ipc_data_write_receive( & callid, & length ))){ |
if(( ! ipc_data_write_receive( & callid, & length )) |
|| ( length != sizeof( size_t ) * ( count + 1 ))){ |
free( lengths ); |
return ERROR_CODE; |
} |
if( length < sizeof( size_t ) * ( count + 1 )){ |
free( lengths ); |
return EINVAL; |
} |
if( ERROR_OCCURED( ipc_data_write_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){ |
88,6 → 86,7 |
} |
* data = malloc( lengths[ count ] ); |
if( !( * data )) return ENOMEM; |
( * data )[ lengths[ count ] - 1 ] = '\0'; |
* strings = ( measured_string_ref ) malloc( sizeof( measured_string_t ) * count ); |
if( !( * strings )){ |
free( lengths ); |
98,8 → 97,8 |
for( index = 0; index < count; ++ index ){ |
( * strings)[ index ].length = lengths[ index ]; |
if( lengths[ index ] > 0 ){ |
ERROR_PROPAGATE( ipc_data_write_receive( & callid, & length )); |
if( length < lengths[ index ] + 1 ){ |
if(( ! ipc_data_write_receive( & callid, & length )) |
|| ( length != lengths[ index ] )){ |
free( * data ); |
free( * strings ); |
free( lengths ); |
106,6 → 105,7 |
return EINVAL; |
} |
ERROR_PROPAGATE( ipc_data_write_finalize( callid, next, lengths[ index ] )); |
( * strings)[ index ].value = next; |
next += lengths[ index ]; |
* next = '\0'; |
++ next; |
130,12 → 130,9 |
} |
lengths = prepare_lengths( strings, count ); |
if( ! lengths ) return ENOMEM; |
if( ERROR_OCCURED( ipc_data_read_receive( & callid, & length ))){ |
if(( ! ipc_data_read_receive( & callid, & length )) |
|| ( length != sizeof( size_t ) * ( count + 1 ))){ |
free( lengths ); |
return ERROR_CODE; |
} |
if( length < strings[ index ].length + 1 ){ |
free( lengths ); |
return EINVAL; |
} |
if( ERROR_OCCURED( ipc_data_read_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){ |
145,8 → 142,8 |
free( lengths ); |
for( index = 0; index < count; ++ index ){ |
if( strings[ index ].length > 0 ){ |
ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length )); |
if( length < strings[ index ].length + 1 ){ |
if(( ! ipc_data_read_receive( & callid, & length )) |
|| ( length != strings[ index ].length )){ |
return EINVAL; |
} |
ERROR_PROPAGATE( ipc_data_read_finalize( callid, strings[ index ].value, strings[ index ].length )); |
162,7 → 159,7 |
int index; |
char * next; |
if(( phone <= 0 ) || ( ! strings ) || ( !( * data )) || ( count <= 0 )){ |
if(( phone <= 0 ) || ( ! strings ) || ( ! data ) || ( count <= 0 )){ |
return EINVAL; |
} |
lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
183,8 → 180,8 |
for( index = 0; index < count; ++ index ){ |
( * strings )[ index ].length = lengths[ index ]; |
if( lengths[ index ] > 0 ){ |
ERROR_PROPAGATE( ipc_data_read_start( phone, next, lengths[ index ] )); |
( * strings )[ index ].value = next; |
ERROR_PROPAGATE( ipc_data_read_start( phone, next, lengths[ index ] )); |
next += lengths[ index ]; |
* next = '\0'; |
++ next; |
214,7 → 211,7 |
free( lengths ); |
for( index = 0; index < count; ++ index ){ |
if( strings[ index ].length > 0 ){ |
ERROR_PROPAGATE( ipc_data_write_start( phone, strings[ index ].value, strings[ index ].length + 1 )); |
ERROR_PROPAGATE( ipc_data_write_start( phone, strings[ index ].value, strings[ index ].length )); |
} |
} |
return EOK; |
/branches/network/uspace/srv/net/measured_strings.h |
---|
41,8 → 41,8 |
typedef measured_string_t * measured_string_ref; |
struct measured_string{ |
char * value; |
size_t length; |
char * value; |
}; |
measured_string_ref measured_string_create_bulk( const char * string, size_t length ); |
/branches/network/uspace/srv/net/netif/netif.c |
---|
64,7 → 64,7 |
int netif_device_find( netif_device_id_t device_id, netif_device_ref * device ){ |
* device = netif_device_map_find( & netif_globals.netif_device_map, device_id ); |
if( ! * device ) return ENOENT; |
if(( ** device ).status == NETIF_NULL ) return EPERM; |
if(( ** device ).state == NETIF_NULL ) return EPERM; |
return EOK; |
} |
113,8 → 113,7 |
case NET_NETIF_REGISTER: |
case NET_LL_REGISTER: |
ERROR_PROPAGATE( netif_device_find( arg1, & device )); |
// TODO back phone |
device->ll_registered = callid; |
device->ll_registered = connect_to_service( arg2 ); |
return EOK; |
case NET_NETIF_SEND: |
return netif_send_message( arg1, arg2, arg3, result1, result2, result3 ); |
138,7 → 137,7 |
} |
int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){ |
/* services_t need[ 2 ]; |
services_t need[ 2 ]; |
int * need_phone[ 2 ]; |
need[ 0 ] = SERVICE_NETWORKING; |
145,8 → 144,8 |
need[ 1 ] = NULL; |
need_phone[ 0 ] = & netif_globals.networking_phone; |
need_phone[ 1 ] = NULL; |
*/ netif_device_map_initialize( & netif_globals.netif_device_map ); |
return start_service( NULL, /*need, need_phone*/ NULL, NULL, client_connection, netif_initialize ); |
netif_device_map_initialize( & netif_globals.netif_device_map ); |
return start_service( NULL, need, need_phone, client_connection, netif_initialize ); |
} |
/** @} |
/branches/network/uspace/srv/net/netif/lo.c |
---|
41,6 → 41,7 |
//#include <sys/mman.h> |
#include "../err.h" |
#include "../measured_strings.h" |
#include "../messages.h" |
#include "../modules.h" |
52,8 → 53,8 |
netif_globals_t netif_globals; |
void change_status( netif_device_ref device, netif_status_t status ); |
int change_status_message( netif_device_id_t device_id, netif_status_t status ); |
void change_state( netif_device_ref device, netif_state_t state ); |
int change_state_message( netif_device_id_t device_id, netif_state_t state ); |
int netif_create( netif_device_id_t device_id, netif_device_ref * device ); |
int netif_call( ipc_callid_t callid ); |
int netif_initialize( void ); |
64,18 → 65,18 |
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
void change_status( netif_device_ref device, netif_status_t status ){ |
device->status = status; |
ll_message( device, NET_LL_DEVICE_STATUS_CHANGED, device->status, NULL, NULL, NULL, NULL ); |
void change_state( netif_device_ref device, netif_state_t state ){ |
device->state = state; |
ll_message( device, NET_LL_DEVICE_STATE_CHANGED, device->state, NULL, NULL, NULL, NULL ); |
} |
int change_status_message( netif_device_id_t device_id, netif_status_t status ){ |
int change_state_message( netif_device_id_t device_id, netif_state_t state ){ |
ERROR_DECLARE; |
netif_device_ref device; |
ERROR_PROPAGATE( netif_device_find( device_id, & device )); |
change_status( device, status ); |
change_state( device, state ); |
return EOK; |
} |
87,11 → 88,11 |
}else{ |
* device = ( netif_device_ref ) malloc( sizeof( netif_device_t )); |
if( !( * device )) return ENOMEM; |
// ( ** device ).device_id = netif_device_id_generate( 1 ); |
( ** device ).device_id = device_id; |
( ** device ).ll_registered = NULL; |
( ** device ).ll_registered = -1; |
( ** device ).specific = NULL; |
netif_device_stats_null( &(( ** device ).stats )); |
( ** device ).status = NETIF_STOPPED; |
( ** device ).state = NETIF_STOPPED; |
( ** device ).flags = NULL; |
( ** device ).mtu = DEFAULT_MTU; |
if( ERROR_OCCURED( netif_device_map_add( & netif_globals.netif_device_map, ( ** device ).device_id, * device ))){ |
108,7 → 109,7 |
} |
int netif_initialize( void ){ |
int phonehash; |
ipcarg_t phonehash; |
return REGISTER_ME( SERVICE_LO, & phonehash ); |
} |
118,13 → 119,13 |
} |
int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
ERROR_DECLARE; |
/* ERROR_DECLARE; |
netif_device_ref device; |
ERROR_PROPAGATE( netif_create( arg1, & device )); |
networking_message( NET_NETWORKING_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
return EOK; |
ipc_call_sync_3_3( netif_globals.networking_phone, NET_NETWORKING_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
*/ return ENOTSUP; |
} |
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
131,8 → 132,35 |
ERROR_DECLARE; |
netif_device_ref device; |
aid_t message; |
ipc_call_t answer; |
measured_string_t configuration[ 1 ] = {{ "MTU", 3 }}; |
int count = 1; |
measured_string_ref settings; |
char * data; |
// create a new device |
ERROR_PROPAGATE( netif_create( arg1, & device )); |
// get configuration |
message = async_send_2( netif_globals.networking_phone, NET_NETWORKING_GET_DEVICE_CONFIGURATION, device->device_id, count, & answer ); |
// send names and get settings |
if( ERROR_OCCURED( measured_strings_send( netif_globals.networking_phone, configuration, count )) |
|| ERROR_OCCURED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){ |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
// MTU is the first one |
if( settings && ( settings[ 0 ].value )){ |
device->mtu = strtoul( settings[ 0 ].value, NULL, 0 ); |
}else{ |
device->mtu = DEFAULT_MTU; |
} |
// print the settings |
printf("\n -MTU=%d", device->mtu ); |
free( settings ); |
free( data ); |
// end request |
async_wait_for( message, NULL ); |
return EOK; |
} |
142,7 → 170,7 |
netif_device_ref device; |
ERROR_PROPAGATE( netif_device_find( arg1, & device )); |
if( device->status == NETIF_ACTIVE ){ |
if( device->state == NETIF_ACTIVE ){ |
++ device->stats.tx_packets; |
++ device->stats.rx_packets; |
// TODO packet size |
156,11 → 184,11 |
} |
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
return change_status_message( arg1, NETIF_ACTIVE ); |
return change_state_message( arg1, NETIF_ACTIVE ); |
} |
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
return change_status_message( arg1, NETIF_STOPPED ); |
return change_state_message( arg1, NETIF_STOPPED ); |
} |
/** @} |
/branches/network/uspace/srv/net/netif/netif.h |
---|
39,18 → 39,10 |
#include "netif_device_id_type.h" |
#define networking_message( ... ) \ |
if( netif_globals.networking_phone ) ipc_call_sync_3_3( netif_globals.networking_phone, __VA_ARGS__ ) |
#define ll_message( device, message, arg2, arg3, result1, result2, result3 ) \ |
if(( device )->ll_registered ) async_msg_3(( device )->ll_registered, ( message ), ( device )->device_id, arg2, arg3 ) |
if(( device )->ll_registered >= 0 ) async_msg_3(( device )->ll_registered, ( message ), ( device )->device_id, arg2, arg3 ) |
typedef enum netif_status{ |
NETIF_NULL = 0, |
NETIF_STOPPED, |
NETIF_ACTIVE, |
NETIF_CARRIER_LOST |
} netif_status_t; |
typedef enum netif_state netif_state_t; |
typedef struct netif_device_stats netif_device_stats_t; |
typedef netif_device_stats_t * netif_device_stats_ref; |
60,6 → 52,13 |
DEVICE_MAP_DECLARE( netif_device_map, netif_device_t ); |
enum netif_state{ |
NETIF_NULL = 0, |
NETIF_STOPPED, |
NETIF_ACTIVE, |
NETIF_CARRIER_LOST |
}; |
// based on linux_kernel/include/linux/netdevice.h |
struct netif_device_stats{ |
96,11 → 95,12 |
struct netif_device{ |
netif_device_id_t device_id; |
ipc_callid_t ll_registered; |
int ll_registered; |
netif_device_stats_t stats; |
netif_status_t status; |
netif_state_t state; |
int flags; |
int mtu; |
size_t mtu; |
void * specific; |
}; |
struct netif_globals{ |
/branches/network/uspace/srv/net/netif/Makefile |
---|
43,6 → 43,7 |
OUTPUT = lo #dp8390_isa |
SOURCES = \ |
$(NETIF).c \ |
../measured_strings.h \ |
../module.c \ |
../modules.c |
/branches/network/uspace/srv/net/ip/ip.c |
---|
41,6 → 41,7 |
//#include <sys/mman.h> |
#include "../err.h" |
#include "../measured_strings.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "../netif/netif_device_id_type.h" |
47,10 → 48,14 |
#include "ip.h" |
#define DEFAULT_IPV 4 |
ip_globals_t ip_globals; |
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
int parse_address( char * value, address_ref address ); |
/** Initializes the module. |
*/ |
int ip_initialize( void ){ |
62,15 → 67,35 |
return EOK; |
} |
int parse_address( char * value, address_ref address ){ |
char * next; |
int index; |
if( ! value ){ |
( * address )[ 0 ] = ( * address )[ 1 ] = ( * address )[ 2 ] = ( * address )[ 3 ] = 0; |
return ENOENT; |
} |
next = value; |
for( index = 0; index < 4; ++ index ){ |
if(( ! next ) || ( ! * next )) return EINVAL; |
if( index ) ++ next; |
( * address )[ index ] = strtoul( next, & next, 0 ); |
} |
return EOK; |
} |
int ip_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
ERROR_DECLARE; |
ip_netif_ref ip_netif; |
ip_netif_ref ip_netif; |
aid_t message; |
ipc_call_t answer; |
measured_string_t configuration[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }}; |
int count = 9; |
measured_string_ref settings; |
char * data; |
// printf( "\nIP message %d", method ); |
switch( method ){ |
// case IPC_M_CONNECT_ME_TO: |
// case IPC_M_CONNECT_TO_ME: |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_IP_ECHO: |
82,18 → 107,72 |
ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t )); |
if( ! ip_netif ) return ENOMEM; |
ip_netif->device_id = arg1; |
ip_netif->phone = connect_to_service( arg2 ); |
if( ERROR_OCCURED( ipc_call_sync_1_0( ip_netif->phone, NET_LL_REGISTER, arg1 ))){ |
free( ip_netif ); |
// get configuration |
message = async_send_2( ip_globals.networking_phone, NET_NETWORKING_GET_DEVICE_CONFIGURATION, ip_netif->device_id, count, & answer ); |
// send names and get settings |
if( ERROR_OCCURED( measured_strings_send( ip_globals.networking_phone, configuration, count )) |
|| ERROR_OCCURED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){ |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
if( ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){ |
if( settings ){ |
if( settings[ 0 ].value ){ |
ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 ); |
}else{ |
ip_netif->ipv = DEFAULT_IPV; |
} |
ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" ); |
if( ip_netif->dhcp ){ |
// TODO dhcp |
free( ip_netif ); |
return ENOTSUP; |
}else if( ip_netif->ipv == 4 ){ |
if( ERROR_OCCURED( parse_address( settings[ 2 ].value, & ip_netif->address )) |
|| ERROR_OCCURED( parse_address( settings[ 3 ].value, & ip_netif->netmask )) |
|| ( parse_address( settings[ 4 ].value, & ip_netif->gateway ) == EINVAL ) |
|| ( parse_address( settings[ 5 ].value, & ip_netif->broadcast ) == EINVAL ) |
|| ( parse_address( settings[ 6 ].value, & ip_netif->dns1 ) == EINVAL ) |
|| ( parse_address( settings[ 7 ].value, & ip_netif->dns2 ) == EINVAL )){ |
free( ip_netif ); |
return EINVAL; |
} |
}else{ |
// TODO ipv6 |
free( ip_netif ); |
return ENOTSUP; |
} |
// TODO ARP module |
} |
// print the settings |
printf( "\n -IPV=%d", ip_netif->ipv ); |
printf( "\n -configuration=%s", ip_netif->dhcp ? "dhcp" : "static" ); |
// TODO ipv6 |
printf( "\n -address=%d.%d.%d.%d", ip_netif->address[ 0 ], ip_netif->address[ 1 ], ip_netif->address[ 2 ], ip_netif->address[ 3 ] ); |
printf( "\n -netmask=%d.%d.%d.%d", ip_netif->netmask[ 0 ], ip_netif->netmask[ 1 ], ip_netif->netmask[ 2 ], ip_netif->netmask[ 3 ] ); |
printf( "\n -gateway=%d.%d.%d.%d", ip_netif->gateway[ 0 ], ip_netif->gateway[ 1 ], ip_netif->gateway[ 2 ], ip_netif->gateway[ 3 ] ); |
printf( "\n -broadcast=%d.%d.%d.%d", ip_netif->broadcast[ 0 ], ip_netif->broadcast[ 1 ], ip_netif->broadcast[ 2 ], ip_netif->broadcast[ 3 ] ); |
printf( "\n -dns1=%d.%d.%d.%d", ip_netif->dns1[ 0 ], ip_netif->dns1[ 1 ], ip_netif->dns1[ 2 ], ip_netif->dns1[ 3 ] ); |
printf( "\n -dns2=%d.%d.%d.%d", ip_netif->dns2[ 0 ], ip_netif->dns2[ 1 ], ip_netif->dns2[ 2 ], ip_netif->dns2[ 3 ] ); |
// TODO arp module |
free( settings ); |
free( data ); |
// end request |
async_wait_for( message, NULL ); |
ip_netif->phone = connect_to_service( arg2 ); |
if( ERROR_OCCURED( async_req_2_0( ip_netif->phone, NET_LL_REGISTER, arg1, SERVICE_IP )) |
|| ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){ |
free( ip_netif ); |
return ERROR_CODE; |
} |
return EOK; |
case NET_IL_DEVICE_STATE_CHANGED: |
case NET_LL_DEVICE_STATE_CHANGED: |
// arg1 device id |
// arg2 state |
// TODO state |
printf( "\nip - device %d changed state to %d\n", arg1, arg2 ); |
case NET_IP_TCP_REGISTER: |
ip_globals.tcp_phone = ipc_connect_to_me( callid, 0, 0, 0, 0 ); |
ip_globals.tcp_phone = connect_to_service( arg1 ); |
return EOK; |
} |
return ENOTSUP; |
/branches/network/uspace/srv/net/ip/Makefile |
---|
44,6 → 44,7 |
SOURCES = \ |
$(NAME)_module.c \ |
$(NAME).c \ |
../measured_strings.c \ |
../module.c \ |
../modules.c |
/branches/network/uspace/srv/net/ip/ip.h |
---|
41,6 → 41,11 |
#include "../netif/netif_device_id_type.h" |
#define IP_MAX_ADDRESS_LENGTH 4 |
typedef int address_t[ IP_MAX_ADDRESS_LENGTH ]; |
typedef address_t * address_ref; |
typedef struct ip_netif ip_netif_t; |
typedef ip_netif_t * ip_netif_ref; |
48,13 → 53,21 |
DEVICE_MAP_DECLARE( ip_netifs, ip_netif_t ) |
struct ip_netif{ |
struct ip_netif{ |
netif_device_id_t device_id; |
int phone; |
// TODO configuration |
int ipv; |
int dhcp; |
address_t address; |
address_t netmask; |
address_t gateway; |
address_t broadcast; |
address_t dns1; |
address_t dns2; |
// TODO modules |
}; |
struct ip_globals{ |
struct ip_globals{ |
int networking_phone; |
int tcp_phone; |
ip_netifs_t netifs; |
/branches/network/uspace/srv/net/networking_startup/networking_startup.c |
---|
52,10 → 52,9 |
int main( int argc, char * argv[] ){ |
ERROR_DECLARE; |
ipcarg_t arg1; |
int networking_phone; |
printf( "Task %d - " NAME, task_get_id()); |
printf( "\nTask %d - " NAME, task_get_id()); |
// run self tests |
ERROR_PROPAGATE( self_test()); |
// start networking service |
/branches/network/uspace/srv/net/Makefile |
---|
62,7 → 62,7 |
build: $(BUILDS) |
clean: $(CLEANS) |
find $(DIRS_ALL) -name '*.o' -follow -exec rm \{\} \; |
find $(DIRS_ALL) ./ -name '*.o' -follow -exec rm \{\} \; |
distclean: clean |