54,15 → 54,16 |
#include "../../include/protocol_map.h" |
#include "../../include/device.h" |
#include "../../include/netif_messages.h" |
#include "../../include/nil_messages.h" |
|
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet.h" |
#include "../../structures/packet/packet_client.h" |
|
#include "../nil_module.h" |
#include "../nil_wrappers.h" |
|
#include "eth.h" |
#include "eth_header.h" |
//#include "eth_messages.h" |
#include "eth_module.h" |
|
#define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
#define ETH_SUFFIX sizeof( eth_fcs_t ) |
71,33 → 72,6 |
#define ETH_MAX_TAGGED_CONTENT ( ETH_MAX_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
#define ETH_MIN_TAGGED_CONTENT ( ETH_MIN_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
|
/** Returns the device identifier message parameter. |
*/ |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
|
/** Returns the packet identifier message parameter. |
*/ |
#define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
|
#define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
|
/** Returns the protocol service message parameter. |
*/ |
#define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
|
/** Returns the device driver service message parameter. |
*/ |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
|
#define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG2( * call ) |
|
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
|
#define IPC_SET_ADDR( answer ) (( size_t * ) & IPC_GET_ARG1( * answer )) |
#define IPC_SET_PREFIX( answer ) (( size_t * ) & IPC_GET_ARG2( * answer )) |
#define IPC_SET_CONTENT( answer ) (( size_t * ) & IPC_GET_ARG3( * answer )) |
#define IPC_SET_SUFFIX( answer ) (( size_t * ) & IPC_GET_ARG4( * answer )) |
|
typedef enum eth_addr_type eth_addr_type_t; |
typedef eth_addr_type_t * eth_addr_type_ref; |
|
124,13 → 98,28 |
int eth_receive_message( device_id_t device_id, packet_t packet ); |
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_register_message( services_t service, int phone ); |
int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
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 ); |
|
int eth_initialize( void ){ |
void nil_device_state_wrapper( device_id_t device_id, int state ){ |
int index; |
eth_proto_ref proto; |
|
//TODO clear device if off? |
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 ); |
} |
rwlock_read_unlock( & eth_globals.protos_lock ); |
} |
|
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 ){ |
ERROR_DECLARE; |
|
rwlock_initialize( & eth_globals.devices_lock ); |
137,6 → 126,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.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 )); |
178,6 → 168,7 |
// 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 ); |
if( device->phone < 0 ){ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
184,6 → 175,7 |
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 ); |
281,7 → 273,7 |
next = pq_detach( packet ); |
proto = eth_process_packet( dummy, packet ); |
if( proto ){ |
async_msg_2( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet )); |
async_msg_3( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet ), proto->service ); |
}else{ |
// drop invalid/unknown |
pq_release( eth_globals.networking_phone, packet_get_id( packet )); |
329,7 → 321,7 |
return ( * address ) ? EOK : ENOENT; |
} |
|
int eth_register_message( services_t service, int phone ){ |
int nil_register_message( services_t service, int phone ){ |
eth_proto_ref proto; |
int protocol; |
int index; |
389,11 → 381,11 |
header = PACKET_PREFIX( packet, eth_header_ex_t ); |
if( ! header ) return ENOMEM; |
header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
header->lsap.dsap = 0xAA; |
header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
header->lsap.ssap = header->lsap.dsap; |
header->lsap.ctrl = 0; |
for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
header->snap.ethertype = ethertype; |
header->snap.ethertype = ( uint16_t ) ethertype; |
length = packet_get_addr( packet, & src, & dest ); |
if( length < 0 ) return length; |
if( length < ETH_ADDR ) return EINVAL; |
439,12 → 431,12 |
} |
}while( next ); |
// send packet queue |
netif_send_msg( device->phone, device_id, packet ); |
netif_send_msg( device->phone, device_id, packet, SERVICE_ETHERNET ); |
rwlock_read_unlock( & eth_globals.devices_lock ); |
return EOK; |
} |
|
int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
int nil_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
|
measured_string_ref address; |
456,7 → 448,7 |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NIL_DEVICE: |
return eth_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_MTU( call )); |
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 ))); |
return eth_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
471,7 → 463,7 |
ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_BROADCAST_ADDR, & address )); |
return measured_strings_reply( address, 1 ); |
case IPC_M_CONNECT_TO_ME: |
return eth_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
return nil_register_message( NIL_GET_PROTO( call ), IPC_GET_PHONE( call )); |
} |
return ENOTSUP; |
} |
480,24 → 472,16 |
ERROR_DECLARE; |
|
packet_t packet; |
int index; |
eth_proto_ref proto; |
|
while( true ){ |
switch( IPC_GET_METHOD( * icall )){ |
case NET_NIL_DEVICE_STATE: |
//TODO clear device if off? |
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, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
} |
rwlock_read_unlock( & eth_globals.protos_lock ); |
nil_device_state_wrapper( 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 = eth_receive_message( IPC_GET_DEVICE( icall ), packet ); |
ERROR_CODE = nil_receive_wrapper( IPC_GET_DEVICE( icall ), packet ); |
} |
ipc_answer_0( iid, ERROR_CODE ); |
break; |