Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4306 → Rev 4307

/branches/network/uspace/srv/net/nil/eth/eth.c
53,14 → 53,14
#include "../../include/ethernet_protocols.h"
#include "../../include/protocol_map.h"
#include "../../include/device.h"
#include "../../include/netif_messages.h"
#include "../../include/nil_messages.h"
#include "../../include/netif_interface.h"
#include "../../include/nil_interface.h"
#include "../../include/il_interface.h"
 
#include "../../structures/measured_strings.h"
#include "../../structures/packet/packet_client.h"
 
#include "../nil_module.h"
#include "../nil_wrappers.h"
 
#include "eth.h"
#include "eth_header.h"
95,7 → 95,8
INT_MAP_IMPLEMENT( eth_protos, eth_proto_t )
 
int eth_device_message( device_id_t device_id, services_t service, size_t mtu );
int eth_receive_message( device_id_t device_id, packet_t packet );
int nil_receive_msg( int nil_phone, device_id_t device_id, packet_t packet );
int nil_register_message( services_t service, int phone );
int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix );
int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address );
int eth_send_message( device_id_t device_id, packet_t packet, services_t sender );
102,7 → 103,7
eth_proto_ref eth_process_packet( int dummy, packet_t packet );
int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype );
 
void nil_device_state_wrapper( device_id_t device_id, int state ){
int nil_device_state_msg( int nil_phone, device_id_t device_id, int state ){
int index;
eth_proto_ref proto;
 
110,16 → 111,13
rwlock_read_lock( & eth_globals.protos_lock );
for( index = eth_protos_count( & eth_globals.protos ) - 1; index >= 0; -- index ){
proto = eth_protos_get_index( & eth_globals.protos, index );
if( proto && proto->phone ) async_msg_2( proto->phone, NET_IL_DEVICE_STATE, device_id, state );
if( proto && proto->phone ) il_device_state_msg( proto->phone, device_id, state );
}
rwlock_read_unlock( & eth_globals.protos_lock );
return EOK;
}
 
int nil_receive_wrapper( device_id_t device_id, packet_t packet ){
return eth_receive_message( device_id, packet );
}
 
int nil_initialize( int networking_phone ){
int nil_initialize( int net_phone ){
ERROR_DECLARE;
 
rwlock_initialize( & eth_globals.devices_lock );
126,7 → 124,7
rwlock_initialize( & eth_globals.protos_lock );
rwlock_write_lock( & eth_globals.devices_lock );
rwlock_write_lock( & eth_globals.protos_lock );
eth_globals.networking_phone = networking_phone;
eth_globals.net_phone = net_phone;
eth_globals.broadcast_addr = measured_string_create_bulk( "\xFF\xFF\xFF\xFF\xFF\xFF", CONVERT_SIZE( uint8_t, char, ETH_ADDR ));
if( ! eth_globals.broadcast_addr ) return ENOMEM;
ERROR_PROPAGATE( eth_devices_initialize( & eth_globals.devices ));
150,13 → 148,13
device = eth_devices_find( & eth_globals.devices, device_id );
if( device ){
if( device->service != service ){
printf( "\nDevice %d already exists", device->device_id );
printf( "Device %d already exists\n", device->device_id );
rwlock_write_unlock( & eth_globals.devices_lock );
return EEXIST;
}else{
// update mtu
device->mtu = mtu;
printf( "\nDevice %d already exists:\tMTU\t= %d", device->device_id, device->mtu );
printf( "Device %d already exists:\tMTU\t= %d\n", device->device_id, device->mtu );
}
}else{
// create a new device
168,14 → 166,12
// TODO get dummy setting
device->dummy = 0;
// bind the device driver
#if ! NETIF_BUNDLE
device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver );
device->phone = netif_bind_service( device->service, device->device_id, SERVICE_ETHERNET, eth_receiver );
if( device->phone < 0 ){
rwlock_write_unlock( & eth_globals.devices_lock );
free( device );
return device->phone;
}
#endif
// get hardware address
if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){
rwlock_write_unlock( & eth_globals.devices_lock );
191,7 → 187,7
free( device );
return index;
}
printf( "\nNew device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X", device->device_id, device->service, device->mtu, device->addr_data[ 0 ], device->addr_data[ 1 ], device->addr_data[ 2 ], device->addr_data[ 3 ], device->addr_data[ 4 ], device->addr_data[ 5 ] );
printf( "New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X\n", device->device_id, device->service, device->mtu, device->addr_data[ 0 ], device->addr_data[ 1 ], device->addr_data[ 2 ], device->addr_data[ 3 ], device->addr_data[ 4 ], device->addr_data[ 5 ] );
}
rwlock_write_unlock( & eth_globals.devices_lock );
return EOK;
254,7 → 250,7
return eth_protos_find( & eth_globals.protos, type );
}
 
