36,14 → 36,15 |
#include <async.h> |
#include <errno.h> |
#include <stdio.h> |
|
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/mman.h> |
|
#include "../err.h" |
#include "../measured_strings.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "../packet.h" |
|
#include "netif.h" |
|
53,49 → 54,45 |
|
netif_globals_t netif_globals; |
|
void change_state( netif_device_ref device, netif_state_t state ); |
int change_state_message( netif_device_id_t device_id, netif_state_t state ); |
int netif_create( netif_device_id_t device_id, netif_device_ref * device ); |
int netif_call( ipc_callid_t callid ); |
int netif_initialize( void ); |
int change_state_message( device_id_t device_id, device_state_t state ); |
int create( device_id_t device_id, device_ref * device ); |
int initialize( void ); |
void netif_print_name( void ); |
int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
int probe_auto_message( void ); |
int probe_message( device_id_t device_id, int irq, int io ); |
int send_message( device_id_t device_id, packet_t packet ); |
int start_message( device_id_t device_id ); |
int stop_message( device_id_t device_id ); |
|
void change_state( netif_device_ref device, netif_state_t state ){ |
device->state = state; |
ll_message( device, NET_LL_DEVICE_STATE_CHANGED, device->state, NULL, NULL, NULL, NULL ); |
} |
|
int change_state_message( netif_device_id_t device_id, netif_state_t state ){ |
int change_state_message( device_id_t device_id, device_state_t state ){ |
ERROR_DECLARE; |
|
netif_device_ref device; |
device_ref device; |
|
ERROR_PROPAGATE( netif_device_find( device_id, & device )); |
change_state( device, state ); |
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != state ){ |
device->state = state; |
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL, NULL, NULL, NULL ); |
} |
return EOK; |
} |
|
int netif_create( netif_device_id_t device_id, netif_device_ref * device ){ |
int create( device_id_t device_id, device_ref * device ){ |
ERROR_DECLARE; |
|
if( netif_device_map_count( & netif_globals.netif_device_map ) > 0 ){ |
if( device_map_count( & netif_globals.device_map ) > 0 ){ |
return EXDEV; |
}else{ |
* device = ( netif_device_ref ) malloc( sizeof( netif_device_t )); |
* device = ( device_ref ) malloc( sizeof( device_t )); |
if( !( * device )) return ENOMEM; |
( ** device ).device_id = device_id; |
( ** device ).ll_registered = -1; |
( ** device ).nil_phone = -1; |
( ** device ).specific = NULL; |
netif_device_stats_null( &(( ** device ).stats )); |
null_device_stats( &(( ** device ).stats )); |
( ** device ).state = NETIF_STOPPED; |
( ** device ).flags = NULL; |
( ** device ).mtu = DEFAULT_MTU; |
if( ERROR_OCCURED( netif_device_map_add( & netif_globals.netif_device_map, ( ** device ).device_id, * device ))){ |
if( ERROR_OCCURED( device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ))){ |
free( * device ); |
* device = NULL; |
return ERROR_CODE; |
104,11 → 101,7 |
return EOK; |
} |
|
int netif_call( ipc_callid_t callid ){ |
return EOK; |
} |
|
int netif_initialize( void ){ |
int initialize( void ){ |
ipcarg_t phonehash; |
|
return REGISTER_ME( SERVICE_LO, & phonehash ); |
118,20 → 111,20 |
printf( NAME ); |
} |
|
int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
int probe_auto_message( void ){ |
/* ERROR_DECLARE; |
|
netif_device_ref device; |
device_ref device; |
|
ERROR_PROPAGATE( netif_create( arg1, & device )); |
ipc_call_sync_3_3( netif_globals.networking_phone, NET_NETWORKING_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
ERROR_PROPAGATE( create( arg1, & device )); |
ipc_call_sync_3_3( netif_globals.networking_phone, NET_NET_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
*/ return ENOTSUP; |
} |
|
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
int probe_message( device_id_t device_id, int irq, int io ){ |
ERROR_DECLARE; |
|
netif_device_ref device; |
device_ref device; |
aid_t message; |
ipc_call_t answer; |
measured_string_t configuration[ 1 ] = {{ "MTU", 3 }}; |
140,9 → 133,9 |
char * data; |
|
// create a new device |
ERROR_PROPAGATE( netif_create( arg1, & device )); |
ERROR_PROPAGATE( create( device_id, & device )); |
// get configuration |
message = async_send_2( netif_globals.networking_phone, NET_NETWORKING_GET_DEVICE_CONFIGURATION, device->device_id, count, & answer ); |
message = async_send_2( netif_globals.networking_phone, NET_NET_GET_DEVICE_CONF, device->device_id, count, & answer ); |
// send names and get settings |
if( ERROR_OCCURED( measured_strings_send( netif_globals.networking_phone, configuration, count )) |
|| ERROR_OCCURED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){ |
156,7 → 149,7 |
device->mtu = DEFAULT_MTU; |
} |
// print the settings |
printf("\n -MTU=%d", device->mtu ); |
printf("\n -MTU =\t%d", device->mtu ); |
free( settings ); |
free( data ); |
// end request |
164,31 → 157,44 |
return EOK; |
} |
|
int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
int send_message( device_id_t device_id, packet_t packet ){ |
ERROR_DECLARE; |
|
netif_device_ref device; |
device_ref device; |
size_t length; |
aid_t message; |
ipc_call_t answer; |
ipcarg_t result; |
packet_t received; |
|
ERROR_PROPAGATE( netif_device_find( arg1, & device )); |
if( device->state == NETIF_ACTIVE ){ |
++ device->stats.tx_packets; |
++ device->stats.rx_packets; |
// TODO packet size |
//device->stats->tx_bytes += ; |
//device->stats->rx_bytes += ; |
ll_message( device, NET_LL_RECEIVED, arg2, NULL, NULL, NULL, NULL ); |
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != NETIF_ACTIVE ) return EPERM; |
++ device->stats.tx_packets; |
++ device->stats.rx_packets; |
length = packet_get_data_length( packet ); |
device->stats.tx_bytes += length; |
device->stats.rx_bytes += length; |
received = packet_copy( packet ); |
packet_destroy( packet ); |
if( ! received ){ |
++ device->stats.rx_dropped; |
return EOK; |
}else{ |
return EPERM; |
} |
message = async_send_1( device->nil_phone, NET_NIL_RECEIVED, ( device_id ), & answer ); |
if( ERROR_OCCURED( packet_send( received, device->nil_phone ))){ |
++ device->stats.rx_dropped; |
} |
async_wait_for( message, & result ); |
if( result != EOK ) ++ device->stats.rx_dropped; |
return EOK; |
} |
|
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
return change_state_message( arg1, NETIF_ACTIVE ); |
int start_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_ACTIVE ); |
} |
|
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
return change_state_message( arg1, NETIF_STOPPED ); |
int stop_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_STOPPED ); |
} |
|
/** @} |