Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4350 → Rev 4351

/branches/network/uspace/srv/net/nil/eth/eth.c
256,7 → 256,7
* @returns EINVAL if the packet is bigger than the device MTU.
* @returns ENOMEM if there is not enough memory in the packet.
*/
int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype );
int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype, size_t mtu );
 
DEVICE_MAP_IMPLEMENT( eth_devices, eth_device_t )
 
270,7 → 270,7
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 ) il_device_state_msg( proto->phone, device_id, state );
if( proto && proto->phone ) il_device_state_msg( proto->phone, device_id, state, proto->service );
}
rwlock_read_unlock( & eth_globals.protos_lock );
return EOK;
535,7 → 535,7
return EOK;
}
 
int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype ){
int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype, size_t mtu ){
eth_header_ex_ref header;
eth_header_ref header_dix;
eth_fcs_ref fcs;
550,8 → 550,7
if( length < 0 ) return length;
if( length < ETH_ADDR ) return EINVAL;
length = packet_get_data_length( packet );
//TODO smaller than MTU!
if( length > ETH_MAX_TAGGED_CONTENT( flags )) return EINVAL;
if( length > mtu ) return EINVAL;
if( length < ETH_MIN_TAGGED_CONTENT( flags )){
padding = packet_suffix( packet, ETH_MIN_TAGGED_CONTENT( flags ) - length );
if( ! padding ) return ENOMEM;
613,7 → 612,7
// process packet queue
next = packet;
do{
if( ERROR_OCCURRED( eth_prepare_packet( device->flags, next, ( uint8_t * ) device->addr->value, ethertype ))){
if( ERROR_OCCURRED( eth_prepare_packet( device->flags, next, ( uint8_t * ) device->addr->value, ethertype, device->mtu ))){
// release invalid packet
tmp = pq_detach( next );
pq_release( eth_globals.net_phone, packet_get_id( next ));
/branches/network/uspace/srv/net/nil/nil_remote.c
46,7 → 46,7
#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 );
return generic_device_state_msg( nil_phone, NET_NIL_DEVICE_STATE, device_id, state, 0 );
}
 
int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ){
/branches/network/uspace/srv/net/structures/packet/packet_remote.c
54,8 → 54,8
* @param packet_id The packet identifier. Input parameter.
* @param size The packet total size in bytes. Input parameter.
* @returns EOK on success.
* \todo ipc_share_in_start() error?
* @returns Other error codes as defined for the pm_add() function.
* @returns Other error codes as defined for the ipc_share_in_start() function.
*/
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size );
 
/branches/network/uspace/srv/net/structures/packet/packet_server.h
49,9 → 49,11
* @param call The message parameters. Input parameter.
* @param answer The message answer parameters. Output parameter.
* @param answer_count The last parameter for the actual answer in the answer parameter. Output parameter.
* \todo all possible message returns?
* @returns EOK on success.
* @returns ENOMEM if there is not enough memory left.
* @returns ENOENT if there is no such packet as in the packet message parameter..
* @returns ENOTSUP if the message is not known.
* @returns Other error codes as defined for the packet_release_wrapper() function.
*/
int packet_server_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
 
/branches/network/uspace/srv/net/structures/packet/packet_client.h
166,7 → 166,7
* @returns EOK on success.
* @returns EINVAL if the packet parameter is NULL.
* @returns Other error codes as defined for the NET_PACKET_GET_SIZE message.
* \todo errors as packet_return()
* @returns Other error codes as defined for the packet_return() function.
*/
int packet_translate( int phone, packet_ref packet, packet_id_t packet_id );
 
179,7 → 179,6
* @param max_suffix The maximal suffix length in bytes. Input parameter.
* @returns The packet reference.
* @returns NULL on error.
* \todo error as NET_PACKET_CREATE_4, packet_return()
*/
packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix );
 
189,7 → 188,6
* @param content The maximal content length in bytes. Input parameter.
* @returns The packet reference.
* @returns NULL on error.
* \todo error as NET_PACKET_CREATE_1, packet_return()
*/
packet_t packet_get_1( int phone, size_t content );
 
/branches/network/uspace/srv/net/structures/packet/packet_server.c
104,7 → 104,10
*/
packet_t packet_get( size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix );
 
/** \todo
/** Releases the packet queue.
* @param packet_id The first packet identifier. Input parameter.
* @returns EOK on success.
* @returns ENOENT if there is no such packet.
*/
int packet_release_wrapper( packet_id_t packet_id );
 
/branches/network/uspace/srv/net/include/protocol_map.h
52,6 → 52,7
static inline int protocol_map( services_t nil, services_t il ){
switch( nil ){
case SERVICE_ETHERNET:
case SERVICE_DP8390:
switch( il ){
case SERVICE_IP:
return ETH_P_IP;
74,6 → 75,7
static inline services_t protocol_unmap( services_t nil, int protocol ){
switch( nil ){
case SERVICE_ETHERNET:
case SERVICE_DP8390:
switch( protocol ){
case ETH_P_IP:
return SERVICE_IP;
/branches/network/uspace/srv/net/include/il_interface.h
55,10 → 55,11
* @param il_phone The internetwork layer module phone used for (semi)remote calls. Input parameter.
* @param device_id The device identifier. Input parameter.
* @param state The new device state. Input parameter.
* @param target The target internetwork module service to be delivered to. Input parameter.
* @returns EOK on success.
*/
static inline int il_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){
return generic_device_state_msg( il_phone, NET_IL_DEVICE_STATE, device_id, state );
static inline int il_device_state_msg( int il_phone, device_id_t device_id, device_state_t state, services_t target ){
return generic_device_state_msg( il_phone, NET_IL_DEVICE_STATE, device_id, state, target );
}
 
/** Notifies the internetwork layer modules about the received packet/s.
/branches/network/uspace/srv/net/include/ip_interface.h
68,7 → 68,13
*/
int ip_device_req( int ip_phone, device_id_t device_id, services_t netif );
 
/** \todo
/** Sends the packet queue.
* @param ip_phone The internet protocol phone. Input parameter.
* @param device_id The device identifier. Input parameter.
* @param packet The packet queue. Input parameter.
* @param sender The sending module service. Input parameter.
* @returns EOK on success.
* @returns Other error codes as defined for the generic_send_msg() function.
*/
int ip_send_msg( int ip_phone, device_id_t device_id, packet_t packet, services_t sender );
 
/branches/network/uspace/srv/net/net/net_standalone.c
60,7 → 60,7
}
}
 
int net_initialize( void ){
int net_initialize( async_client_conn_t client_connection ){
ERROR_DECLARE;
 
task_id_t task_id;
/branches/network/uspace/srv/net/net/net_bundle.c
66,7 → 66,7
default:
return EINVAL;
}
}else if( IS_NET_IP_MESSAGE( call )){
}else if( IS_NET_IP_MESSAGE( call ) || IS_NET_NIL_MESSAGE( call )){
return ip_message( callid, call, answer, answer_count );
}else if( IS_NET_ARP_MESSAGE( call )){
return arp_message( callid, call, answer, answer_count );
89,7 → 89,7
}
}
 
int net_initialize( void ){
int net_initialize( async_client_conn_t client_connection ){
ERROR_DECLARE;
 
ipcarg_t phonehash;
107,21 → 107,21
 
ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module ));
ERROR_PROPAGATE( ip_initialize());
ERROR_PROPAGATE( ip_initialize( client_connection ));
ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
ERROR_PROPAGATE( arp_initialize());
ERROR_PROPAGATE( arp_initialize( client_connection ));
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
// ERROR_PROPAGATE( rarp_initialize());
// ERROR_PROPAGATE( rarp_initialize( client_connection ));
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
// ERROR_PROPAGATE( icmp_initialize());
// ERROR_PROPAGATE( icmp_initialize( client_connection ));
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
// ERROR_PROPAGATE( udp_initialize());
// ERROR_PROPAGATE( udp_initialize( client_connection ));
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
// ERROR_PROPAGATE( tcp_initialize());
// ERROR_PROPAGATE( tcp_initialize( client_connection ));
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash ));
// ERROR_PROPAGATE( socket_initialize());
// ERROR_PROPAGATE( socket_initialize( client_connection ));
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash ));
// ERROR_PROPAGATE( ethernet_initialize());
// ERROR_PROPAGATE( ethernet_initialize( client_connection ));
return EOK;
}
 