int eth_receive_message( device_id_t device_id, packet_t packet ){
int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ){
eth_proto_ref proto;
packet_t next;
eth_device_ref device;
273,10 → 269,10
next = pq_detach( packet );
proto = eth_process_packet( dummy, packet );
if( proto ){
async_msg_3( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet ), proto->service );
il_received_msg( proto->phone, device_id, packet, proto->service );
}else{
// drop invalid/unknown
pq_release( eth_globals.networking_phone, packet_get_id( packet ));
pq_release( eth_globals.net_phone, packet_get_id( packet ));
}
packet = next;
}while( packet );
350,7 → 346,7
return index;
}
}
printf( "\nNew protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d", proto->protocol, proto->service, proto->phone );
printf( "New protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d\n", proto->protocol, proto->service, proto->phone );
rwlock_write_unlock( & eth_globals.protos_lock );
return EOK;
}
409,7 → 405,7
 
ethertype = htons( protocol_map( SERVICE_ETHERNET, sender ));
if( ! ethertype ){
pq_release( eth_globals.networking_phone, packet_get_id( packet ));
pq_release( eth_globals.net_phone, packet_get_id( packet ));
return EINVAL;
}
rwlock_read_lock( & eth_globals.devices_lock );
424,7 → 420,7
if( ERROR_OCCURRED( eth_prepare_packet( device->dummy, next, ( uint8_t * ) device->addr->value, ethertype ))){
// release invalid packet
tmp = pq_detach( next );
pq_release( eth_globals.networking_phone, packet_get_id( next ));
pq_release( eth_globals.net_phone, packet_get_id( next ));
next = tmp;
}else{
next = pq_next( next );
442,7 → 438,7
measured_string_ref address;
packet_t packet;
 
// printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_NIL_FIRST );
// printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_NIL_FIRST );
* answer_count = 0;
switch( IPC_GET_METHOD( * call )){
case IPC_M_PHONE_HUNGUP:
450,7 → 446,7
case NET_NIL_DEVICE:
return eth_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), NIL_GET_MTU( call ));
case NET_NIL_SEND:
ERROR_PROPAGATE( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( call )));
ERROR_PROPAGATE( packet_translate( eth_globals.net_phone, & packet, IPC_GET_PACKET( call )));
return eth_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call ));
case NET_NIL_PACKET_SPACE:
ERROR_PROPAGATE( eth_packet_space_message( IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer )));
476,12 → 472,12
while( true ){
switch( IPC_GET_METHOD( * icall )){
case NET_NIL_DEVICE_STATE:
nil_device_state_wrapper( IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall ));
nil_device_state_msg( 0, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall ));
ipc_answer_0( iid, EOK );
break;
case NET_NIL_RECEIVED:
if( ! ERROR_OCCURRED( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){
ERROR_CODE = nil_receive_wrapper( IPC_GET_DEVICE( icall ), packet );
if( ! ERROR_OCCURRED( packet_translate( eth_globals.net_phone, & packet, IPC_GET_PACKET( icall )))){
ERROR_CODE = nil_received_msg( 0, IPC_GET_DEVICE( icall ), packet, 0 );
}
ipc_answer_0( iid, ERROR_CODE );
break;