Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4191 → Rev 4192

/branches/network/uspace/srv/net/netif/netif.c
35,11 → 35,11
 
#include <async.h>
#include <mem.h>
#include <rwlock.h>
#include <stdio.h>
 
#include <ipc/ipc.h>
#include <ipc/services.h>
//#include <sys/mman.h>
 
#include "../err.h"
#include "../messages.h"
51,6 → 51,7
 
#include "device.h"
#include "netif.h"
#include "netif_interface.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 )
60,22 → 61,12
 
extern netif_globals_t netif_globals;
 
extern int initialize( void );
extern int probe_auto_message( void );
extern int probe_message( device_id_t device_id, int irq, int io );
extern int send_message( device_id_t device_id, packet_t packet );
extern int start_message( device_id_t device_id );
extern int stop_message( device_id_t device_id );
extern measured_string_ref get_addr_message( device_id_t device_id );
 
DEVICE_MAP_IMPLEMENT( device_map, device_t )
 
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
int netif_start_module( async_client_conn_t client_connection );
int register_message( device_id_t device_id, int phone );
int get_device_stats( device_id_t device_id, device_stats_ref * stats );
 
 
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 );
84,17 → 75,6
return EOK;
}
 
int get_device_stats( device_id_t device_id, device_stats_ref * stats ){
ERROR_DECLARE;
 
device_ref device;
 
if( ! stats ) return EBADMEM;
ERROR_PROPAGATE( find_device( device_id, & device ));
* stats = & device->stats;
return EOK;
}
 
void null_device_stats( device_stats_ref stats ){
bzero( stats, sizeof( device_stats_t ));
}
115,38 → 95,68
ERROR_DECLARE;
 
size_t length;
device_stats_ref stats;
device_stats_t stats;
packet_t packet;
measured_string_ref address;
measured_string_t address;
 
// printf( "\nNETIF message %d", method );
* answer_count = 0;
switch( IPC_GET_METHOD( * call )){
case IPC_M_PHONE_HUNGUP:
return EOK;
case NET_NETIF_PROBE_AUTO:
return probe_auto_message();
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = probe_auto_message();
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_PROBE:
return probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call ));
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;
case IPC_M_CONNECT_TO_ME:
return register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_SEND:
ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )));
return send_message( IPC_GET_DEVICE( call ), packet );
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;
case NET_NETIF_START:
return start_message( IPC_GET_DEVICE( call ));
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = start_message( IPC_GET_DEVICE( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_STATS:
ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length ));
if( length < sizeof( device_stats_t )) return EOVERFLOW;
ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats ));
return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t ));
rwlock_read_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
if( length < sizeof( device_stats_t )){
ERROR_CODE = EOVERFLOW;
}else{
if( ! ERROR_OCCURRED( get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
}
}
}
rwlock_read_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_STOP:
return stop_message( IPC_GET_DEVICE( call ));
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = stop_message( IPC_GET_DEVICE( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_GET_ADDR:
address = get_addr_message( IPC_GET_DEVICE( call ));
return address ? measured_strings_reply( address, 1 ) : ENOENT;
rwlock_read_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( get_addr_message( IPC_GET_DEVICE( call ), & address ))){
ERROR_CODE = measured_strings_reply( & address, 1 );
}
rwlock_read_unlock( & netif_globals.lock );
return ERROR_CODE;
}
return ENOTSUP;
return specific_message( callid, call, answer, answer_count );
}
 
int netif_start_module( async_client_conn_t client_connection ){
156,6 → 166,7
netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
device_map_initialize( & netif_globals.device_map );
ERROR_PROPAGATE( pm_init());
rwlock_initialize( & netif_globals.lock );
if( ERROR_OCCURRED( initialize())){
pm_destroy();
return ERROR_CODE;
167,5 → 178,13
return EOK;
}
 
void netif_pq_release( packet_id_t packet_id ){
pq_release( netif_globals.networking_phone, packet_id );
}
 
packet_t netif_packet_get_1( size_t content ){
return packet_get_1( netif_globals.networking_phone, content );
}
 
/** @}
*/