/branches/network/uspace/srv/net/net/net.c
148,7 → 148,7
 
async_set_client_connection( client_connection );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( net_initialize())
if( ERROR_OCCURRED( net_initialize( client_connection ))
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){
pm_destroy();
return ERROR_CODE;
/branches/network/uspace/srv/net/net/net.h
196,10 → 196,11
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
 
/** Initializes the networking module.
* @param client_connection The client connection processing function. The module skeleton propagates its own one. Input parameter.
* @returns EOK on success.
* @returns ENOMEM if there is not enough memory left.
*/
int net_initialize( void );
int net_initialize( async_client_conn_t client_connection );
 
/** Processes the module message.
* Distributes the message to the right bundled module.
/branches/network/uspace/srv/net/messages.h
201,8 → 201,8
return ( int ) async_req_1_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t * ) addr_len, ( ipcarg_t * ) prefix, ( ipcarg_t * ) content, ( ipcarg_t * ) suffix );
}
 
static inline int generic_device_state_msg( int phone, int message, device_id_t device_id, int state ){
async_msg_2( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) state );
static inline int generic_device_state_msg( int phone, int message, device_id_t device_id, int state, services_t target ){
async_msg_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) state, target );
return EOK;
}
 
/branches/network/uspace/srv/net/il/arp/arp.c
139,12 → 139,6
*/
void clear_device( arp_device_ref device );
 
/** Processes IPC messages from the registered device driver modules in an infinite loop.
* @param iid The message identifier. Input parameter.
* @param icall The message parameters. Input/output parameter.
*/
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall );
 
