35,6 → 35,7 |
|
#include <async.h> |
#include <stdio.h> |
|
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/mman.h> |
42,36 → 43,53 |
#include "../err.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "../packet.h" |
|
#include "device.h" |
#include "netif.h" |
#include "netif_device_id_type.h" |
|
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_IRQ( call ) ( int ) IPC_GET_ARG2( * call ) |
#define IPC_GET_IO( call ) ( int ) IPC_GET_ARG3( * call ) |
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
|
extern netif_globals_t netif_globals; |
|
extern int netif_initialize( void ); |
extern void netif_print_name( void ); |
extern int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
extern int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
extern int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
extern int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
extern int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
extern int initialize( void ); |
extern int probe_auto_message( void ); |
extern int probe_message( device_id_t device_id, int irq, int io ); |
extern int send_message( device_id_t device_id, packet_t packet ); |
extern int start_message( device_id_t device_id ); |
extern int stop_message( device_id_t device_id ); |
|
DEVICE_MAP_IMPLEMENT( netif_device_map, netif_device_t ) |
DEVICE_MAP_IMPLEMENT( device_map, device_t ) |
|
int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )); |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
int netif_start_module( async_client_conn_t client_connection ); |
int register_message( device_id_t device_id, int phone ); |
int get_device_stats( device_id_t device_id, device_stats_ref * stats ); |
|
int netif_device_find( netif_device_id_t device_id, netif_device_ref * device ){ |
* device = netif_device_map_find( & netif_globals.netif_device_map, device_id ); |
int find_device( device_id_t device_id, device_ref * device ){ |
* device = device_map_find( & netif_globals.device_map, device_id ); |
if( ! * device ) return ENOENT; |
if(( ** device ).state == NETIF_NULL ) return EPERM; |
return EOK; |
} |
|
void netif_device_stats_null( netif_device_stats_ref stats ) |
{ |
//memset( stats, 0, sizeof( netif_device_t )); |
stats->rx_packets = 0; |
int get_device_stats( device_id_t device_id, device_stats_ref * stats ){ |
ERROR_DECLARE; |
|
device_ref device; |
|
if( ! stats ) return EINVAL; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
* stats = & device->stats; |
return EOK; |
} |
|
void null_device_stats( device_stats_ref stats ){ |
memset( stats, 0, sizeof( device_stats_t )); |
/* stats->rx_packets = 0; |
stats->tx_packets = 0; |
stats->rx_bytes = 0; |
stats->tx_bytes = 0; |
94,58 → 112,65 |
stats->tx_window_errors = 0; |
stats->rx_compressed = 0; |
stats->tx_compressed = 0; |
*/ |
} |
|
int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
int register_message( device_id_t device_id, int phone ){ |
ERROR_DECLARE; |
|
device_ref device; |
|
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->nil_phone ) return ELIMIT; |
device->nil_phone = phone; |
return EOK; |
} |
|
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
|
size_t length; |
netif_device_ref device; |
device_stats_ref stats; |
packet_t packet; |
|
// printf( "\nNETIF message %d", method ); |
switch( method ){ |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NETIF_PROBE_AUTO: |
return netif_probe_auto_message( arg1, arg2, arg3, result1, result2, result3 ); |
return probe_auto_message(); |
case NET_NETIF_PROBE: |
return netif_probe_message( arg1, arg2, arg3, result1, result2, result3 ); |
case NET_NETIF_REGISTER: |
case NET_LL_REGISTER: |
ERROR_PROPAGATE( netif_device_find( arg1, & device )); |
device->ll_registered = connect_to_service( arg2 ); |
return EOK; |
return probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call )); |
case IPC_M_CONNECT_TO_ME: |
return register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call )); |
case NET_NETIF_SEND: |
return netif_send_message( arg1, arg2, arg3, result1, result2, result3 ); |
ERROR_PROPAGATE( packet_receive( & packet )); |
return send_message( IPC_GET_DEVICE( call ), packet ); |
case NET_NETIF_START: |
return netif_start_message( arg1, arg2, arg3, result1, result2, result3 ); |
return start_message( IPC_GET_DEVICE( call )); |
case NET_NETIF_STATS: |
ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length )); |
if( length < sizeof( netif_device_stats_t )){ |
ipc_answer_0( callid, EOVERFLOW ); |
return EOVERFLOW; |
} |
if( ERROR_OCCURED( netif_device_find( arg1, & device ))){ |
ipc_answer_0( callid, ERROR_CODE ); |
return ERROR_CODE; |
} |
return ipc_data_read_finalize( callid, & device->stats, sizeof( netif_device_stats_t )); |
if( length < sizeof( device_stats_t )) return EOVERFLOW; |
ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats )); |
return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t )); |
case NET_NETIF_STOP: |
return netif_stop_message( arg1, arg2, arg3, result1, result2, result3 ); |
return stop_message( IPC_GET_DEVICE( call )); |
} |
return ENOTSUP; |
} |
|
int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){ |
services_t need[ 2 ]; |
int * need_phone[ 2 ]; |
int netif_start_module( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
|
need[ 0 ] = SERVICE_NETWORKING; |
need[ 1 ] = NULL; |
need_phone[ 0 ] = & netif_globals.networking_phone; |
need_phone[ 1 ] = NULL; |
netif_device_map_initialize( & netif_globals.netif_device_map ); |
return start_service( NULL, need, need_phone, client_connection, netif_initialize ); |
async_set_client_connection( client_connection ); |
netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
device_map_initialize( & netif_globals.device_map ); |
ERROR_PROPAGATE( initialize()); |
|
async_manager(); |
|
return EOK; |
} |
|
/** @} |