/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(); |
/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 |