DEVICE_MAP_IMPLEMENT( arp_cache, arp_device_t )
 
INT_MAP_IMPLEMENT( arp_protos, arp_proto_t )
222,11 → 216,12
}
}
 
int arp_initialize( void ){
int arp_initialize( async_client_conn_t client_connection ){
ERROR_DECLARE;
 
rwlock_initialize( & arp_globals.lock );
rwlock_write_lock( & arp_globals.lock );
arp_globals.client_connection = client_connection;
ERROR_PROPAGATE( arp_cache_initialize( & arp_globals.cache ));
rwlock_write_unlock( & arp_globals.lock );
return EOK;
308,7 → 303,7
}
device->service = service;
// bind the new one
device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver );
device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_globals.client_connection );
if( device->phone < 0 ){
rwlock_write_unlock( & arp_globals.lock );
arp_protos_destroy( & device->protos );
480,6 → 475,7
measured_string_ref address;
measured_string_ref translation;
char * data;
packet_t packet;
 
// printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_ARP_FIRST );
* answer_count = 0;
510,35 → 506,19
return arp_clear_device_req( 0, IPC_GET_DEVICE( call ));
case NET_ARP_CLEAN_CACHE:
return arp_clean_cache_req( 0 );
case NET_IL_DEVICE_STATE:
// do nothing - keep the cache
return EOK;
case NET_IL_RECEIVED:
if( ! ERROR_OCCURRED( packet_translate( arp_globals.net_phone, & packet, IPC_GET_PACKET( call )))){
rwlock_read_lock( & arp_globals.lock );
ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( call ), packet );
rwlock_read_unlock( & arp_globals.lock );
}
return ERROR_CODE;
}
return ENOTSUP;
}
 
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ){
ERROR_DECLARE;
 
packet_t packet;
 
while( true ){
switch( IPC_GET_METHOD( * icall )){
case NET_IL_DEVICE_STATE:
// do nothing - keep the cache
ipc_answer_0( iid, EOK );
break;
case NET_IL_RECEIVED:
if( ! ERROR_OCCURRED( packet_translate( arp_globals.net_phone, & packet, IPC_GET_PACKET( icall )))){
rwlock_read_lock( & arp_globals.lock );
ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( icall ), packet );
rwlock_read_unlock( & arp_globals.lock );
}
ipc_answer_0( iid, ERROR_CODE );
break;
default:
ipc_answer_0( iid, ENOTSUP );
}
iid = async_get_call( icall );
}
}
 
/** @}
*/
/branches/network/uspace/srv/net/il/arp/arp.h
167,6 → 167,10
/** ARP address cache.
*/
arp_cache_t cache;
/** The client connection processing function.
* The module skeleton propagates its own one.
*/
async_client_conn_t client_connection;
};
 
