Subversion Repositories HelenOS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 4306 → Rev 4307

/branches/network/uspace/srv/net/nil/nil_wrappers.h
File deleted
Property changes:
Deleted: svn:eol-style
-native
\ No newline at end of property
/branches/network/uspace/srv/net/nil/nil_messages.h
0,0 → 1,70
/*
* Copyright (c) 2009 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup net_nil
* @{
*/
 
/**
* @file
*/
 
#ifndef __NET_NIL_MESSAGES_H__
#define __NET_NIL_MESSAGES_H__
 
#include <ipc/ipc.h>
 
#include "../messages.h"
 
typedef enum {
/* ( device_id, driver_service, mtu ) */
NET_NIL_DEVICE = NET_NIL_FIRST,
/* ( device_id, state ) */
NET_NIL_DEVICE_STATE,
/* ( device_id ), packet_send */
NET_NIL_RECEIVED,
/* ( device_id ), packet_send */
NET_NIL_SEND,
/* ( device_id ) -> addr, prefix, content, suffix */
NET_NIL_PACKET_SPACE,
/* ( device_id ), measured_strings_return( hardware address ) */
NET_NIL_ADDR,
/* ( device_id ), measured_strings_return( broadcast address ) */
NET_NIL_BROADCAST_ADDR,
} nil_messages;
 
/** Returns the protocol service message parameter.
*/
#define NIL_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call )
 
#define NIL_GET_MTU( call ) ( size_t ) IPC_GET_ARG2( * call )
 
#endif
 
/** @}
*/
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/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;
/branches/network/uspace/srv/net/nil/eth/eth.h
126,7 → 126,7
struct eth_globals{
/** Networking module phone.
*/
int networking_phone;
int net_phone;
/** Safety lock for devices.
*/
rwlock_t devices_lock;
/branches/network/uspace/srv/net/nil/eth/eth_module.c
42,6 → 42,8
#include "../../err.h"
#include "../../modules.h"
 
#include "../../include/net_interface.h"
 
#include "../../structures/packet/packet.h"
 
#include "../nil_module.h"
50,25 → 52,26
 
#define NAME "Ethernet protocol"
 
void eth_print_name( void );
int eth_start_module( async_client_conn_t client_connection );
void module_print_name( void );
int module_start( async_client_conn_t client_connection );
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
 
extern eth_globals_t eth_globals;
 
void eth_print_name( void ){
void module_print_name( void ){
printf( "%s", NAME );
}
 
int eth_start_module( async_client_conn_t client_connection ){
int module_start( async_client_conn_t client_connection ){
ERROR_DECLARE;
 
ipcarg_t phonehash;
int networking_phone;
int net_phone;
 
async_set_client_connection( client_connection );
networking_phone = connect_to_service( SERVICE_NETWORKING );
net_phone = net_connect_module( SERVICE_NETWORKING );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( nil_initialize( networking_phone ))
if( ERROR_OCCURRED( nil_initialize( net_phone ))
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_ETHERNET, & phonehash ))){
pm_destroy();
return ERROR_CODE;
80,5 → 83,9
return EOK;
}
 
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
return nil_message( callid, call, answer, answer_count );
}
 
/** @}
*/
/branches/network/uspace/srv/net/nil/eth/Makefile
35,13 → 35,15
SOURCES = \
$(NAME)_module.c \
$(NAME).c \
$(REBUILD) \
$(NET_BASE)module.c \
$(NET_BASE)modules.c \
$(NET_BASE)crc.c \
$(STRUCTURES)measured_strings.c \
$(STRUCTURES)packet/packet.c \
$(STRUCTURES)packet/packet_client.c
$(STRUCTURES)/packet/packet_client.c \
$(STRUCTURES)packet/packet_remote.c \
$(NET_BASE)netif/netif_remote.c \
$(NET_BASE)net/net_remote.c
 
NET_DEFS += -D NIL_BUNDLE=1 -Dnil_message=$(NAME)_message
 
include $(NET_BASE)Makefile.module
/branches/network/uspace/srv/net/nil/nil_module.h
40,7 → 40,6
 
int nil_initialize( int networking_phone );
int nil_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
int nil_register_message( services_t service, int phone );
 
#endif
 
/branches/network/uspace/srv/net/nil/nil_remote.c
0,0 → 1,52
/*
* Copyright (c) 2009 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup net_nil
* @{
*/
 
#include "../messages.h"
 
#include "../include/device.h"
#include "../include/nil_interface.h"
 
#include "../structures/packet/packet.h"
#include "../structures/packet/packet_client.h"
 
#include "nil_messages.h"
 
int nil_device_state_msg( int nil_phone, device_id_t device_id, int state ){
return generic_device_state_msg( nil_phone, NET_NIL_DEVICE_STATE, device_id, state );
}
 
int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ){
return generic_received_msg( nil_phone, NET_NIL_RECEIVED, device_id, packet_get_id( packet ), target );
}
 
/** @}
*/
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
Added: svn:mergeinfo