Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4242 → Rev 4243

/branches/network/uspace/srv/net/netif/netif.c
49,16 → 49,13
#include "../structures/packet/packet_client.h"
#include "../structures/measured_strings.h"
 
#include "device.h"
#include "../include/device.h"
#include "../include/netif_messages.h"
 
#include "netif.h"
#include "netif_interface.h"
#include "netif_wrappers.h"
 
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call )
#define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call )
#define IPC_GET_IRQ( call ) ( int ) IPC_GET_ARG2( * call )
#define IPC_GET_IO( call ) ( int ) IPC_GET_ARG3( * call )
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call )
 
extern netif_globals_t netif_globals;
 
DEVICE_MAP_IMPLEMENT( device_map, device_t )
67,6 → 64,57
int netif_start_module( async_client_conn_t client_connection );
int register_message( device_id_t device_id, int phone );
 
int netif_probe_wrapper( device_id_t device_id, int irq, int io ){
int result;
 
rwlock_write_lock( & netif_globals.lock );
result = netif_probe_message( device_id, irq, io );
rwlock_write_unlock( & netif_globals.lock );
return result;
}
 
int netif_send_wrapper( device_id_t device_id, packet_t packet ){
int result;
 
rwlock_write_lock( & netif_globals.lock );
result = netif_send_message( device_id, packet );
rwlock_write_unlock( & netif_globals.lock );
return result;
}
 
int netif_start_wrapper( device_id_t device_id ){
int result;
 
rwlock_write_lock( & netif_globals.lock );
result = netif_start_message( device_id );
rwlock_write_unlock( & netif_globals.lock );
return result;
}
 
int netif_stop_wrapper( device_id_t device_id ){
int result;
 
rwlock_write_lock( & netif_globals.lock );
result = netif_stop_message( device_id );
rwlock_write_unlock( & netif_globals.lock );
return result;
}
 
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address ){
ERROR_DECLARE;
 
measured_string_t translation;
 
if( ! address ) return EBADMEM;
rwlock_read_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
* address = measured_string_create_bulk( translation.value, translation.length );
ERROR_CODE = ( * address ) ? EOK : ENOMEM;
}
rwlock_read_unlock( & netif_globals.lock );
return ERROR_CODE;
}
 
int find_device( device_id_t device_id, device_ref * device ){
if( ! device ) return EBADMEM;
* device = device_map_find( & netif_globals.device_map, device_id );
105,31 → 153,21
return EOK;
case NET_NETIF_PROBE_AUTO:
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = probe_auto_message();
ERROR_CODE = netif_probe_auto_message();
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_PROBE:
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
return netif_probe_wrapper( NETIF_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
case IPC_M_CONNECT_TO_ME:
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
ERROR_CODE = register_message( NETIF_GET_DEVICE( call ), IPC_GET_PHONE( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_SEND:
rwlock_write_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )))){
ERROR_CODE = send_message( IPC_GET_DEVICE( call ), packet );
}
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, NETIF_GET_PACKET( call )));
return netif_send_wrapper( NETIF_GET_DEVICE( call ), packet );
case NET_NETIF_START:
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = start_message( IPC_GET_DEVICE( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
return netif_start_wrapper( NETIF_GET_DEVICE( call ));
case NET_NETIF_STATS:
rwlock_read_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
136,7 → 174,7
if( length < sizeof( device_stats_t )){
ERROR_CODE = EOVERFLOW;
}else{
if( ! ERROR_OCCURRED( get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
if( ! ERROR_OCCURRED( netif_get_device_stats( NETIF_GET_DEVICE( call ), & stats ))){
ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
}
}
144,19 → 182,16
rwlock_read_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_STOP:
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = stop_message( IPC_GET_DEVICE( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
return netif_stop_wrapper( NETIF_GET_DEVICE( call ));
case NET_NETIF_GET_ADDR:
rwlock_read_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( get_addr_message( IPC_GET_DEVICE( call ), & address ))){
if( ! ERROR_OCCURRED( netif_get_addr_message( NETIF_GET_DEVICE( call ), & address ))){
ERROR_CODE = measured_strings_reply( & address, 1 );
}
rwlock_read_unlock( & netif_globals.lock );
return ERROR_CODE;
}
return specific_message( callid, call, answer, answer_count );
return netif_specific_message( callid, call, answer, answer_count );
}
 
int netif_start_module( async_client_conn_t client_connection ){
167,7 → 202,7
device_map_initialize( & netif_globals.device_map );
ERROR_PROPAGATE( pm_init());
rwlock_initialize( & netif_globals.lock );
if( ERROR_OCCURRED( initialize())){
if( ERROR_OCCURRED( netif_initialize())){
pm_destroy();
return ERROR_CODE;
}