/branches/network/uspace/srv/net/net/net_standalone.c |
---|
0,0 → 1,123 |
/* |
* 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 |
* @{ |
*/ |
/** @file |
* |
*/ |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include "../messages.h" |
#include "../include/ip_interface.h" |
#include "../structures/measured_strings.h" |
#include "../structures/module_map.h" |
#include "../structures/packet/packet_server.h" |
#include "net.h" |
extern net_globals_t net_globals; |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
if( IS_NET_PACKET_MESSAGE( call )){ |
return packet_server_message( callid, call, answer, answer_count ); |
}else{ |
return net_message( callid, call, answer, answer_count ); |
} |
} |
int net_initialize( void ){ |
ERROR_DECLARE; |
task_id_t task_id; |
netifs_initialize( & net_globals.netifs ); |
char_map_initialize( & net_globals.netif_names ); |
modules_initialize( & net_globals.modules ); |
measured_strings_initialize( & net_globals.configuration ); |
// run self tests |
// ERROR_PROPAGATE( self_test()); |
ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service )); |
ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service )); |
ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service )); |
task_id = spawn( "/srv/ip" ); |
if( ! task_id ) return EINVAL; |
ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id, ip_connect_module )); |
// if( ! spawn( "/srv/udp" )) return EINVAL; |
// if( ! spawn( "/srv/tcp" )) return EINVAL; |
// if( ! spawn( "/srv/socket" )) return EINVAL; |
// not always necesssary |
// if( ! spawn( "/srv/arp" )) return EINVAL; |
// if( ! spawn( "/srv/rarp" )) return EINVAL; |
// if( ! spawn( "/srv/icmp" )) return EINVAL; |
return EOK; |
} |
int read_netif_configuration( char * name, netif_ref netif ){ |
ERROR_DECLARE; |
if( strncmp( name, "lo", 2 ) == 0 ){ |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
}else if( strncmp( name, "ne2k", 4 ) == 0 ){ |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
// standalone ethernet |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )); |
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" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
} |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/net/net_bundle.c |
---|
0,0 → 1,155 |
/* |
* 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 |
* @{ |
*/ |
/** @file |
* |
*/ |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include "../messages.h" |
#include "../include/ip_interface.h" |
#include "../structures/measured_strings.h" |
#include "../structures/module_map.h" |
#include "../structures/packet/packet_server.h" |
#include "../il/arp/arp_module.h" |
#include "../il/ip/ip_module.h" |
#include "net.h" |
extern net_globals_t net_globals; |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
if( IS_NET_IL_MESSAGE( call )){ |
switch( IPC_GET_TARGET( call )){ |
case SERVICE_IP: |
return ip_message( callid, call, answer, answer_count ); |
default: |
return EINVAL; |
} |
}else if( IS_NET_IP_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 ); |
/* }else if( IS_NET_RARP_MESSAGE( call )){ |
return rarp_message( callid, call, answer, answer_count ); |
}else if( IS_NET_ICMP_MESSAGE( call )){ |
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 )){ |
return tcp_message( callid, call, answer, answer_count ); |
}else if( IS_NET_SOCKET_MESSAGE( call )){ |
return socket_message( callid, call, answer, answer_count ); |
*/ }else{ |
if( IS_NET_PACKET_MESSAGE( call )){ |
return packet_server_message( callid, call, answer, answer_count ); |
}else{ |
return net_message( callid, call, answer, answer_count ); |
} |
} |
} |
int net_initialize( void ){ |
ERROR_DECLARE; |
ipcarg_t phonehash; |
netifs_initialize( & net_globals.netifs ); |
char_map_initialize( & net_globals.netif_names ); |
modules_initialize( & net_globals.modules ); |
measured_strings_initialize( & net_globals.configuration ); |
// run self tests |
// ERROR_PROPAGATE( self_test()); |
ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service )); |
ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service )); |
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( REGISTER_ME( SERVICE_ARP, & phonehash )); |
ERROR_PROPAGATE( arp_initialize()); |
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash )); |
// ERROR_PROPAGATE( rarp_initialize()); |
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash )); |
// ERROR_PROPAGATE( icmp_initialize()); |
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash )); |
// ERROR_PROPAGATE( udp_initialize()); |
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash )); |
// ERROR_PROPAGATE( tcp_initialize()); |
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash )); |
// ERROR_PROPAGATE( socket_initialize()); |
// ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash )); |
// ERROR_PROPAGATE( ethernet_initialize()); |
return EOK; |
} |
int read_netif_configuration( char * name, netif_ref netif ){ |
ERROR_DECLARE; |
if( strncmp( name, "lo", 2 ) == 0 ){ |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
}else if( strncmp( name, "ne2k", 4 ) == 0 ){ |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
// ethernet bundled in dp8390 |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME )); |
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" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
} |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/net/net_remote.c |
---|
0,0 → 1,68 |
/* |
* 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 |
* @{ |
*/ |
/** @file |
*/ |
#include <ipc/services.h> |
#include <malloc.h> |
#include "../messages.h" |
#include "../modules.h" |
#include "../include/device.h" |
#include "../include/net_interface.h" |
#include "../structures/measured_strings.h" |
//#include "net_messages.h" |
int net_get_device_conf_req( int net_phone, device_id_t device_id, measured_string_ref * configuration, int count, char ** data ){ |
return generic_translate_req( net_phone, NET_NET_GET_DEVICE_CONF, device_id, 0, * configuration, count, configuration, data ); |
} |
int net_get_conf_req( int net_phone, measured_string_ref * configuration, int count, char ** data ){ |
return generic_translate_req( net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, * configuration, count, configuration, data ); |
} |
void net_free_settings( measured_string_ref settings, char * data ){ |
if( settings ) free( settings ); |
if( data ) free( data ); |
} |
int net_connect_module( services_t service ){ |
return connect_to_service( SERVICE_NETWORKING ); |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/net/net.c |
---|
0,0 → 1,386 |
/* |
* 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 |
* @{ |
*/ |
/** @file |
*/ |
#include <async.h> |
#include <ctype.h> |
#include <ddi.h> |
#include <errno.h> |
#include <malloc.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../err.h" |
#include "../messages.h" |
#include "../modules.h" |
//#include "../self_test.h" |
#include "../structures/char_map.h" |
#include "../structures/generic_char_map.h" |
#include "../structures/measured_strings.h" |
#include "../structures/module_map.h" |
#include "../structures/packet/packet.h" |
#include "../il/il_messages.h" |
#include "../include/device.h" |
#include "../include/netif_interface.h" |
#include "../include/nil_interface.h" |
#include "../include/net_interface.h" |
#include "../include/ip_interface.h" |
#include "net.h" |
#define NAME "Networking" |
void module_print_name( void ); |
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name ); |
int module_start( async_client_conn_t client_connection ); |
//int parse_line( measured_strings_ref configuration, char * line ); |
int read_configuration( void ); |
int start_device( netif_ref netif ); |
int startup( void ); |
device_id_t generate_new_device_id( void ); |
int net_get_conf( measured_strings_ref device_conf, measured_string_ref configuration, int count, char ** data ); |
net_globals_t net_globals; |
DEVICE_MAP_IMPLEMENT( netifs, netif_t ) |
GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t ) |
void module_print_name( void ){ |
printf( "%s", NAME ); |
} |
int module_start( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
ipcarg_t phonehash; |
async_set_client_connection( client_connection ); |
ERROR_PROPAGATE( pm_init()); |
if( ERROR_OCCURRED( net_initialize()) |
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){ |
pm_destroy(); |
return ERROR_CODE; |
} |
async_manager(); |
pm_destroy(); |
return EOK; |
} |
int net_get_device_conf_req( int net_phone, device_id_t device_id, measured_string_ref * configuration, int count, char ** data ){ |
netif_ref netif; |
if( !( configuration && ( count > 0 ))) return EINVAL; |
netif = netifs_find( & net_globals.netifs, device_id ); |
if( netif ){ |
return net_get_conf( & netif->configuration, * configuration, count, data ); |
}else{ |
return net_get_conf( NULL, * configuration, count, data ); |
} |
} |
int net_get_conf_req( int net_phone, measured_string_ref * configuration, int count, char ** data ){ |
if( !( configuration && ( count > 0 ))) return EINVAL; |
return net_get_conf( NULL, * configuration, count, data ); |
} |
int net_get_conf( measured_strings_ref device_conf, measured_string_ref configuration, int count, char ** data ){ |
measured_string_ref setting; |
int index; |
if( data ) * data = NULL; |
for( index = 0; index < count; ++ index ){ |
setting = measured_strings_find( device_conf, configuration[ index ].value, 0 ); |
if( ! setting ){ |
setting = measured_strings_find( & net_globals.configuration, configuration[ index ].value, 0 ); |
} |
if( setting ){ |
configuration[ index ].length = setting->length; |
configuration[ index ].value = setting->value; |
}else{ |
configuration[ index ].length = 0; |
configuration[ index ].value = NULL; |
} |
} |
return EOK; |
} |
void net_free_settings( measured_string_ref settings, char * data ){ |
} |
int net_connect_module( services_t service ){ |
return EOK; |
} |
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
measured_string_ref strings; |
char * data; |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NET_DEVICE: |
// TODO configure, register |
printf( "Networking: new netif %d\n", IPC_GET_DEVICE( call )); |
return EOK; |
case NET_NET_GET_DEVICE_CONF: |
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call ))); |
net_get_device_conf_req( 0, IPC_GET_DEVICE( call ), & strings, IPC_GET_COUNT( call ), NULL ); |
// strings should not contain received data anymore |
free( data ); |
ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call )); |
free( strings ); |
return ERROR_CODE; |
case NET_NET_GET_CONF: |
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call ))); |
net_get_conf_req( 0, & strings, IPC_GET_COUNT( call ), NULL ); |
// strings should not contain received data anymore |
free( data ); |
ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call )); |
free( strings ); |
return ERROR_CODE; |
case NET_NET_STARTUP: |
return startup(); |
} |
return ENOTSUP; |
} |
/* |
int parse_line( measured_strings_ref configuration, char * line ){ |
ERROR_DECLARE; |
measured_string_ref setting; |
char * name; |
char * value; |
// from the beginning |
name = line; |
// skip spaces |
while( isspace( * name )) ++ name; |
// remember the name start |
value = name; |
// skip the name |
while( isalnum( * value ) || ( * value == '_' )){ |
// make uppercase |
// * value = toupper( * value ); |
++ value; |
} |
if( * value == '=' ){ |
// terminate the name |
* value = '\0'; |
}else{ |
// terminate the name |
* value = '\0'; |
// skip until '=' |
++ value; |
while(( * value ) && ( * value != '=' )) ++ value; |
// not found? |
if( * value != '=' ) return EINVAL; |
} |
++ value; |
// skip spaces |
while( isspace( * value )) ++ value; |
// create a bulk measured string till the end |
setting = measured_string_create_bulk( value, -1 ); |
if( ! setting ) return ENOMEM; |
// add the configuration setting |
if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ |
free( setting ); |
return ERROR_CODE; |
} |
return EOK; |
} |
*/ |
int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){ |
ERROR_DECLARE; |
measured_string_ref setting; |
setting = measured_string_create_bulk( value, 0 ); |
if( ! setting ) return ENOMEM; |
// add the configuration setting |
if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ |
free( setting ); |
return ERROR_CODE; |
} |
return EOK; |
} |
device_id_t generate_new_device_id( void ){ |
return device_assign_devno(); |
} |
int read_configuration( void ){ |
ERROR_DECLARE; |
// read general configuration |
ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "IPV", "4" )); |
ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "MTU", "1500" )); |
return EOK; |
} |
int start_device( netif_ref netif ){ |
ERROR_DECLARE; |
measured_string_ref setting; |
services_t internet_service; |
int irq; |
int io; |
int mtu; |
// mandatory netif |
setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 ); |
netif->driver = get_running_module( & net_globals.modules, setting->value ); |
if( ! netif->driver ){ |
printf( "Failed to start the network interface driver %s\n", setting->value ); |
return EINVAL; |
} |
// optional network interface layer |
setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 ); |
if( setting ){ |
netif->nil = get_running_module( & net_globals.modules, setting->value ); |
if( ! netif->nil ){ |
printf( "Failed to start the network interface layer %s\n", setting->value ); |
return EINVAL; |
} |
}else{ |
netif->nil = NULL; |
} |
// mandatory internet layer |
setting = measured_strings_find( & netif->configuration, CONF_IL, 0 ); |
netif->il = get_running_module( & net_globals.modules, setting->value ); |
if( ! netif->il ){ |
printf( "Failed to start the internet layer %s\n", setting->value ); |
return EINVAL; |
} |
// end of the static loopback initialization |
// startup the loopback interface |
setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 ); |
irq = setting ? strtol( setting->value, NULL, 10 ) : 0; |
setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); |
io = setting ? strtol( setting->value, NULL, 16 ) : 0; |
ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io )); |
if( netif->nil ){ |
setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); |
if( ! setting ){ |
setting = measured_strings_find( & net_globals.configuration, CONF_MTU, 0 ); |
} |
mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
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; |
} |
switch( netif->il->service ){ |
case SERVICE_IP: |
ERROR_PROPAGATE( ip_device_req( netif->il->phone, netif->id, internet_service )); |
break; |
default: |
return ENOENT; |
} |
ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id )); |
return EOK; |
} |
int startup( void ){ |
ERROR_DECLARE; |
char * conf_files[] = { "lo", "ne2k" }; |
int count = sizeof( conf_files ) / sizeof( char * ); |
int index; |
netif_ref netif; |
int i; |
measured_string_ref setting; |
// TODO dynamic configuration |
ERROR_PROPAGATE( read_configuration()); |
for( i = 0; i < count; ++ i ){ |
netif = ( netif_ref ) malloc( sizeof( netif_t )); |
if( ! netif ) return ENOMEM; |
netif->id = generate_new_device_id(); |
if( ! netif->id ) return EXDEV; |
ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); |
// read configuration files |
if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif ))){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
// mandatory name |
setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 ); |
if( ! setting ){ |
printf( "The name is missing\n" ); |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
netif->name = setting->value; |
// add to the netifs map |
index = netifs_add( & net_globals.netifs, netif->id, netif ); |
if( index < 0 ){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return index; |
} |
// add to the netif names map |
if( ERROR_OCCURRED( char_map_add( & net_globals.netif_names, netif->name, 0, index )) |
// start network interfaces and needed modules |
|| ERROR_OCCURRED( start_device( netif ))){ |
measured_strings_destroy( & netif->configuration ); |
netifs_exclude_index( & net_globals.netifs, index ); |
return ERROR_CODE; |
} |
// increment modules' usage |
++ netif->driver->usage; |
if( netif->nil ) ++ netif->nil->usage; |
++ netif->il->usage; |
printf( "New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name ); |
} |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/net/net.h |
---|
0,0 → 1,125 |
/* |
* 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 |
* @{ |
*/ |
/** @file |
* Networking subsystem compilation configuration. |
*/ |
#ifndef __NET_NET_H__ |
#define __NET_NET_H__ |
#include <ipc/ipc.h> |
#include "../include/device.h" |
#include "../structures/char_map.h" |
#include "../structures/generic_char_map.h" |
#include "../structures/measured_strings.h" |
#include "../structures/module_map.h" |
#include "../structures/packet/packet.h" |
#define LO_NAME "lo" |
#define LO_FILENAME "/srv/lo" |
#define DP8390_NAME "dp8390" |
#define DP8390_FILENAME "/srv/dp8390" |
#define ETHERNET_NAME "ethernet" |
#define ETHERNET_FILENAME "/srv/eth" |
#define IP_NAME "ip" |
#define IP_FILENAME "/srv/ip" |
#define CONF_NAME "NAME" |
#define CONF_NETIF "NETIF" |
#define CONF_NIL "NIL" |
#define CONF_IL "IL" |
#define CONF_IRQ "IRQ" |
#define CONF_IO "IO" |
#define CONF_MTU "MTU" |
typedef struct netif netif_t; |
typedef netif_t * netif_ref; |
typedef struct net_globals net_globals_t; |
DEVICE_MAP_DECLARE( netifs, netif_t ) |
GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t ) |
/** A present network interface device. |
*/ |
struct netif{ |
/** A system-unique network interface identifier. |
*/ |
device_id_t id; |
/** A serving network interface driver module index. |
*/ |
module_ref driver; |
/** A serving link layer module index. |
*/ |
module_ref nil; |
/** A serving internet layer module index. |
*/ |
module_ref il; |
/** A system-unique network interface name. |
*/ |
char * name; |
/** Configuration. |
*/ |
measured_strings_t configuration; |
}; |
/** A net module global variables. |
*/ |
struct net_globals{ |
/** Present network interfaces. |
*/ |
netifs_t netifs; |
/** Network interface structure indices by names. |
*/ |
char_map_t netif_names; |
/** Available modules. |
*/ |
modules_t modules; |
/** Global configuration. |
*/ |
measured_strings_t configuration; |
}; |
int add_configuration( measured_strings_ref configuration, const char * name, const char * value ); |
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
int net_initialize( void ); |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
int read_netif_configuration( char * name, netif_ref netif ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/net/Makefile |
---|
0,0 → 1,70 |
# |
# 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. |
# |
NAME = net |
NET_BASE = ../ |
STRUCTURES = $(NET_BASE)structures/ |
include $(NET_BASE)../../../Makefile.config |
## Sources |
# |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME).c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(STRUCTURES)char_map.c \ |
$(STRUCTURES)measured_strings.c \ |
$(STRUCTURES)module_map.c \ |
$(STRUCTURES)packet/packet.c \ |
$(STRUCTURES)packet/packet_client.c \ |
$(STRUCTURES)packet/packet_server.c \ |
$(NET_BASE)netif/netif_remote.c |
# $(NET_BASE)self_test.c |
ifeq ($(NETWORKING), module) |
SOURCES += $(NAME)_bundle.c \ |
$(NET_BASE)il/arp/arp.c \ |
$(NET_BASE)il/ip/ip.c \ |
$(NET_BASE)sockaddr.c |
# $(NET_BASE)tl/tcp/tcp.c |
else |
SOURCES += $(NAME)_standalone.c \ |
$(NET_BASE)il/arp/arp_remote.c \ |
$(NET_BASE)il/ip/ip_remote.c \ |
# $(NET_BASE)tl/tcp/tcp_remote.c |
endif |
include $(NET_BASE)Makefile.module |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/net/start/netstart.c |
---|
0,0 → 1,113 |
/* |
* 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 |
* @{ |
*/ |
/** @file |
* Starts the net subsystem. |
* Performs self test if configured so. |
* @see configuration.h |
*/ |
#include <async.h> |
#include <stdio.h> |
#include <task.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../self_test.h" |
/** Networking startup module name. |
*/ |
#define NAME "Networking startup" |
/** Module entry point. |
* @param argc The number of command line parameters. Input parameter. |
* @param argv The command line parameters. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the net module cannot be started. |
* @returns Other error codes as defined for the self_test() function. |
* @returns Other error codes as defined for the NET_NET_STARTUP message. |
*/ |
int main( int argc, char * argv[] ); |
/** Starts the module. |
* @param fname The module absolute name. Input parameter. |
* @returns The started module task identifier. |
* @returns Other error codes as defined for the task_spawn() function. |
*/ |
task_id_t spawn( char * fname ); |
int main( int argc, char * argv[] ){ |
ERROR_DECLARE; |
int net_phone; |
printf( "Task %d - ", task_get_id()); |
printf( "%s\n", NAME ); |
// run self tests |
ERROR_PROPAGATE( self_test()); |
// start net service |
if( ! spawn( "/srv/net" )){ |
printf( "Could not spawn net\n" ); |
return EINVAL; |
} |
// start net |
net_phone = connect_to_service( SERVICE_NETWORKING ); |
if( ERROR_OCCURRED( ipc_call_sync_0_0( net_phone, NET_NET_STARTUP ))){ |
printf( "ERROR %d\n", ERROR_CODE ); |
return ERROR_CODE; |
} |
printf( "OK\n" ); |
return EOK; |
} |
task_id_t spawn( char * fname ){ |
char * argv[ 2 ]; |
task_id_t res; |
// printf( "Spawning %s\n", fname ); |
argv[ 0 ] = fname; |
argv[ 1 ] = NULL; |
res = task_spawn( fname, argv ); |
if( res != 0 ){ |
/* Success */ |
usleep( 50000 ); |
} |
return res; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/net/start/Makefile |
---|
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. |
# |
NAME = netstart |
NET_BASE = ../../ |
STRUCTURES = $(NET_BASE)structures/ |
include ../../../../../Makefile.config |
## Sources |
# |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME).c \ |
$(NET_BASE)modules.c \ |
$(NET_BASE)self_test.c \ |
$(STRUCTURES)char_map.c \ |
$(STRUCTURES)measured_strings.c \ |
$(NET_BASE)crc.c |
include $(NET_BASE)Makefile.module |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/net/start |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/net/. |
---|
Property changes: |
Added: svn:mergeinfo |