Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3684 → Rev 3685

/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