/branches/network/uspace/srv/net/nil/eth/eth_module.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/eth/eth.c |
---|
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; |
/branches/network/uspace/srv/net/nil/eth/eth.h |
---|
38,10 → 38,8 |
#define __NET_ETH_H__ |
#include <rwlock.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../include/sockaddr.h" |
#include "../../include/device.h" |
#include "../../structures/measured_strings.h" |
/branches/network/uspace/srv/net/nil/eth/eth_module.c |
---|
44,8 → 44,9 |
#include "../../structures/packet/packet.h" |
#include "../nil_module.h" |
#include "eth.h" |
#include "eth_module.h" |
#define NAME "Ethernet protocol" |
62,11 → 63,12 |
ERROR_DECLARE; |
ipcarg_t phonehash; |
int networking_phone; |
async_set_client_connection( client_connection ); |
eth_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
networking_phone = connect_to_service( SERVICE_NETWORKING ); |
ERROR_PROPAGATE( pm_init()); |
if( ERROR_OCCURRED( eth_initialize()) |
if( ERROR_OCCURRED( nil_initialize( networking_phone )) |
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_ETHERNET, & phonehash ))){ |
pm_destroy(); |
return ERROR_CODE; |
/branches/network/uspace/srv/net/nil/eth/Makefile |
---|
42,6 → 42,6 |
$(STRUCTURES)packet/packet.c \ |
$(STRUCTURES)packet/packet_client.c |
NET_DEFS += -D ETH_BUNDLE=1 |
NET_DEFS += -D NIL_BUNDLE=1 -Dnil_message=$(NAME)_message |
include $(NET_BASE)Makefile.module |
/branches/network/uspace/srv/net/nil/nil_wrappers.h |
---|
0,0 → 1,46 |
/* |
* 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 |
* @{ |
*/ |
#ifndef __NET_NIL_WRAPPERS_H__ |
#define __NET_NIL_WRAPPERS_H__ |
#include "../include/device.h" |
#include "../structures/packet/packet.h" |
void nil_device_state_wrapper( device_id_t device_id, int state ); |
int nil_receive_wrapper( device_id_t device_id, packet_t packet ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/nil_module.h |
---|
0,0 → 1,48 |
/* |
* 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_ETH_MODULE_H__ |
#define __NET_ETH_MODULE_H__ |
#include <ipc/ipc.h> |
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 |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/include/nil_messages.h |
---|
0,0 → 1,114 |
/* |
* 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 <async.h> |
#include <errno.h> |
#include <malloc.h> |
#include <ipc/ipc.h> |
#include "../messages.h" |
#include "../structures/measured_strings.h" |
#include "../structures/packet/packet.h" |
#include "device.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; |
#ifdef NIL_BUNDLE |
#include "../nil/nil_wrappers.h" |
/** 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 ) |
#define nil_device_state_msg( nil_phone, device_id, state ) \ |
nil_device_state_wrapper( device_id, state ) |
#define nil_received_msg( nil_phone, device_id, packet, target ) \ |
( void ) nil_receive_wrapper( device_id, packet ) |
#else |
#define nil_get_addr( nil_phone, device_id, address, data ) \ |
generic_get_addr( nil_phone, NET_NIL_ADDR, device_id, address, data ) |
#define nil_get_broadcast_addr( nil_phone, device_id, address, data ) \ |
generic_get_addr( nil_phone, NET_NIL_BROADCAST_ADDR, device_id, address, data ) |
#define nil_send_msg( nil_phone, device_id, packet, sender ) \ |
generic_send_msg( nil_phone, NET_NIL_SEND, device_id, packet_get_id( packet ), sender ) |
#define nil_packet_size_req( nil_phone, device_id, addr_len, prefix, content, suffix ) \ |
generic_packet_size_req( nil_phone, NET_NIL_PACKET_SPACE, device_id, addr_len, prefix, content, suffix ) |
#define nil_device_state_msg( nil_phone, device_id, state ) \ |
generic_device_state_msg( nil_phone, NET_NIL_DEVICE_STATE, device_id, state ) |
#define nil_received_msg( nil_phone, device_id, packet, target ) \ |
generic_received_msg( nil_phone, NET_NIL_RECEIVED, device_id, packet_get_id( packet ), target ) |
#define nil_device_req( nil_phone, device_id, mtu, netif_service ) \ |
generic_device_req( nil_phone, NET_NIL_DEVICE, device_id, mtu, netif_service ) |
#endif |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/include/netif_messages.h |
---|
73,59 → 73,48 |
#include "../netif/netif_wrappers.h" |
#define NETIF_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define NETIF_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
#define NETIF_GET_IRQ( call ) ( int ) IPC_GET_ARG2( * call ) |
#define NETIF_GET_IO( call ) ( int ) IPC_GET_ARG3( * call ) |
#define netif_get_addr( netif_phone, device_id, address, data ) \ |
netif_get_addr_wrapper( netif_phone, device_id, address, data ) |
netif_get_addr_wrapper( device_id, address, data ) |
#define netif_probe_req( netif_phone, device_id, irq, io ) \ |
netif_probe_wrapper( device_id, irq, io ) |
static inline int netif_probe_req( int netif_phone, device_id_t device_id, int irq, int io ){ |
return netif_probe_wrapper( device_id, irq, io ); |
} |
#define netif_send_msg( netif_phone, device_id, packet ) \ |
netif_send_wrapper( device_id, packet ) |
#define netif_send_msg( netif_phone, device_id, packet, sender ) \ |
netif_send_wrapper( device_id, packet, sender ) |
#define netif_start_req( netif_phone, device_id ) \ |
netif_start_wrapper( device_id ) |
static inline int netif_start_req( int netif_phone, device_id_t device_id ){ |
return netif_start_wrapper( device_id ); |
} |
#define netif_stop_req( netif_phone, device_id ) \ |
netif_stop_wrapper( device_id ) |
static inline int netif_stop_req( int netif_phone, device_id_t device_id ){ |
return netif_stop_wrapper( device_id ); |
} |
#else |
static inline int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){ |
aid_t message; |
// ipc_call_t answer; |
ipcarg_t result; |
int string; |
#define netif_get_addr( netif_phone, device_id, address, data ) \ |
generic_get_addr( netif_phone, NET_NETIF_GET_ADDR, device_id, address, data ) |
if( !( address && data )) return EBADMEM; |
message = async_send_1( netif_phone, NET_NETIF_GET_ADDR, device_id, NULL /* & answer */ ); |
string = measured_strings_return( netif_phone, address, data, 1 ); |
async_wait_for( message, & result ); |
if(( string == EOK ) && ( result != EOK )){ |
free( * address ); |
free( * data ); |
static inline int netif_probe_req( int netif_phone, device_id_t device_id, int irq, int io ){ |
return async_req_3_0( netif_phone, NET_NETIF_PROBE, device_id, irq, io ); |
} |
return result; |
} |
#define netif_probe_req( netif_phone, device_id, irq, io ) \ |
async_req_3_0( netif_phone, NET_NETIF_PROBE, device_id, irq, io ) |
#define netif_send_msg( netif_phone, device_id, packet, sender ) \ |
generic_send_msg( netif_phone, NET_NETIF_SEND, device_id, packet_get_id( packet ), sender ) |
#define netif_send_msg( netif_phone, device_id, packet ) \ |
async_msg_2( netif_phone, NET_NETIF_SEND, device_id, packet_get_id( packet )) |
static inline int netif_start_req( int netif_phone, device_id_t device_id ){ |
return async_req_1_0( netif_phone, NET_NETIF_START, device_id ); |
} |
#define netif_start_req( netif_phone, device_id ) \ |
async_req_1_0( netif_phone, NET_NETIF_START, device_id ) |
static inline int netif_stop_req( int netif_phone, device_id_t device_id ){ |
return async_req_1_0( netif_phone, NET_NETIF_STOP, device_id ); |
} |
#define netif_stop_req( netif_phone, device_id ) \ |
async_req_1_0( netif_phone, NET_NETIF_STOP, device_id ) |
#endif |
#endif |
/branches/network/uspace/srv/net/include/protocol_map.h |
---|
108,6 → 108,7 |
static inline int hardware_map( services_t nil ){ |
switch( nil ){ |
case SERVICE_ETHERNET: |
case SERVICE_DP8390: |
return HW_ETHER; |
default: |
return 0; |
/branches/network/uspace/srv/net/include/byteorder.h |
---|
39,6 → 39,8 |
#include <byteorder.h> |
#include <sys/types.h> |
#ifdef ARCH_IS_BIG_ENDIAN |
// Already in the network byte order. |
75,7 → 77,7 |
* @param number The number in the host byte order to be converted. |
* @returns The number in the network byte order. |
*/ |
#define htons( number ) uint16_t_byteorder_swap( number ) |
#define htons( number ) uint16_t_byteorder_swap(( uint16_t )( number )) |
/** Converts the given long number ( 32 bit ) from the host byte order to the network byte order ( big endian ). |
* @param number The number in the host byte order to be converted. |
87,7 → 89,7 |
* @param number The number in the network byte order to be converted. |
* @returns The number in the host byte order. |
*/ |
#define ntohs( number ) uint16_t_byteorder_swap( number ) |
#define ntohs( number ) uint16_t_byteorder_swap(( uint16_t )( number )) |
/** Converts the given long number ( 32 bit ) from the network byte order ( big endian ) to the host byte order. |
* @param number The number in the network byte order to be converted. |
/branches/network/uspace/srv/net/networking/networking.c |
---|
58,7 → 58,8 |
#include "../il/ip/ip_messages.h" |
#include "../include/device.h" |
#include "../include/netif_messages.h" |
#include "../include/nil_messages.h" |
/* |
#if IP_BUNDLE |
#include "../ip/ip_module.h" |
70,7 → 71,7 |
#include "../tcp/tcp_module.h" |
#endif |
*/ |
#define NAME "Networking" |
#define LO_NAME "lo" |
167,11 → 168,11 |
} |
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
#ifdef NETWORKING_module |
/*#ifdef NETWORKING_module |
//TODO map to *_message |
if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){ |
return ip_message( callid, call, answer, answer_count ); |
/* }else if( IS_NET_ARP_MESSAGE( call )){ |
*//* }else if( IS_NET_ARP_MESSAGE( call )){ |
return arp_message( callid, call, answer, answer_count ); |
*//* }else if( IS_NET_RARP_MESSAGE( call )){ |
return rarp_message( callid, call, answer, answer_count ); |
179,22 → 180,23 |
return icmp_message( callid, call, answer, answer_count ); |
*//* }else if( IS_NET_UDP_MESSAGE( call )){ |
return udp_message( callid, call, answer, answer_count ); |
*/ }else if( IS_NET_TCP_MESSAGE( call )){ |
*//* }else if( IS_NET_TCP_MESSAGE( call )){ |
return tcp_message( callid, call, answer, answer_count ); |
/* }else if( IS_NET_SOCKET_MESSAGE( call )){ |
*//* }else if( IS_NET_SOCKET_MESSAGE( call )){ |
return socket_message( callid, call, answer, answer_count ); |
*//* }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){ |
return ethernet_message( callid, call, answer, answer_count ); |
*/ }else{ |
*//* }else{ |
#endif |
if( IS_NET_PACKET_MESSAGE( call )){ |
*/ if( IS_NET_PACKET_MESSAGE( call )){ |
return packet_server_message( callid, call, answer, answer_count ); |
}else{ |
return net_message( callid, call, answer, answer_count ); |
} |
#ifdef NETWORKING_module |
/*#ifdef NETWORKING_module |
} |
#endif |
*/ |
} |
int networking_start_module( async_client_conn_t client_connection ){ |
233,7 → 235,7 |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0 )); |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0 )); |
#ifdef NETWORKING_modular |
//#ifdef NETWORKING_modular |
task_id = spawn( "/srv/ip" ); |
if( ! task_id ) return EINVAL; |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id )); |
244,7 → 246,7 |
// if( ! spawn( "/srv/arp" )) return EINVAL; |
// if( ! spawn( "/srv/rarp" )) return EINVAL; |
// if( ! spawn( "/srv/icmp" )) return EINVAL; |
/* |
#else |
#ifdef NETWORKING_module |
ipcarg_t phonehash; |
268,7 → 270,7 |
// ERROR_PROPAGATE( ethernet_initialize()); |
#endif |
#endif |
*/ |
return EOK; |
} |
429,7 → 431,13 |
}else if( strncmp( name, "ne2k", 4 ) == 0 ){ |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
#ifdef NETWORKING_module |
// ethernet bundled in dp8390 |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME )); |
#else |
// standalone ethernet |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )); |
#endif |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
493,13 → 501,13 |
setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 ); |
} |
mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, mtu, netif->driver->service )); |
ERROR_PROPAGATE( nil_device_req( netif->nil->phone, netif->id, mtu, netif->driver->service )); |
internet_service = netif->nil->service; |
}else{ |
internet_service = netif->driver->service; |
} |
// TODO IL_BUNDLE |
ERROR_PROPAGATE( async_req_2_0( netif->il->phone, NET_IL_DEVICE, netif->id, internet_service )); |
ERROR_PROPAGATE( async_req_3_0( netif->il->phone, NET_IL_DEVICE, netif->id, 0, internet_service )); |
ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id )); |
return EOK; |
} |
/branches/network/uspace/srv/net/networking/Makefile |
---|
31,7 → 31,7 |
NET_BASE = ../ |
STRUCTURES = $(NET_BASE)structures/ |
include ../../../../Makefile.config |
include $(NET_BASE)../../../Makefile.config |
## Sources |
# |
/branches/network/uspace/srv/net/messages.h |
---|
36,9 → 36,19 |
#ifndef __NET_MESSAGES_H__ |
#define __NET_MESSAGES_H__ |
#include <async.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "include/device.h" |
#include "structures/measured_strings.h" |
#include "structures/packet/packet.h" |
#define NET_NETIF_COUNT 8 |
#define NET_NET_COUNT 9 |
#define NET_NIL_COUNT 8 |
#define NET_NIL_COUNT 7 |
#define NET_ETH_COUNT 0 |
#define NET_IL_COUNT 3 |
#define NET_IP_COUNT 2 |
104,8 → 114,29 |
#define IS_NET_SOCKET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_SOCKET_FIRST, NET_SOCKET_LAST ) |
#define IS_NET_PACKET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_PACKET_FIRST, NET_PACKET_LAST ) |
/** 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 device driver service message parameter. |
*/ |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
#define IPC_GET_TARGET( call ) ( services_t ) IPC_GET_ARG3( * call ) |
#define IPC_GET_SENDER( call ) ( services_t ) IPC_GET_ARG3( * 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 { |
/* () not supported, registers new device */ |
NET_NET_DEVICE = NET_NET_FIRST, |
125,20 → 156,6 |
NET_NET_STOP, |
/* ( device_id ) ipc_data_read( stats ) */ |
NET_NET_STATS, |
/* ( 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, |
/* ( device_id, nil_service ) */ |
NET_IL_DEVICE = NET_IL_FIRST, |
/* ( device_id, state ) */ |
165,6 → 182,43 |
NET_PACKET_RELEASE |
} net_messages; |
static inline int generic_get_addr( int phone, int message, device_id_t device_id, measured_string_ref * address, char ** data ){ |
aid_t message_id; |
// ipc_call_t answer; |
ipcarg_t result; |
int string; |
if( !( address && data )) return EBADMEM; |
message_id = async_send_1( phone, message, device_id, NULL /* & answer */ ); |
string = measured_strings_return( phone, address, data, 1 ); |
async_wait_for( message_id, & result ); |
if(( string == EOK ) && ( result != EOK )){ |
free( * address ); |
free( * data ); |
} |
return result; |
} |
static inline void generic_send_msg( int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender ){ |
async_msg_3( phone, message, device_id, packet_id, sender ); |
} |
static inline int generic_packet_size_req( int phone, int message, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
return async_req_1_4( phone, message, device_id, ( ipcarg_t * ) addr_len, ( ipcarg_t * ) prefix, ( ipcarg_t * ) content, ( ipcarg_t * ) suffix ); |
} |
static inline void generic_device_state_msg( int phone, int message, device_id_t device_id, int state ){ |
async_msg_2( phone, message, device_id, state ); |
} |
static inline void generic_received_msg( int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t target ){ |
async_msg_3( phone, message, device_id, packet_id, target ); |
} |
static inline int generic_device_req( int phone, int message, device_id_t device_id, int arg2, services_t service ){ |
return async_req_3_0( phone, message, device_id, arg2, service ); |
} |
#endif |
/** @} |
/branches/network/uspace/srv/net/Makefile.module |
---|
60,9 → 60,14 |
depend: |
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend |
$(OUTPUT): $(OBJECTS) $(LIBS) |
$(OUTPUT): freshen $(OBJECTS) $(LIBS) |
$(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $@.map |
freshen: |
if $(REBUILD) |
-rm -f $(addsuffix .o,$(basename $(REBUILD))) |
endif |
disasm: $(DISASMS) |
%.disasm: $@ |
/branches/network/uspace/srv/net/il/arp/arp.c |
---|
50,6 → 50,7 |
#include "../../include/byteorder.h" |
#include "../../include/device.h" |
#include "../../include/nil_messages.h" |
#include "../../include/protocol_map.h" |
#include "../../structures/measured_strings.h" |
62,22 → 63,10 |
//#include "arp_messages.h" |
#include "arp_module.h" |
/** 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 ) |
/** Returns the protocol service message parameter. |
*/ |
#define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
#define ARP_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 ) |
/** ARP global data. |
*/ |
arp_globals_t arp_globals; |
189,9 → 178,6 |
ERROR_DECLARE; |
arp_device_ref device; |
aid_t message; |
ipc_call_t answer; |
ipcarg_t result; |
arp_proto_ref proto; |
int index; |
219,7 → 205,7 |
if( index < 0 ){ |
rwlock_write_unlock( & arp_globals.lock ); |
free( proto ); |
return result; |
return index; |
} |
} |
printf( "\nCache of the existing device %d cleaned", device->device_id ); |
257,7 → 243,7 |
return EREFUSED; |
} |
// get packet dimensions |
if( ERROR_OCCURRED( async_req_1_4( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){ |
if( ERROR_OCCURRED( nil_packet_size_req( device->phone, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
264,38 → 250,22 |
return ERROR_CODE; |
} |
// get hardware address |
message = async_send_1( device->phone, NET_NIL_ADDR, device->device_id, & answer ); |
if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){ |
if( ERROR_OCCURRED( nil_get_addr( device->phone, device_id, & device->addr, & device->addr_data ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
if( ERROR_OCCURRED( result )){ |
rwlock_write_unlock( & arp_globals.lock ); |
free( device->addr ); |
free( device->addr_data ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
} |
// get broadcast address |
message = async_send_1( device->phone, NET_NIL_BROADCAST_ADDR, device->device_id, & answer ); |
if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->broadcast_addr, & device->broadcast_data, 1 ))){ |
if( ERROR_OCCURRED( nil_get_broadcast_addr( device->phone, device_id, & device->broadcast_addr, & device->broadcast_data ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
free( device->addr ); |
free( device->addr_data ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
// add to the cache |
if( ERROR_OCCURRED( result ) |
|| ERROR_OCCURRED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){ |
if( ERROR_OCCURRED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
free( device->addr ); |
free( device->addr_data ); |
346,7 → 316,7 |
length += device->addr->length; |
memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length )); |
async_msg_3( device->phone, NET_NIL_SEND, device_id, packet_get_id( packet ), SERVICE_ARP ); |
nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
return NULL; |
} |
404,7 → 374,7 |
memcpy( src_hw, des_hw, header->hardware_length ); |
memcpy( des_hw, hw_source->value, header->hardware_length ); |
packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
async_msg_3( device->phone, NET_NIL_SEND, device_id, packet_get_id( packet ), SERVICE_ARP ); |
nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
}else{ |
pq_release( arp_globals.networking_phone, packet_get_id( packet )); |
} |
475,7 → 445,7 |
return EOK; |
case NET_ARP_DEVICE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_PROTO( call ), address ))){ |
if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), ARP_GET_PROTO( call ), address ))){ |
free( address ); |
free( data ); |
} |
483,7 → 453,7 |
case NET_ARP_TRANSLATE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
rwlock_read_lock( & arp_globals.lock ); |
translation = arp_translate_message( IPC_GET_DEVICE( call ), IPC_GET_PROTO( call ), address ); |
translation = arp_translate_message( IPC_GET_DEVICE( call ), ARP_GET_PROTO( call ), address ); |
free( address ); |
free( data ); |
if( ! translation ){ |
/branches/network/uspace/srv/net/il/arp/arp.h |
---|
40,6 → 40,7 |
#include <rwlock.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../include/device.h" |
102,17 → 103,17 |
ipcarg_t hardware; |
/** Reserved packet prefix length. |
*/ |
ipcarg_t prefix; |
size_t prefix; |
/** Maximal packet content length. |
*/ |
ipcarg_t content; |
size_t content; |
/** Reserved packet suffix length. |
*/ |
ipcarg_t suffix; |
size_t suffix; |
/** Packet address length. |
* The hardware address length is used. |
*/ |
ipcarg_t addr_len; |
size_t addr_len; |
/** Actual device hardware address. |
*/ |
measured_string_ref addr; |
/branches/network/uspace/srv/net/il/arp/arp_module.h |
---|
38,8 → 38,6 |
#ifndef __NET_ARP_MODULE_H__ |
#define __NET_ARP_MODULE_H__ |
#include <errno.h> |
#include <ipc/ipc.h> |
/** Initializes the ARP module. |
/branches/network/uspace/srv/net/il/ip/ip.c |
---|
47,6 → 47,7 |
#include "../../include/sockaddr.h" |
#include "../../include/socket.h" |
#include "../../include/device.h" |
#include "../../include/nil_messages.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/module_map.h" |
#include "../../structures/packet/packet_client.h" |
60,10 → 61,7 |
#define ARP_NAME "arp" |
#define ARP_FILENAME "/srv/arp" |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * call ) |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
180,7 → 178,6 |
free( settings ); |
free( data ); |
} |
// TODO mapping |
ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver ); |
if( ip_netif->phone < 0 ){ |
printf( "\nFailed to contact the nil service %d", service ); |
/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,44 → 80,86 |
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 ); |
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 ); |
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(); |
/branches/network/uspace/srv/net/netif/dp8390/dp8390_module.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/dp8390/dp8390.c |
---|
39,7 → 39,6 |
#include "../netif.h" |
#include "dp8390_drv.h" |
#include "dp8390_module.h" |
#include "dp8390_port.h" |
/* |
922,6 → 921,7 |
{ |
int last, count; |
packet_t packet; |
packet_t queue; |
if (!(dep->de_flags & DEF_READING)) |
return EGENERIC; |
956,7 → 956,10 |
dep->de_flags |= DEF_PACK_RECV; |
dep->de_flags &= ~DEF_READING; |
if( netif_send_packet( dep, packet ) != EOK ){ |
queue = pq_add( dep->received_queue, packet, 0, 0 ); |
if( queue ){ |
dep->received_queue = queue; |
}else{ |
netif_pq_release( packet_get_id( packet )); |
} |
return OK; |
/branches/network/uspace/srv/net/netif/dp8390/Makefile |
---|
31,15 → 31,18 |
NET_BASE = ../../ |
STRUCTURES = $(NET_BASE)structures/ |
include $(NET_BASE)../../../Makefile.config |
## Sources |
# |
OUTPUT = dp8390 |
REBUILD = $(OUTPUT)_module.c \ |
../$(NAME).c |
SOURCES = \ |
$(OUTPUT).c \ |
$(OUTPUT)_module.c \ |
$(REBUILD) \ |
ne2000.c \ |
../$(NAME).c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(STRUCTURES)measured_strings.c \ |
48,4 → 51,14 |
NET_DEFS += -D NETIF_BUNDLE=1 |
ifeq ($(NETWORKING), module) |
SOURCES += $(NET_BASE)crc.c |
REBUILD += $(NET_BASE)nil/eth/eth.c |
NET_DEFS += -D NIL_BUNDLE=1 |
endif |
include $(NET_BASE)Makefile.module |
/branches/network/uspace/srv/net/netif/dp8390/dp8390.h |
---|
40,6 → 40,8 |
#include "dp8390_port.h" |
#include "local.h" |
#define DP8390_IO_SIZE 0x01f |
/* |
dp8390.h |
268,14 → 270,15 |
typedef struct dpeth |
{ |
/* Parent device structure. |
*/ |
void * parent; |
/* Packet send queue. |
*/ |
packet_t packet_queue; |
int packet_count; |
/* Packet receive queue. |
*/ |
packet_t received_queue; |
/* The de_base_port field is the starting point of the probe. |
* The conf routine also fills de_linmem and de_irq. If the probe |
* routine knows the irq and/or memory address because they are |
/branches/network/uspace/srv/net/netif/dp8390/dp8390_module.c |
---|
49,6 → 49,7 |
#include "../../structures/measured_strings.h" |
#include "../../include/device.h" |
#include "../../include/nil_messages.h" |
#include "../netif.h" |
#include "../netif_interface.h" |
55,12 → 56,11 |
#include "dp8390.h" |
#include "dp8390_drv.h" |
#include "dp8390_module.h" |
#include "dp8390_port.h" |
#define NAME "dp8390 network interface" |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
#define IRQ_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
#define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
static irq_cmd_t dp8390_cmds[] = { |
92,7 → 92,7 |
void netif_print_name( void ); |
void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
void change_state( device_ref device, device_state_t state ); |
int change_state( device_ref device, device_state_t state ); |
int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
return ENOTSUP; |
144,14 → 144,24 |
// int irq; |
device_ref device; |
dpeth_t * dep; |
packet_t received; |
device_id_t device_id; |
int phone; |
printf( "\ndevice %d - irq %x", IPC_GET_DEVICE( call ), IPC_GET_ISR( call )); |
if( find_device( IPC_GET_DEVICE( call ), & device ) != EOK ) return; |
device_id = IRQ_GET_DEVICE( call ); |
// printf( "\ndevice %d - irq %x", device_id, IPC_GET_ISR( call )); |
rwlock_write_lock( & netif_globals.lock ); |
if( find_device( device_id, & device ) != EOK ){ |
rwlock_write_unlock( & netif_globals.lock ); |
return; |
} |
dep = ( dpeth_t * ) device->specific; |
printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
if ( dep->de_mode != DEM_ENABLED) |
// printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
if ( dep->de_mode != DEM_ENABLED){ |
// continue; |
rwlock_write_unlock( & netif_globals.lock ); |
return; |
} |
assert( dep->de_flags & DEF_ENABLED); |
// irq= dep.de_irq; |
// assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
167,6 → 177,15 |
"unable enable interrupts", r); |
} |
*/// } |
if( dep->received_queue ){ |
received = dep->received_queue; |
phone = device->nil_phone; |
dep->received_queue = NULL; |
rwlock_write_unlock( & netif_globals.lock ); |
nil_received_msg( phone, device_id, received, NULL ); |
}else{ |
rwlock_write_unlock( & netif_globals.lock ); |
} |
ipc_answer_0( iid, EOK ); |
} |
194,7 → 213,6 |
device->nil_phone = -1; |
device->specific = ( void * ) dep; |
device->state = NETIF_STOPPED; |
dep->parent = device; |
dep->de_irq = irq; |
dep->de_mode = DEM_DISABLED; |
//TODO address? |
212,7 → 230,7 |
return EOK; |
} |
int netif_send_message( device_id_t device_id, packet_t packet ){ |
int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
ERROR_DECLARE; |
device_ref device; |
236,13 → 254,11 |
return EOK; |
} |
int netif_start_message( device_id_t device_id ){ |
int netif_start_message( device_ref device ){ |
ERROR_DECLARE; |
device_ref device; |
dpeth_t * dep; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != NETIF_ACTIVE ){ |
dep = ( dpeth_t * ) device->specific; |
dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
252,31 → 268,27 |
ipc_unregister_irq( dep->de_irq, device->device_id ); |
return ERROR_CODE; |
} |
change_state( device, NETIF_ACTIVE ); |
return change_state( device, NETIF_ACTIVE ); |
} |
return EOK; |
} |
int netif_stop_message( device_id_t device_id ){ |
ERROR_DECLARE; |
device_ref device; |
int netif_stop_message( device_ref device ){ |
dpeth_t * dep; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != NETIF_STOPPED ){ |
dep = ( dpeth_t * ) device->specific; |
do_stop( dep ); |
ipc_unregister_irq( dep->de_irq, device->device_id ); |
change_state( device, NETIF_STOPPED ); |
return change_state( device, NETIF_STOPPED ); |
} |
return EOK; |
} |
void change_state( device_ref device, device_state_t state ){ |
int change_state( device_ref device, device_state_t state ){ |
device->state = state; |
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
return state; |
} |
int netif_initialize( void ){ |
287,11 → 299,5 |
return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
} |
int netif_send_packet( dpeth_t * dep, packet_t packet ){ |
if( !( dep && dep->parent )) return EINVAL; |
nil_message(( device_ref ) dep->parent, NET_NIL_RECEIVED, packet_get_id( packet ), 0 ); |
return EOK; |
} |
/** @} |
*/ |
/branches/network/uspace/srv/net/netif/lo/lo.c |
---|
48,6 → 48,7 |
#include "../../structures/packet/packet_client.h" |
#include "../../include/device.h" |
#include "../../include/nil_messages.h" |
#include "../netif.h" |
#include "../netif_interface.h" |
65,7 → 66,7 |
int mtu; |
} lo_globals; |
static int change_state_message( device_id_t device_id, device_state_t state ); |
static int change_state_message( device_ref device, device_state_t state ); |
static int create( device_id_t device_id, device_ref * device ); |
void netif_print_name( void ); |
92,16 → 93,11 |
return EOK; |
} |
static int change_state_message( device_id_t device_id, device_state_t state ){ |
ERROR_DECLARE; |
device_ref device; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
static int change_state_message( device_ref device, device_state_t state ){ |
if( device->state != state ){ |
device->state = state; |
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
return state; |
} |
return EOK; |
} |
198,12 → 194,13 |
return EOK; |
} |
int netif_send_message( device_id_t device_id, packet_t packet ){ |
int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
ERROR_DECLARE; |
device_ref device; |
size_t length; |
packet_t next; |
int phone; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != NETIF_ACTIVE ) return EPERM; |
216,16 → 213,19 |
(( device_stats_ref ) device->specific )->rx_bytes += length; |
next = pq_next( next ); |
}while( next ); |
nil_message( device, NET_NIL_RECEIVED, packet_get_id( packet ), PACKET_SELF ); |
phone = device->nil_phone; |
rwlock_write_unlock( & netif_globals.lock ); |
nil_received_msg( phone, device_id, packet, sender ); |
rwlock_write_lock( & netif_globals.lock ); |
return EOK; |
} |
int netif_start_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_ACTIVE ); |
int netif_start_message( device_ref device ){ |
return change_state_message( device, NETIF_ACTIVE ); |
} |
int netif_stop_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_STOPPED ); |
int netif_stop_message( device_ref device ){ |
return change_state_message( device, NETIF_STOPPED ); |
} |
/** @} |
/branches/network/uspace/srv/net/netif/lo/Makefile |
---|
35,9 → 35,10 |
# |
OUTPUT = lo |
REBUILD = ../$(NAME).c |
SOURCES = \ |
$(OUTPUT).c \ |
../$(NAME).c \ |
$(REBUILD) \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(STRUCTURES)measured_strings.c \ |
/branches/network/uspace/srv/net/netif/netif.h |
---|
41,17 → 41,6 |
#include "../include/device.h" |
/** Sends the notification message to the registered network interface layer module. |
* Wrapper of the async_msg_3(). |
* The first message argument is always the device identifier. |
* @param device The device specific data. Input parameter. |
* @param message The message to be sent. Input parameter. |
* @param arg2 The second message argument. Input parameter. |
* @param arg3 The third message argument. Input parameter. |
*/ |
#define nil_message( device, message, arg2, arg3 ) \ |
if(( device )->nil_phone >= 0 ) async_msg_3(( device )->nil_phone, ( message ), ( device )->device_id, arg2, arg3 ) |
/** Network interface module skeleton global data. |
*/ |
typedef struct netif_globals netif_globals_t; |
/branches/network/uspace/srv/net/netif/netif_interface.h |
---|
34,6 → 34,7 |
#define __NET_NETIF_INTERFACE_H__ |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../structures/measured_strings.h" |
#include "../structures/packet/packet.h" |
43,9 → 44,9 |
int netif_initialize( void ); |
int netif_probe_auto_message( void ); |
int netif_probe_message( device_id_t device_id, int irq, int io ); |
int netif_send_message( device_id_t device_id, packet_t packet ); |
int netif_start_message( device_id_t device_id ); |
int netif_stop_message( device_id_t device_id ); |
int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
int netif_start_message( device_ref device ); |
int netif_stop_message( device_ref device ); |
int netif_get_addr_message( device_id_t device_id, measured_string_ref address ); |
int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ); |
/branches/network/uspace/srv/net/netif/netif_wrappers.h |
---|
41,10 → 41,10 |
#include "../include/device.h" |
int netif_probe_wrapper( device_id_t device_id, int irq, int io ); |
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 netif_start_wrapper( device_id_t device_id ); |
int netif_stop_wrapper( device_id_t device_id ); |
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 ); |
#endif |
/branches/network/uspace/srv/net/sockaddr.c |
---|
34,6 → 34,7 |
* |
*/ |
#include <errno.h> |
#include <mem.h> |
#include <stdio.h> |
40,8 → 41,6 |
#include "include/sockaddr.h" |
#include "include/socket.h" |
#include "err.h" |
int inet_pton( uint16_t family, const char * address, uint8_t * data ){ |
const char * next; |
char * last; |