#endif
/branches/network/uspace/srv/net/il/arp/arp_module.c
97,7 → 97,7
async_set_client_connection( client_connection );
arp_globals.net_phone = net_connect_module( SERVICE_NETWORKING );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( arp_initialize())
if( ERROR_OCCURRED( arp_initialize( client_connection ))
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_ARP, & phonehash ))){
pm_destroy();
return ERROR_CODE;
/branches/network/uspace/srv/net/il/arp/arp_module.h
41,10 → 41,11
#include <ipc/ipc.h>
 
/** Initializes the ARP module.
* @param client_connection The client connection processing function. The module skeleton propagates its own one. Input parameter.
* @returns EOK on success.
* @returns ENOMEM if there is not enough memory left.
*/
int arp_initialize( void );
int arp_initialize( async_client_conn_t client_connection );
 
/** Processes the ARP message.
* @param callid The message identifier. Input parameter.
/branches/network/uspace/srv/net/il/ip/ip_module.h
38,7 → 38,7
 
#include <ipc/ipc.h>
 
int ip_initialize( void );
int ip_initialize( async_client_conn_t client_connection );
int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
 
#endif
/branches/network/uspace/srv/net/il/ip/ip.c
75,17 → 75,17
 
INT_MAP_IMPLEMENT( ip_protos, ip_proto_t )
 
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall );
int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state );
int ip_register( int il_phone, int protocol, int phone );
 
/** Initializes the module.
*/
int ip_initialize( void ){
int ip_initialize( async_client_conn_t client_connection ){
ERROR_DECLARE;
 
ERROR_PROPAGATE( ip_netifs_initialize( & ip_globals.netifs ));
ERROR_PROPAGATE( ip_protos_initialize( & ip_globals.protos ));
ip_globals.client_connection = client_connection;
ERROR_PROPAGATE( modules_initialize( & ip_globals.modules ));
ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, arp_task_get_id(), arp_connect_module ));
return EOK;
149,7 → 149,7
}
net_free_settings( configuration, data );
}
ip_netif->phone = bind_service( netif, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver );
ip_netif->phone = bind_service( netif, ip_netif->device_id, SERVICE_IP, 0, ip_globals.client_connection );
if( ip_netif->phone < 0 ){
printf( "Failed to contact the nil service %d\n", netif );
free( ip_netif );
192,53 → 192,6
return EOK;
}
 
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){
ERROR_DECLARE;
 
ipc_callid_t callid;
ipc_call_t call;
// ipc_call_t answer;
// int count;
int result;
packet_t packet;
 
/*
* Accept the connection
* - Answer the first IPC_M_CONNECT_ME_TO call.
*/
ipc_answer_0( iid, EOK );
 
while( true ){
/* // refresh data
count = 0;
IPC_SET_RETVAL( answer, 0 );
// just to be precize
IPC_SET_RETVAL( answer, 0 );
IPC_SET_ARG1( answer, 0 );
IPC_SET_ARG2( answer, 0 );
IPC_SET_ARG3( answer, 0 );
IPC_SET_ARG4( answer, 0 );
IPC_SET_ARG5( answer, 0 );
*/
callid = async_get_call( & call );
switch( IPC_GET_METHOD( call )){
case NET_IL_DEVICE_STATE:
case NET_NIL_DEVICE_STATE:
result = ip_device_state_msg( 0, IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call ));
ipc_answer_0( callid, result );
break;
// TODO packer received
case NET_IL_RECEIVED:
case NET_NIL_RECEIVED:
if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( & call )))){
//result = il_receive_msg( 0, IPC_GET_DEVICE( call ), packet );
}
ipc_answer_0( callid, result );
break;
}
}
}
 
int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){
// ERROR_DECLARE;
 
315,6 → 268,14
case NET_IL_SEND:
ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call )));
return ip_send_msg( 0, IPC_GET_DEVICE( call ), packet, 0 );
case NET_IL_DEVICE_STATE:
case NET_NIL_DEVICE_STATE:
return ip_device_state_msg( 0, IPC_GET_DEVICE( call ), IPC_GET_STATE( call ));
// TODO packet received
case NET_IL_RECEIVED:
case NET_NIL_RECEIVED:
ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call )));
//return il_receive_msg( 0, IPC_GET_DEVICE( call ), packet );
}
return ENOTSUP;
}
/branches/network/uspace/srv/net/il/ip/ip.h
81,6 → 81,7
ip_netifs_t netifs;
ip_protos_t protos;
modules_t modules;
async_client_conn_t client_connection;
};
 
#endif
/branches/network/uspace/srv/net/il/ip/ip_module.c
69,7 → 69,7
async_set_client_connection( client_connection );
ip_globals.net_phone = net_connect_module( SERVICE_NETWORKING );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( ip_initialize())
if( ERROR_OCCURRED( ip_initialize( client_connection ))
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_IP, & phonehash ))){
pm_destroy();
return ERROR_CODE;
/branches/network/uspace/srv/net/netif/dp8390/dp8390.c
271,7 → 271,6
// strncpy((char *) dep->de_address.ea_addr, "ZDP", 6);
// dep->de_address.ea_addr[5] = port;
// dp_confaddr(dep);
//TODO ether address?
// reply_mess.m_type = DL_CONF_REPLY;
// reply_mess.m3_i1 = mp->DL_PORT;
// reply_mess.m3_i2 = DE_PORT_NR;
280,7 → 279,6
// return;
return EOK;
}
//TODO assert?
assert(dep->de_mode == DEM_ENABLED);
assert(dep->de_flags & DEF_ENABLED);
 
296,7 → 294,6
// dep->de_client = mp->m_source;
dp_reinit(dep);
 
//TODO ether address?
// reply_mess.m_type = DL_CONF_REPLY;
// reply_mess.m3_i1 = mp->DL_PORT;
// reply_mess.m3_i2 = DE_PORT_NR;
/branches/network/uspace/srv/net/netif/dp8390/dp8390_module.c
74,11 → 74,7
.value = 1,
.srcarg = 2
},
/* { .cmd = CMD_PIO_WRITE_8,
.addr = NULL,
.value = 0
},
*/ {
{
.cmd = CMD_ACCEPT
}
};
/branches/network/uspace/srv/net/netif/lo/lo.c
104,7 → 104,6
void module_print_name( void );
 
int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
//TODO nil send message
return ENOTSUP;
}