Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4260 → Rev 4261

/branches/network/uspace/srv/net/netif/netif.c
51,11 → 51,18
 
#include "../include/device.h"
#include "../include/netif_messages.h"
#include "../include/nil_messages.h"
 
#include "netif.h"
#include "netif_interface.h"
#include "netif_wrappers.h"
 
#if NIL_BUNDLE
 
#include "../nil/nil_module.h"
 
#endif
 
extern netif_globals_t netif_globals;
 
DEVICE_MAP_IMPLEMENT( device_map, device_t )
73,43 → 80,85
return result;
}
 
int netif_send_wrapper( device_id_t device_id, packet_t packet ){
int netif_send_wrapper( device_id_t device_id, packet_t packet, services_t sender ){
int result;
 
rwlock_write_lock( & netif_globals.lock );
result = netif_send_message( device_id, packet );
result = netif_send_message( device_id, packet, sender );
rwlock_write_unlock( & netif_globals.lock );
return result;
}
 
int netif_start_wrapper( device_id_t device_id ){
ERROR_DECLARE;
 
device_ref device;
int result;
int phone;
 
rwlock_write_lock( & netif_globals.lock );
result = netif_start_message( device_id );
rwlock_write_unlock( & netif_globals.lock );
if( ERROR_OCCURRED( find_device( device_id, & device ))){
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
}
result = netif_start_message( device );
if( result > NETIF_NULL ){
phone = device->nil_phone;
rwlock_write_unlock( & netif_globals.lock );
nil_device_state_msg( phone, device_id, result );
return EOK;
}else{
rwlock_write_unlock( & netif_globals.lock );
}
return result;
}
 
int netif_stop_wrapper( device_id_t device_id ){
ERROR_DECLARE;
 
device_ref device;
int result;
int phone;
 
rwlock_write_lock( & netif_globals.lock );
result = netif_stop_message( device_id );
rwlock_write_unlock( & netif_globals.lock );
if( ERROR_OCCURRED( find_device( device_id, & device ))){
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
}
result = netif_stop_message( device );
if( result > NETIF_NULL ){
phone = device->nil_phone;
rwlock_write_unlock( & netif_globals.lock );
nil_device_state_msg( phone, device_id, result );
return EOK;
}else{
rwlock_write_unlock( & netif_globals.lock );
}
return result;
}
 
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address ){
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address, char ** data ){
ERROR_DECLARE;
 
measured_string_t translation;
 
if( ! address ) return EBADMEM;
if( !( address && data )) 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;
// * address = measured_string_create_bulk( translation.value, translation.length );
* address = ( measured_string_ref ) malloc( sizeof( measured_string_t ));
if( * address ){
* data = ( char * ) malloc( translation.length + 1 );
if( * data ){
memcpy( * data, translation.value, translation.length + 1 );
( ** address ).value = * data;
( ** address ).length = translation.length;
rwlock_read_unlock( & netif_globals.lock );
return EOK;
}
free( * address );
}
ERROR_CODE = ENOMEM;
}
rwlock_read_unlock( & netif_globals.lock );
return ERROR_CODE;
147,6 → 196,12
packet_t packet;
measured_string_t address;
 
// printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_NETIF_FIRST );
#if NIL_BUNDLE
if( IS_NET_NIL_MESSAGE( call )){
return nil_message( callid, call, answer, answer_count );
}
#endif
* answer_count = 0;
switch( IPC_GET_METHOD( * call )){
case IPC_M_PHONE_HUNGUP:
157,17 → 212,22
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_PROBE:
return netif_probe_wrapper( NETIF_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
return netif_probe_wrapper( IPC_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
case IPC_M_CONNECT_TO_ME:
#if NIL_BUNDLE
return nil_register_message( NIL_GET_PROTO( call ), IPC_GET_PHONE( call ));
#else
rwlock_write_lock( & netif_globals.lock );
ERROR_CODE = register_message( NETIF_GET_DEVICE( call ), IPC_GET_PHONE( call ));
ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
rwlock_write_unlock( & netif_globals.lock );
return ERROR_CODE;
#endif
case NET_NETIF_SEND:
ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, NETIF_GET_PACKET( call )));
return netif_send_wrapper( NETIF_GET_DEVICE( call ), packet );
case NET_NIL_SEND:
ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )));
return netif_send_wrapper( IPC_GET_DEVICE( call ), packet, IPC_GET_SENDER( call ));
case NET_NETIF_START:
return netif_start_wrapper( NETIF_GET_DEVICE( call ));
return netif_start_wrapper( IPC_GET_DEVICE( call ));
case NET_NETIF_STATS:
rwlock_read_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
174,7 → 234,7
if( length < sizeof( device_stats_t )){
ERROR_CODE = EOVERFLOW;
}else{
if( ! ERROR_OCCURRED( netif_get_device_stats( NETIF_GET_DEVICE( call ), & stats ))){
if( ! ERROR_OCCURRED( netif_get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
}
}
182,10 → 242,11
rwlock_read_unlock( & netif_globals.lock );
return ERROR_CODE;
case NET_NETIF_STOP:
return netif_stop_wrapper( NETIF_GET_DEVICE( call ));
return netif_stop_wrapper( IPC_GET_DEVICE( call ));
case NET_NETIF_GET_ADDR:
case NET_NIL_ADDR:
rwlock_read_lock( & netif_globals.lock );
if( ! ERROR_OCCURRED( netif_get_addr_message( NETIF_GET_DEVICE( call ), & address ))){
if( ! ERROR_OCCURRED( netif_get_addr_message( IPC_GET_DEVICE( call ), & address ))){
ERROR_CODE = measured_strings_reply( & address, 1 );
}
rwlock_read_unlock( & netif_globals.lock );
206,6 → 267,12
pm_destroy();
return ERROR_CODE;
}
#if NIL_BUNDLE
if( ERROR_OCCURRED( nil_initialize( netif_globals.networking_phone ))){
pm_destroy();
return ERROR_CODE;
}
#endif
 
async_manager();