/branches/network/uspace/app/init/init.c |
---|
107,7 → 107,7 |
// FIXME: spawn("/sbin/pci"); |
spawn("/sbin/fb"); |
spawn("/sbin/kbd"); |
spawn("/sbin/networking"); |
spawn("/sbin/networking_startup"); |
spawn("/sbin/console"); |
console_wait(); |
/branches/network/uspace/lib/libc/include/ipc/services.h |
---|
45,6 → 45,9 |
SERVICE_VFS, |
SERVICE_DEVMAP, |
SERVICE_NETWORKING, |
SERVICE_LO, |
SERVICE_DP8390_ISA, |
SERVICE_ETHERNET, |
SERVICE_IP, |
SERVICE_ARP, |
SERVICE_RARP, |
51,8 → 54,7 |
SERVICE_ICMP, |
SERVICE_UDP, |
SERVICE_TCP, |
SERVICE_SOCKET, |
SERVICE_ETHERNET |
SERVICE_SOCKET |
} services_t; |
/* Memory area to be received from NS */ |
/branches/network/uspace/srv/net/tcp/tcp.c |
---|
40,25 → 40,27 |
#include <ipc/services.h> |
//#include <sys/mman.h> |
#include "../err.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "tcp.h" |
struct { |
int ip_phone; |
} tcp_globals; |
tcp_globals_t tcp_globals; |
/** Initializes the module. |
*/ |
int tcp_initialize( void ){ |
ipcarg_t arg1, arg2; |
ERROR_DECLARE; |
printf( "TCP - testing to send IP:\t" ); |
ERROR_PROPAGATE( ip_message( NET_IP_ECHO, 12, 34, NULL, & arg1, & arg2, NULL )); |
if(( arg1 != 12 ) || ( arg2 != 34 )) return EINVAL; |
printf( "OK\n" ); |
ipcarg_t arg1, arg2; |
// printf( "TCP - testing to send IP:\t" ); |
// ERROR_PROPAGATE( ip_message( NET_IP_ECHO, 12, 34, NULL, & arg1, & arg2, NULL )); |
// if(( arg1 != 12 ) || ( arg2 != 34 )) return EINVAL; |
// printf( "OK\n" ); |
// ERROR_PROPAGATE( ip_message( NET_IP_TCP_REGISTER, NULL, NULL, NULL, NULL, NULL, NULL )); |
return EOK; |
} |
66,8 → 68,9 |
return EOK; |
} |
int tcp_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 ){ |
int tcp_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 ){ |
switch( method ){ |
// case IPC_M_CONNECT_ME_TO: |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
} |
/branches/network/uspace/srv/net/tcp/tcp.h |
---|
47,9 → 47,16 |
#endif |
#endif |
typedef struct tcp_globals tcp_globals_t; |
struct tcp_globals{ |
int ip_phone; |
int networking_phone; |
}; |
int tcp_initialize( void ); |
int tcp_call( ipc_callid_t callid ); |
int tcp_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 ); |
int tcp_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 ); |
#endif |
/branches/network/uspace/srv/net/tcp/tcp_module.c |
---|
34,61 → 34,35 |
*/ |
#include <async.h> |
#include <errno.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/mman.h> |
#include "../modules.h" |
#include "tcp.h" |
extern struct { |
int ip_phone; |
} tcp_globals; |
#define NAME "TCP protocol" |
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ); |
int main( int argc, char * argv[] ); |
void tcp_print_name( void ); |
int tcp_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )); |
/** Default thread for new connections. |
*/ |
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ){ |
ipc_callid_t callid; |
ipc_call_t call; |
ipcarg_t arg1, arg2, arg3; |
int res; |
extern tcp_globals_t tcp_globals; |
/* Accept the connection */ |
ipc_answer_0( iid, EOK ); |
while( true ){ |
callid = async_get_call( & call ); |
arg1 = 0; |
arg2 = 0; |
arg3 = 0; |
res = tcp_call( callid ); |
if( res == EOK ){ |
res = tcp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 ); |
void tcp_print_name( void ){ |
printf( NAME ); |
} |
ipc_answer_2( callid, EOK, arg1, arg2 ); |
} |
} |
/** Starts the module. |
* Parameters are ignored. |
*/ |
int main( int argc, char * argv[] ){ |
services_t need[ 2 ]; |
int * need_phone[ 2 ]; |
int tcp_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){ |
services_t need[ 3 ]; |
int * need_phone[ 3 ]; |
printf("tcp : HelenOS TCP network protocol\n"); |
need[ 0 ] = SERVICE_IP; |
need[ 1 ] = NULL; |
need[ 1 ] = SERVICE_NETWORKING; |
need[ 2 ] = NULL; |
need_phone[ 0 ] = & tcp_globals.ip_phone; |
need_phone[ 1 ] = NULL; |
need_phone[ 1 ] = & tcp_globals.networking_phone; |
need_phone[ 2 ] = NULL; |
return start_service( SERVICE_TCP, need, need_phone, client_connection, tcp_initialize ); |
} |
/branches/network/uspace/srv/net/tcp/Makefile |
---|
44,8 → 44,11 |
SOURCES = \ |
$(NAME)_module.c \ |
$(NAME).c \ |
../module.c \ |
../modules.c |
DEFS += -D NETWORKING_$(NETWORKING) -D $(NAME)_call=module_call -D $(NAME)_message=module_message -D $(NAME)_start_module=module_start -D $(NAME)_print_name=module_print_name |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
.PHONY: all clean depend disasm |
75,4 → 78,4 |
$(AS) $(AFLAGS) $< -o $@ |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -D NETWORKING_$(NETWORKING) -c $< -o $@ |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
/branches/network/uspace/srv/net/networking/networking.c |
---|
34,16 → 34,27 |
*/ |
#include <async.h> |
#include <ctype.h> |
#include <errno.h> |
#include <malloc.h> |
#include <stdio.h> |
#include <task.h> |
//#include <thread.h> |
#include <unistd.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/mman.h> |
#include "../char_map.h" |
#include "../err.h" |
#include "../generic_char_map.h" |
#include "../measured_strings.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "../messages.h" |
//#include "../self_test.h" |
#include "../netif/netif_device_id_type.h" |
#ifdef NETWORKING_module |
#include "../ip/ip.h" |
51,96 → 62,121 |
#endif |
#define IS_IN_INTERVAL( item, first_inclusive, last_exclusive ) ((( item ) >= ( first_inclusive )) && (( item ) < ( last_exclusive ))) |
#define LO_NAME "lo" |
#define LO_FILENAME "/sbin/lo" |
#define DP8390_ISA_NAME "dp8390_isa" |
#define DP8390_ISA_FILENAME "/sbin/dp8380_isa" |
#define ETHERNET_NAME "ethernet" |
#define ETHERNET_FILENAME "/sbin/ethernet" |
#define IP_NAME "ip" |
#define IP_FILENAME "/sbin/ip" |
#define IS_NET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_FIRST, NET_LAST ) |
#define IS_NET_NETWORKING_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_NETWORKING_FIRST, NET_NETWORKING_LAST ) |
#define IS_NET_IP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_IP_FIRST, NET_IP_LAST ) |
#define IS_NET_ARP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_ARP_FIRST, NET_ARP_LAST ) |
#define IS_NET_RARP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_RARP_FIRST, NET_RARP_LAST ) |
#define IS_NET_UDP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_UDP_FIRST, NET_UDP_LAST ) |
#define IS_NET_TCP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_TCP_FIRST, NET_TCP_LAST ) |
#define IS_NET_SOCKET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_SOCKET_FIRST, NET_SOCKET_LAST ) |
#define IS_NET_ETHERNET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_ETHERNET_FIRST, NET_SOCKET_LAST ) |
typedef struct module_struct module_t; |
typedef module_t * module_ref; |
int networking_initialize( void ); |
typedef struct netif netif_t; |
typedef netif_t * netif_ref; |
typedef struct networking_globals networking_globals_t; |
DEVICE_MAP_DECLARE( netifs, netif_t ) |
GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t ) |
GENERIC_CHAR_MAP_DECLARE( modules, module_t ) |
struct module_struct{ |
task_id_t task_id; |
services_t service; |
int phone; |
int usage; |
const char * name; |
const char * filename; |
}; |
/** A present network interface device. |
*/ |
struct netif{ |
/** A system-unique network interface identifier. |
*/ |
netif_device_id_t id; |
/** A serving network interface driver module index. |
*/ |
module_ref driver_module; |
/** A serving link layer module index. |
*/ |
module_ref link_layer_module; |
/** A serving internet layer module index. |
*/ |
module_ref internet_layer_module; |
/** A system-unique network interface name. |
*/ |
char * name; |
/** Configuration. |
*/ |
measured_strings_t configuration; |
}; |
/** A networking module global variables. |
*/ |
struct networking_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_module( module_ref * module, modules_ref modules, const char const * name, const char const * filename, services_t service, task_id_t task_id ); |
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ); |
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name ); |
int main( int argc, char * argv[] ); |
int spawn( const char * fname ); |
int networking_call( ipc_callid_t callid ); |
int networking_initialize( void ); |
int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 ); |
//int parse_line( measured_strings_ref configuration, char * line ); |
int add_configuration( measured_strings_ref configuration, const char * name, const char * value ); |
int read_configuration( void ); |
task_id_t spawn( const char * fname ); |
int startup( void ); |
netif_device_id_t generate_new_device_id( void ); |
int networking_call( ipc_callid_t callid ){ |
return EOK; |
} |
static networking_globals_t networking_globals; |
int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 ){ |
switch( method ){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
} |
return ENOTSUP; |
} |
DEVICE_MAP_IMPLEMENT( netifs, netif_t ) |
int spawn(const char *fname) |
{ |
const char *argv[2]; |
int res; |
GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t ) |
printf("Spawning %s\n", fname); |
GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t ) |
argv[0] = fname; |
argv[1] = NULL; |
int add_module( module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id ){ |
ERROR_DECLARE; |
res = task_spawn(fname, argv); |
if( res != 0 ){ |
/* Success */ |
sleep(1); |
}else return EINVAL; |
module_ref tmp_module; |
return EOK; |
tmp_module = ( module_ref ) malloc( sizeof( module_t )); |
if( ! tmp_module ) return ENOMEM; |
tmp_module->task_id = task_id; |
tmp_module->phone = 0; |
tmp_module->usage = 0; |
tmp_module->name = name; |
tmp_module->filename = filename; |
tmp_module->service = service; |
if( ERROR_OCCURED( modules_add( modules, tmp_module->name, tmp_module ))){ |
free( tmp_module ); |
return ERROR_CODE; |
} |
/** Initializes the module. |
*/ |
int networking_initialize( void ){ |
ERROR_DECLARE; |
#ifdef NETWORKING_modular |
ERROR_PROPAGATE( spawn("/sbin/ip")); |
// ERROR_PROPAGATE( spawn("/sbin/arp")); |
// ERROR_PROPAGATE( spawn("/sbin/rarp")); |
// ERROR_PROPAGATE( spawn("/sbin/icmp")); |
// ERROR_PROPAGATE( spawn("/sbin/udp")); |
ERROR_PROPAGATE( spawn("/sbin/tcp")); |
// ERROR_PROPAGATE( spawn("/sbin/socket")); |
#else |
#ifdef NETWORKING_module |
ipcarg_t phonehash; |
ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
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()); |
#endif |
#endif |
if( module ) * module = tmp_module; |
return EOK; |
} |
/** Default thread for new connections. |
*/ |
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ){ |
ipc_callid_t callid; |
ipc_call_t call; |
156,7 → 192,7 |
arg2 = 0; |
arg3 = 0; |
#ifdef NETWORKING_module |
if( IS_NET_IP_MESSAGE( call )){ |
if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){ |
res = ip_call( callid ); |
if( res == EOK ){ |
res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 ); |
191,7 → 227,7 |
if( res == EOK ){ |
res = socket_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 ); |
} |
*//* }else if( IS_NET_ETHERNET_MESSAGE( call )){ |
*//* }else if( IS_NET_LL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){ |
res = ethernet_call( callid ); |
if( res == EOK ){ |
res = ethernet_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 ); |
205,19 → 241,406 |
#ifdef NETWORKING_module |
} |
#endif |
ipc_answer_2( callid, EOK, arg1, arg2 ); |
ipc_answer_2( callid, res, arg1, arg2 ); |
} |
} |
/** Starts the module. |
* Parameters are ignored. |
*/ |
int main( int argc, char * argv[] ){ |
printf("networking : HelenOS Networking subsystem\n"); |
printf("\nTask %d - Networking: HelenOS Networking subsystem\n", task_get_id()); |
return start_service( SERVICE_NETWORKING, NULL, NULL, client_connection, networking_initialize ); |
} |
int networking_call( ipc_callid_t callid ){ |
return EOK; |
} |
int networking_initialize( void ){ |
ERROR_DECLARE; |
task_id_t task_id; |
netifs_initialize( & networking_globals.netifs ); |
char_map_initialize( & networking_globals.netif_names ); |
modules_initialize( & networking_globals.modules ); |
measured_strings_initialize( & networking_globals.configuration ); |
// run self tests |
// ERROR_PROPAGATE( self_test()); |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0 )); |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, DP8390_ISA_NAME, DP8390_ISA_FILENAME, SERVICE_DP8390_ISA, 0 )); |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0 )); |
#ifdef NETWORKING_modular |
task_id = spawn( "/sbin/ip" ); |
if( ! task_id ) return EINVAL; |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id )); |
// if( ! spawn( "/sbin/udp" )) return EINVAL; |
if( ! spawn( "/sbin/tcp" )) return EINVAL; |
// if( ! spawn( "/sbin/socket" )) return EINVAL; |
// not always necesssary |
// if( ! spawn( "/sbin/arp" )) return EINVAL; |
// if( ! spawn( "/sbin/rarp" )) return EINVAL; |
// if( ! spawn( "/sbin/icmp" )) return EINVAL; |
#else |
#ifdef NETWORKING_module |
ipcarg_t phonehash; |
ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id())); |
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()); |
#endif |
#endif |
return EOK; |
} |
int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
ERROR_DECLARE; |
measured_string_ref strings; |
char * data; |
int index; |
measured_string_ref setting; |
measured_strings_ref configuration; |
netif_ref netif; |
// printf( "\nNetworking message: %d\n", method ); |
switch( method ){ |
// case IPC_M_CONNECT_ME_TO: |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NETWORKING_DEVICE: |
// TODO configure, register |
// arg1 = netif id |
printf( "\nNetworking: new netif %d", arg1 ); |
return EOK; |
case NET_NETWORKING_GET_DEVICE_CONFIGURATION: |
// arg1 = netif id |
// arg2 = count |
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg2 )); |
netif = netifs_find( & networking_globals.netifs, arg1 ); |
if( netif ){ |
configuration = & netif->configuration; |
}else{ |
configuration = NULL; |
} |
for( index = 0; index < arg2; ++ index ){ |
setting = measured_strings_find( configuration, strings[ index ].value ); |
if( ! setting ){ |
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value ); |
} |
if( setting ){ |
strings[ index ].length = setting->length; |
strings[ index ].value = setting->value; |
}else{ |
strings[ index ].length = 0; |
strings[ index ].value = NULL; |
} |
} |
// strings should not contain received data anymore |
free( data ); |
ERROR_CODE = measured_strings_reply( strings, arg2 ); |
free( strings ); |
return ERROR_CODE; |
case NET_NETWORKING_GET_CONFIGURATION: |
// arg1 = count |
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg1 )); |
for( index = 0; index < arg1; ++ index ){ |
setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value ); |
if( setting ){ |
strings[ index ].length = setting->length; |
strings[ index ].value = setting->value; |
}else{ |
strings[ index ].length = 0; |
strings[ index ].value = NULL; |
} |
} |
// strings should not contain received data anymore |
free( data ); |
ERROR_CODE = measured_strings_reply( strings, arg1 ); |
free( strings ); |
return ERROR_CODE; |
case NET_NETWORKING_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_OCCURED( measured_strings_add( configuration, name, 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_OCCURED( measured_strings_add( configuration, name, setting ))){ |
free( setting ); |
return ERROR_CODE; |
} |
return EOK; |
} |
netif_device_id_t generate_new_device_id( void ){ |
return netifs_count( & networking_globals.netifs ) + 1; |
} |
int read_configuration( void ){ |
ERROR_DECLARE; |
netif_ref netif; |
measured_string_ref setting; |
services_t internet_service; |
// read general configuration |
ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" )); |
// read network interfaces configuration |
// static loopback initialization |
printf( "\nloopback initialization" ); |
netif = ( netif_ref ) malloc( sizeof( netif_t )); |
if( ! netif ) return ENOMEM; |
netif->id = generate_new_device_id(); |
ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); |
if( ERROR_OCCURED( add_configuration( & netif->configuration, "NAME", LO_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "NETIF", LO_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IL", IP_NAME )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )) |
|| ERROR_OCCURED( add_configuration( & netif->configuration, "NETMASK", "255.255.255.255" )) |
){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
// mandatory name |
printf( "\n\tname" ); |
setting = measured_strings_find( & netif->configuration, "NAME" ); |
if( ! setting ){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
netif->name = setting->value; |
printf( " %s OK", netif->name ); |
// mandatory netif |
printf( "\n\tnetif" ); |
setting = measured_strings_find( & netif->configuration, "NETIF" ); |
if( ! setting ){ |
printf( " unknown" ); |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
// printf( " find %s in %d?", setting->value, modules_count( & networking_globals.modules )); |
netif->driver_module = modules_find( & networking_globals.modules, setting->value ); |
if( ! netif->driver_module ){ |
printf( " not found" ); |
// TODO register the unknown one |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
printf( " found" ); |
if( ! netif->driver_module->task_id ){ |
netif->driver_module->task_id = spawn( netif->driver_module->filename ); |
if( ! netif->driver_module->task_id ){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
} |
if( ! netif->driver_module->phone ){ |
printf( " connect?" ); |
netif->driver_module->phone = connect_to_service( netif->driver_module->service ); |
} |
printf( " connected" ); |
if( ERROR_OCCURED( ipc_call_sync_1_0( netif->driver_module->phone, NET_NETIF_PROBE, netif->id ))){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
++ netif->driver_module->usage; |
printf( " OK" ); |
// optional link layer |
printf( "\n\tlink layer" ); |
setting = measured_strings_find( & netif->configuration, "LL" ); |
if( setting ){ |
netif->link_layer_module = modules_find( & networking_globals.modules, setting->value ); |
if( ! netif->link_layer_module ){ |
// TODO register the unknown one |
-- netif->driver_module->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
if( ! netif->link_layer_module->task_id ){ |
netif->link_layer_module->task_id = spawn( netif->link_layer_module->filename ); |
if( ! netif->link_layer_module->task_id ){ |
-- netif->driver_module->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
} |
if( ! netif->link_layer_module->phone ){ |
netif->link_layer_module->phone = connect_to_service( netif->link_layer_module->service ); |
} |
if( ERROR_OCCURED( ipc_call_sync_2_0( netif->link_layer_module->phone, NET_LL_DEVICE, netif->id, netif->driver_module->service ))){ |
-- netif->driver_module->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
++ netif->link_layer_module->usage; |
internet_service = netif->link_layer_module->service; |
printf( " OK" ); |
}else{ |
internet_service = netif->driver_module->service; |
printf( " none" ); |
} |
// mandatory internet layer |
printf( "\n\tinternet layer" ); |
setting = measured_strings_find( & netif->configuration, "IL" ); |
if( ! setting ){ |
-- netif->driver_module->usage; |
-- netif->link_layer_module->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
printf( " set %s", setting->value ); |
netif->internet_layer_module = modules_find( & networking_globals.modules, setting->value ); |
if( ! netif->internet_layer_module ){ |
// TODO register the unknown one |
-- netif->driver_module->usage; |
-- netif->link_layer_module->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
printf( " found" ); |
if( ! netif->internet_layer_module->task_id ){ |
netif->internet_layer_module->task_id = spawn( netif->internet_layer_module->filename ); |
if( ! netif->internet_layer_module->task_id ){ |
-- netif->driver_module->usage; |
-- netif->link_layer_module->usage; |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return EINVAL; |
} |
} |
if( ! netif->internet_layer_module->phone ){ |
printf( " connect" ); |
netif->internet_layer_module->phone = connect_to_service( netif->internet_layer_module->service ); |
} |
if( ERROR_OCCURED( ipc_call_sync_2_0( netif->internet_layer_module->phone, NET_IL_DEVICE, netif->id, internet_service ))){ |
measured_strings_destroy( & netif->configuration ); |
free( netif ); |
return ERROR_CODE; |
} |
++ netif->internet_layer_module->usage; |
printf( " OK" ); |
if( ERROR_OCCURED( netifs_add( & networking_globals.netifs, netif->id, netif ))){ |
free( netif ); |
return ERROR_CODE; |
} |
printf( "\nloopback OK" ); |
// end of static loopback initialization |
return EOK; |
} |
task_id_t spawn( const char * fname ){ |
const 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; |
} |
int startup( void ){ |
ERROR_DECLARE; |
// read configuration files |
if( ERROR_OCCURED( read_configuration())) return ERROR_CODE; |
// start network interfaces and needed modules |
// start_device( "/sbin/lo", "/sbin/dummy_link_layer" ); |
return EOK; |
} |
/** @} |
*/ |
/branches/network/uspace/srv/net/networking/Makefile |
---|
32,6 → 32,7 |
LIBC_PREFIX = ../../../lib/libc |
SOFTINT_PREFIX = ../../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
include ../../../../Makefile.config |
LIBS = $(LIBC_PREFIX)/libc.a |
41,7 → 42,10 |
OUTPUT = networking |
SOURCES = \ |
networking.c \ |
../char_map.c \ |
../measured_strings.c \ |
../modules.c |
# ../self_test.c |
ifeq ($(NETWORKING), module) |
SOURCES += ../ip/ip.c \ |
48,6 → 52,8 |
../tcp/tcp.c |
endif |
DEFS += -D NETWORKING_$(NETWORKING) |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
.PHONY: all clean depend disasm |
77,4 → 83,4 |
$(AS) $(AFLAGS) $< -o $@ |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -D NETWORKING_$(NETWORKING) -c $< -o $@ |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
/branches/network/uspace/srv/net/packet.c |
---|
0,0 → 1,42 |
/* |
* Copyright (c) 2008 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 |
*/ |
struct packet{ |
void * start; |
size_t length; |
}; |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/modules.c |
---|
33,12 → 33,10 |
/** @file |
*/ |
#include <async.h> |
#include <errno.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include <stdio.h> |
#include "err.h" |
#include "modules.h" |
#define MODULE_WAIT_TIME 10000 |
60,7 → 58,7 |
ipcarg_t phonehash; |
ERROR_DECLARE; |
if(( ! me ) || ( ! client_connection )) return EINVAL; |
if( ! client_connection ) return EINVAL; |
async_set_client_connection( client_connection ); |
if( need ){ |
79,7 → 77,7 |
if( initialize_me ) ERROR_PROPAGATE( initialize_me()); |
/* Register service at NS */ |
ERROR_PROPAGATE( REGISTER_ME( me, & phonehash )); |
if( me ) ERROR_PROPAGATE( REGISTER_ME( me, & phonehash )); |
async_manager(); |
/branches/network/uspace/srv/net/char_map.c |
---|
0,0 → 1,180 |
/* |
* Copyright (c) 2008 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 <errno.h> |
#include <malloc.h> |
#include <unistd.h> |
#include <string.h> |
#include "char_map.h" |
#define CHAR_MAP_MAGIC_VALUE 0x12345611 |
int char_map_add_item( char_map_ref map, const char * identifier, const int value ); |
char_map_ref char_map_find_node( char_map_ref map, const char * identifier ); |
int char_map_is_valid( char_map_ref map ); |
int char_map_add( char_map_ref map, const char * identifier, const int value ){ |
if( char_map_is_valid( map ) && ( * identifier )){ |
int index; |
for( index = 0; index < map->next; ++ index ){ |
if( map->items[ index ]->c == * identifier ){ |
++ identifier; |
if( * identifier ){ |
return char_map_add( map->items[ index ], identifier, value ); |
}else{ |
if( map->items[ index ]->value != CHAR_MAP_NULL ) return EEXISTS; |
map->items[ index ]->value = value; |
return EOK; |
} |
} |
} |
return char_map_add_item( map, identifier, value ); |
} |
return EINVAL; |
} |
int char_map_add_item( char_map_ref map, const char * identifier, const int value ){ |
if( map->next == ( map->size - 1 )){ |
char_map_ref * tmp; |
tmp = ( char_map_ref * ) malloc( sizeof( char_map_ref ) * 2 * map->size ); |
if( ! tmp ) return ENOMEM; |
map->size *= 2; |
memcpy( tmp, map->items, sizeof( char_map_ref ) * map->next ); |
free( map->items ); |
map->items = tmp; |
} |
map->items[ map->next ] = ( char_map_ref ) malloc( sizeof( char_map_t )); |
if( ! map->items[ map->next ] ) return ENOMEM; |
char_map_initialize( map->items[ map->next ] ); |
map->items[ map->next ]->c = * identifier; |
++ identifier; |
if( * identifier ){ |
map->items[ map->next ]->value = CHAR_MAP_NULL; |
char_map_add_item( map->items[ map->next ], identifier, value ); |
}else{ |
map->items[ map->next ]->value = value; |
} |
++ map->next; |
return EOK; |
} |
void char_map_destroy( char_map_ref map ){ |
if( char_map_is_valid( map )){ |
int index; |
map->magic = 0; |
for( index = 0; index < map->next; ++ index ){ |
char_map_destroy( map->items[ index ] ); |
} |
free( map->items ); |
} |
} |
int char_map_exclude( char_map_ref map, const char * identifier ){ |
char_map_ref node; |
node = char_map_find_node( map, identifier ); |
if( node ){ |
int value; |
value = node->value; |
node->value = CHAR_MAP_NULL; |
return value; |
} |
return CHAR_MAP_NULL; |
} |
int char_map_find( char_map_ref map, const char * identifier ){ |
char_map_ref node; |
node = char_map_find_node( map, identifier ); |
return node ? node->value : CHAR_MAP_NULL; |
} |
char_map_ref char_map_find_node( char_map_ref map, const char * identifier ){ |
if( ! char_map_is_valid( map )) return NULL; |
if( * identifier ){ |
int index; |
for( index = 0; index < map->next; ++ index ){ |
if( map->items[ index ]->c == * identifier ){ |
++ identifier; |
return char_map_find_node( map->items[ index ], identifier ); |
} |
} |
return NULL; |
} |
return map; |
} |
int char_map_get_value( char_map_ref map ){ |
return char_map_is_valid( map ) ? map->value : CHAR_MAP_NULL; |
} |
int char_map_initialize( char_map_ref map ){ |
if( ! map ) return EINVAL; |
map->c = 0; |
map->value = CHAR_MAP_NULL; |
map->size = 2; |
map->next = 0; |
map->items = malloc( sizeof( char_map_ref ) * map->size ); |
if( ! map->items ) return ENOMEM; |
map->items[ map->next ] = NULL; |
map->magic = CHAR_MAP_MAGIC_VALUE; |
return EOK; |
} |
int char_map_is_valid( char_map_ref map ){ |
return map && ( map->magic == CHAR_MAP_MAGIC_VALUE ); |
} |
int char_map_update( char_map_ref map, const char * identifier, const int value ){ |
char_map_ref node; |
// if( ! char_map_is_valid( map )) return EINVAL; |
node = char_map_find_node( map, identifier ); |
if( node ){ |
node->value = value; |
return EOK; |
}else{ |
return char_map_add( map, identifier, value ); |
} |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/generic_char_map.h |
---|
0,0 → 1,137 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __GENERIC_CHAR_MAP_H__ |
#define __GENERIC_CHAR_MAP_H__ |
#include <unistd.h> |
#include "char_map.h" |
#include "err.h" |
#include "generic_field.h" |
#define GENERIC_CHAR_MAP_MAGIC_VALUE 0x12345622 |
#define GENERIC_CHAR_MAP_DECLARE( name, type ) \ |
\ |
GENERIC_FIELD_DECLARE( name##_items, type ) \ |
\ |
typedef struct name name##_t; \ |
typedef name##_t * name##_ref; \ |
\ |
struct name{ \ |
char_map_t names; \ |
name##_items_t values; \ |
int magic; \ |
}; \ |
\ |
int name##_add( name##_ref map, const char * name, type * value ); \ |
int name##_count( name##_ref map ); \ |
void name##_destroy( name##_ref map ); \ |
void name##_exclude( name##_ref map, const char * name ); \ |
type * name##_find( name##_ref map, const char * name ); \ |
type * name##_get_index( name##_ref map, int index ); \ |
int name##_initialize( name##_ref map ); \ |
int name##_is_valid( name##_ref map ); |
#define GENERIC_CHAR_MAP_IMPLEMENT( name, type ) \ |
\ |
GENERIC_FIELD_IMPLEMENT( name##_items, type ) \ |
\ |
int name##_add( name##_ref map, const char * name, type * value ){ \ |
ERROR_DECLARE; \ |
int index; \ |
\ |
if( ! name##_is_valid( map )) return EINVAL; \ |
index = name##_items_add( & map->values, value ); \ |
if( index < 0 ) return index; \ |
if( ERROR_OCCURED( char_map_add( & map->names, name, index ))){ \ |
name##_items_exclude_index( & map->values, index ); \ |
return ERROR_CODE; \ |
} \ |
return EOK; \ |
} \ |
\ |
int name##_count( name##_ref map ){ \ |
return name##_is_valid( map ) ? name##_items_count( & map->values ) : -1; \ |
} \ |
\ |
void name##_destroy( name##_ref map ){ \ |
if( name##_is_valid( map )){ \ |
char_map_destroy( & map->names ); \ |
name##_items_destroy( & map->values ); \ |
} \ |
} \ |
\ |
void name##_exclude( name##_ref map, const char * name ){ \ |
if( name##_is_valid( map )){ \ |
int index; \ |
\ |
index = char_map_exclude( & map->names, name ); \ |
if( index != CHAR_MAP_NULL ){ \ |
name##_items_exclude_index( & map->values, index ); \ |
} \ |
} \ |
} \ |
\ |
type * name##_find( name##_ref map, const char * name ){ \ |
if( name##_is_valid( map )){ \ |
int index; \ |
\ |
index = char_map_find( & map->names, name ); \ |
if( index != CHAR_MAP_NULL ){ \ |
return name##_items_get_index( & map->values, index ); \ |
} \ |
} \ |
return NULL; \ |
} \ |
\ |
int name##_initialize( name##_ref map ){ \ |
if( ! map ) return EINVAL; \ |
char_map_initialize( & map->names ); \ |
name##_items_initialize( & map->values ); \ |
map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE; \ |
return EOK; \ |
} \ |
\ |
int name##_is_valid( name##_ref map ){ \ |
return map && ( map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE ); \ |
} |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/messages.h |
---|
33,29 → 33,92 |
/** @file |
*/ |
#define NET_NETIF_COUNT 7 |
#define NET_NETWORKING_COUNT 4 |
#define NET_LL_COUNT 5 |
#define NET_ETHERNET_COUNT 0 |
#define NET_IL_COUNT 2 |
#define NET_IP_COUNT 4 |
#define NET_ARP_COUNT 0 |
#define NET_RARP_COUNT 0 |
#define NET_ICMP_COUNT 0 |
#define NET_UDP_COUNT 0 |
#define NET_TCP_COUNT 0 |
#define NET_SOCKET_COUNT 0 |
#define NET_FIRST 2000 |
#define NET_NETWORKING_FIRST NET_FIRST |
#define NET_NETWORKING_LAST ( NET_NETWORKING_FIRST + 0 ) |
#define NET_IP_FIRST ( NET_NETWORKING_LAST + 0 ) |
#define NET_IP_LAST ( NET_IP_FIRST + 1 ) |
#define NET_NETIF_FIRST NET_FIRST |
#define NET_NETIF_LAST ( NET_NETIF_FIRST + NET_NETIF_COUNT ) |
#define NET_NETWORKING_FIRST ( NET_NETIF_LAST + 0 ) |
#define NET_NETWORKING_LAST ( NET_NETWORKING_FIRST + NET_NETWORKING_COUNT ) |
#define NET_LL_FIRST ( NET_NETWORKING_LAST + 0 ) |
#define NET_LL_LAST ( NET_LL_FIRST + NET_LL_COUNT ) |
#define NET_ETHERNET_FIRST ( NET_LL_LAST + 0 ) |
#define NET_ETHERNET_LAST ( NET_ETHERNET_FIRST + NET_ETHERNET_COUNT ) |
#define NET_IL_FIRST ( NET_ETHERNET_LAST + 0 ) |
#define NET_IL_LAST ( NET_IL_FIRST + NET_IL_COUNT ) |
#define NET_IP_FIRST ( NET_IL_LAST + 0 ) |
#define NET_IP_LAST ( NET_IP_FIRST + NET_IP_COUNT ) |
#define NET_ARP_FIRST ( NET_IP_LAST + 0 ) |
#define NET_ARP_LAST ( NET_ARP_FIRST + 0 ) |
#define NET_ARP_LAST ( NET_ARP_FIRST + NET_ARP_COUNT ) |
#define NET_RARP_FIRST ( NET_ARP_LAST + 0 ) |
#define NET_RARP_LAST ( NET_RARP_FIRST + 0 ) |
#define NET_RARP_LAST ( NET_RARP_FIRST + NET_RARP_COUNT ) |
#define NET_ICMP_FIRST ( NET_RARP_LAST + 0 ) |
#define NET_ICMP_LAST ( NET_ICMP_FIRST + 0 ) |
#define NET_ICMP_LAST ( NET_ICMP_FIRST + NET_ICMP_COUNT ) |
#define NET_UDP_FIRST ( NET_ICMP_LAST + 0 ) |
#define NET_UDP_LAST ( NET_UDP_FIRST + 0 ) |
#define NET_UDP_LAST ( NET_UDP_FIRST + NET_UDP_COUNT ) |
#define NET_TCP_FIRST ( NET_UDP_LAST + 0 ) |
#define NET_TCP_LAST ( NET_TCP_FIRST + 0 ) |
#define NET_TCP_LAST ( NET_TCP_FIRST + NET_TCP_COUNT ) |
#define NET_SOCKET_FIRST ( NET_TCP_LAST + 0 ) |
#define NET_SOCKET_LAST ( NET_SOCKET_FIRST + 0 ) |
#define NET_ETHERNET_FIRST ( NET_SOCKET_LAST + 0 ) |
#define NET_ETHERNET_LAST ( NET_ETHERNET_FIRST + 0 ) |
#define NET_LAST NET_ETHERNET_LAST |
#define NET_SOCKET_LAST ( NET_SOCKET_FIRST + NET_SOCKET_COUNT ) |
#define NET_LAST NET_SOCKET_LAST |
#define NET_COUNT ( NET_LAST - NET_FIRST ) |
#define IS_IN_INTERVAL( item, first_inclusive, last_exclusive ) ((( item ) >= ( first_inclusive )) && (( item ) < ( last_exclusive ))) |
#define IS_NET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_FIRST, NET_LAST ) |
#define IS_NET_NETWORKING_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_NETWORKING_FIRST, NET_NETWORKING_LAST ) |
#define IS_NET_LL_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_LL_FIRST, NET_LL_LAST ) |
#define IS_NET_ETHERNET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_ETHERNET_FIRST, NET_SOCKET_LAST ) |
#define IS_NET_IL_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_IL_FIRST, NET_IL_LAST ) |
#define IS_NET_IP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_IP_FIRST, NET_IP_LAST ) |
#define IS_NET_ARP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_ARP_FIRST, NET_ARP_LAST ) |
#define IS_NET_RARP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_RARP_FIRST, NET_RARP_LAST ) |
#define IS_NET_UDP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_UDP_FIRST, NET_UDP_LAST ) |
#define IS_NET_TCP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_TCP_FIRST, NET_TCP_LAST ) |
#define IS_NET_SOCKET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_SOCKET_FIRST, NET_SOCKET_LAST ) |
typedef enum { |
NET_IP_ECHO = NET_IP_FIRST |
NET_NETIF_PROBE = NET_NETIF_FIRST, |
NET_NETIF_PROBE_AUTO, |
NET_NETIF_REGISTER, |
NET_NETIF_SEND, |
NET_NETIF_START, |
NET_NETIF_STATS, |
NET_NETIF_STOP, |
NET_NETWORKING_DEVICE = NET_NETWORKING_FIRST, |
NET_NETWORKING_GET_CONFIGURATION, |
NET_NETWORKING_GET_DEVICE_CONFIGURATION, |
NET_NETWORKING_STARTUP, |
NET_LL_DEVICE = NET_LL_FIRST, |
NET_LL_DEVICE_STATUS_CHANGED, |
NET_LL_MTU_CHANGED, |
NET_LL_RECEIVED, |
NET_LL_REGISTER, |
NET_IL_DEVICE = NET_IL_FIRST, |
NET_IL_DEVICE_STATUS_CHANGED, |
NET_IP_CONFIGURATION_DHCP = NET_IP_FIRST, |
NET_IP_CONFIGURATION_STATIC, |
NET_IP_ECHO, |
NET_IP_TCP_REGISTER |
} net_message; |
/** @} |
/branches/network/uspace/srv/net/configuration.h |
---|
0,0 → 1,49 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __NET_CONFIGURATION_H__ |
#define __NET_CONFIGURATION_H__ |
#define NET_SELF_TEST 0 |
#define NET_SELF_TEST_MEASURED_STRINGS 1 |
#define NET_SELF_TEST_CHAR_MAP 0 |
#define NET_SELF_TEST_INT_MAP 0 |
#define NET_SELF_TEST_GENERIC_FIELD 0 |
#define NET_SELF_TEST_GENERIC_CHAR_MAP 0 |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/packet.h |
---|
0,0 → 1,39 |
/* |
* Copyright (c) 2008 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 |
*/ |
typedef struct packet * packet_t; |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/modules.h |
---|
33,15 → 33,9 |
/** @file |
*/ |
#include <errno.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#define ERROR_NAME error_check_return_value |
#define ERROR_DECLARE int ERROR_NAME |
#define ERROR_OCCURED( value ) (( ERROR_NAME = ( value )) != EOK ) |
#define ERROR_PROPAGATE( value ) if( ERROR_OCCURED( value )) return ERROR_NAME |
#define REGISTER_ME( me, phonehash ) ipc_connect_to_me( PHONE_NS, ( me ), 0, 0, ( phonehash )) |
int connect_to_service( services_t need ); |
/branches/network/uspace/srv/net/measured_strings.c |
---|
0,0 → 1,241 |
/* |
* Copyright (c) 2008 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 <errno.h> |
#include <malloc.h> |
#include <string.h> |
#include <unistd.h> |
#include <ipc/ipc.h> |
#include "err.h" |
#include "measured_strings.h" |
#include "modules.h" |
size_t * prepare_lengths( measured_string_ref strings, size_t count ); |
measured_string_ref measured_string_create_bulk( const char * string, size_t length ){ |
measured_string_ref new; |
if( length == 0 ){ |
while( string[ length ] ) ++ length; |
} |
new = ( measured_string_ref ) malloc( sizeof( measured_string_t ) + ( sizeof( char ) * ( length + 1 ))); |
if( ! new ) return NULL; |
new->length = length; |
new->value = (( char * ) new ) + sizeof( measured_string_t ); |
memcpy( new->value, string, new->length + 1 ); |
return new; |
} |
int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count ){ |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
size_t length; |
char * next; |
ipc_callid_t callid; |
if(( ! strings ) || ( !( * data )) || ( count <= 0 )){ |
return EINVAL; |
} |
lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
if( ! lengths ) return ENOMEM; |
if( ERROR_OCCURED( ipc_data_write_receive( & callid, & length ))){ |
free( lengths ); |
return ERROR_CODE; |
} |
if( length < sizeof( size_t ) * ( count + 1 )){ |
free( lengths ); |
return EINVAL; |
} |
if( ERROR_OCCURED( ipc_data_write_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){ |
free( lengths ); |
return ERROR_CODE; |
} |
* data = malloc( lengths[ count ] ); |
if( !( * data )) return ENOMEM; |
* strings = ( measured_string_ref ) malloc( sizeof( measured_string_t ) * count ); |
if( !( * strings )){ |
free( lengths ); |
free( * data ); |
return ENOMEM; |
} |
next = * data; |
for( index = 0; index < count; ++ index ){ |
( * strings)[ index ].length = lengths[ index ]; |
if( lengths[ index ] > 0 ){ |
ERROR_PROPAGATE( ipc_data_write_receive( & callid, & length )); |
if( length < lengths[ index ] + 1 ){ |
free( * data ); |
free( * strings ); |
free( lengths ); |
return EINVAL; |
} |
ERROR_PROPAGATE( ipc_data_write_finalize( callid, next, lengths[ index ] )); |
next += lengths[ index ]; |
* next = '\0'; |
++ next; |
}else{ |
( * strings )[ index ].value = NULL; |
} |
} |
free( lengths ); |
return EOK; |
} |
int measured_strings_reply( measured_string_ref strings, size_t count ){ |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
size_t length; |
ipc_callid_t callid; |
if(( ! strings ) || ( count <= 0 )){ |
return EINVAL; |
} |
lengths = prepare_lengths( strings, count ); |
if( ! lengths ) return ENOMEM; |
if( ERROR_OCCURED( ipc_data_read_receive( & callid, & length ))){ |
free( lengths ); |
return ERROR_CODE; |
} |
if( length < strings[ index ].length + 1 ){ |
free( lengths ); |
return EINVAL; |
} |
if( ERROR_OCCURED( ipc_data_read_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){ |
free( lengths ); |
return ERROR_CODE; |
} |
free( lengths ); |
for( index = 0; index < count; ++ index ){ |
if( strings[ index ].length > 0 ){ |
ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length )); |
if( length < strings[ index ].length + 1 ){ |
return EINVAL; |
} |
ERROR_PROPAGATE( ipc_data_read_finalize( callid, strings[ index ].value, strings[ index ].length )); |
} |
} |
return EOK; |
} |
int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count ){ |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
char * next; |
if(( phone <= 0 ) || ( ! strings ) || ( !( * data )) || ( count <= 0 )){ |
return EINVAL; |
} |
lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
if( ! lengths ) return ENOMEM; |
if( ERROR_OCCURED( ipc_data_read_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){ |
free( lengths ); |
return ERROR_CODE; |
} |
* data = malloc( lengths[ count ] ); |
if( !( * data )) return ENOMEM; |
* strings = ( measured_string_ref ) malloc( sizeof( measured_string_t ) * count ); |
if( !( * strings )){ |
free( lengths ); |
free( * data ); |
return ENOMEM; |
} |
next = * data; |
for( index = 0; index < count; ++ index ){ |
( * strings )[ index ].length = lengths[ index ]; |
if( lengths[ index ] > 0 ){ |
( * strings )[ index ].value = next; |
ERROR_PROPAGATE( ipc_data_read_start( phone, next, lengths[ index ] )); |
next += lengths[ index ]; |
* next = '\0'; |
++ next; |
}else{ |
( * strings )[ index ].value = NULL; |
} |
} |
free( lengths ); |
return EOK; |
} |
int measured_strings_send( int phone, measured_string_ref strings, size_t count ){ |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
if(( phone <= 0 ) || ( ! strings ) || ( count <= 0 )){ |
return EINVAL; |
} |
lengths = prepare_lengths( strings, count ); |
if( ! lengths ) return ENOMEM; |
if( ERROR_OCCURED( ipc_data_write_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){ |
free( lengths ); |
return ERROR_CODE; |
} |
free( lengths ); |
for( index = 0; index < count; ++ index ){ |
if( strings[ index ].length > 0 ){ |
ERROR_PROPAGATE( ipc_data_write_start( phone, strings[ index ].value, strings[ index ].length + 1 )); |
} |
} |
return EOK; |
} |
size_t * prepare_lengths( measured_string_ref strings, size_t count ){ |
size_t * lengths; |
int index; |
size_t length; |
lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
if( ! lengths ) return NULL; |
length = 0; |
for( index = 0; index < count; ++ index ){ |
lengths[ index ] = strings[ index ].length; |
length += lengths[ index ] + 1; |
} |
lengths[ count ] = length; |
return lengths; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/char_map.h |
---|
0,0 → 1,64 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __CHAR_MAP_H__ |
#define __CHAR_MAP_H__ |
#define CHAR_MAP_NULL ( -1 ) |
typedef struct char_map char_map_t; |
typedef char_map_t * char_map_ref; |
struct char_map{ |
char c; |
int value; |
int size; |
int next; |
char_map_ref * items; |
int magic; |
}; |
int char_map_add( char_map_ref map, const char * identifier, const int value ); |
void char_map_destroy( char_map_ref map ); |
int char_map_exclude( char_map_ref map, const char * identifier ); |
int char_map_find( char_map_ref map, const char * identifier ); |
int char_map_get_value( char_map_ref map ); |
int char_map_initialize( char_map_ref map ); |
int char_map_update( char_map_ref map, const char * identifier, const int value ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/measured_strings.h |
---|
0,0 → 1,58 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __MEASURED_STRINGS_H__ |
#define __MEASURED_STRINGS_H__ |
typedef struct measured_string measured_string_t; |
typedef measured_string_t * measured_string_ref; |
struct measured_string{ |
size_t length; |
char * value; |
}; |
measured_string_ref measured_string_create_bulk( const char * string, size_t length ); |
int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count ); |
int measured_strings_reply( measured_string_ref strings, size_t count ); |
int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count ); |
int measured_strings_send( int phone, measured_string_ref strings, size_t count ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/generic_field.h |
---|
0,0 → 1,143 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __GENERIC_FIELD_H__ |
#define __GENERIC_FIELD_H__ |
#include <errno.h> |
#include <malloc.h> |
#include <string.h> |
#include <unistd.h> |
#define GENERIC_FIELD_MAGIC_VALUE 0x55667788 |
#define GENERIC_FIELD_DECLARE( name, type ) \ |
\ |
typedef struct name name##_t; \ |
typedef name##_t * name##_ref; \ |
\ |
struct name{ \ |
int size; \ |
int next; \ |
type ** items; \ |
int magic; \ |
}; \ |
\ |
int name##_add( name##_ref field, type * value ); \ |
int name##_count( name##_ref field ); \ |
void name##_destroy( name##_ref field ); \ |
void name##_exclude_index( name##_ref field, int index ); \ |
type ** name##_get_field( name##_ref field ); \ |
type * name##_get_index( name##_ref field, int index ); \ |
int name##_initialize( name##_ref field ); \ |
int name##_is_valid( name##_ref field ); |
#define GENERIC_FIELD_IMPLEMENT( name, type ) \ |
\ |
int name##_add( name##_ref field, type * value ){ \ |
if( name##_is_valid( field )){ \ |
if( field->next == ( field->size - 1 )){ \ |
type ** tmp; \ |
\ |
tmp = ( type ** ) malloc( sizeof( type * ) * 2 * field->size ); \ |
if( ! tmp ) return ENOMEM; \ |
field->size *= 2; \ |
memcpy( tmp, field->items, sizeof( type * ) * field->next ); \ |
free( field->items ); \ |
field->items = tmp; \ |
} \ |
field->items[ field->next ] = value; \ |
++ field->next; \ |
field->items[ field->next ] = NULL; \ |
return field->next - 1; \ |
} \ |
return EINVAL; \ |
} \ |
\ |
int name##_count( name##_ref field ){ \ |
return name##_is_valid( field ) ? field->next : -1; \ |
} \ |
\ |
void name##_destroy( name##_ref field ){ \ |
if( name##_is_valid( field )){ \ |
int index; \ |
\ |
field->magic = 0; \ |
for( index = 0; index < field->next; ++ index ){ \ |
free( field->items[ index ] ); \ |
} \ |
free( field->items ); \ |
} \ |
} \ |
\ |
void name##_exclude_index( name##_ref field, int index ){ \ |
if( name##_is_valid( field ) && ( index >= 0 ) && ( index < field->next ) && ( field->items[ index ] )){ \ |
free( field->items[ index ] ); \ |
field->items[ index ] = NULL; \ |
} \ |
} \ |
\ |
type * name##_get_index( name##_ref field, int index ){ \ |
if( name##_is_valid( field ) && ( index >= 0 ) && ( index < field->next ) && ( field->items[ index ] )){ \ |
return field->items[ index ]; \ |
} \ |
return NULL; \ |
} \ |
\ |
type ** name##_get_field( name##_ref field ){ \ |
return name##_is_valid( field ) ? field->items : NULL; \ |
} \ |
\ |
int name##_initialize( name##_ref field ){ \ |
if( ! field ) return EINVAL; \ |
field->size = 2; \ |
field->next = 0; \ |
field->items = ( type ** ) malloc( sizeof( type * ) * field->size ); \ |
if( ! field->items ) return ENOMEM; \ |
field->items[ field->next ] = NULL; \ |
field->magic = INT_MAP_MAGIC_VALUE; \ |
return EOK; \ |
} \ |
\ |
int name##_is_valid( name##_ref field ){ \ |
return field && ( field->magic == INT_MAP_MAGIC_VALUE ); \ |
} |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/netif.c |
---|
0,0 → 1,153 |
/* |
* Copyright (c) 2008 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 <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/mman.h> |
#include "../err.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "netif.h" |
#include "netif_device_id_type.h" |
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 ); |
DEVICE_MAP_IMPLEMENT( netif_device_map, netif_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 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 ); |
if( ! * device ) return ENOENT; |
if(( ** device ).status == 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; |
stats->tx_packets = 0; |
stats->rx_bytes = 0; |
stats->tx_bytes = 0; |
stats->rx_errors = 0; |
stats->tx_errors = 0; |
stats->rx_dropped = 0; |
stats->tx_dropped = 0; |
stats->multicast = 0; |
stats->collisions = 0; |
stats->rx_length_errors = 0; |
stats->rx_over_errors = 0; |
stats->rx_crc_errors = 0; |
stats->rx_frame_errors = 0; |
stats->rx_fifo_errors = 0; |
stats->rx_missed_errors = 0; |
stats->tx_aborted_errors = 0; |
stats->tx_carrier_errors = 0; |
stats->tx_fifo_errors = 0; |
stats->tx_heartbeat_errors = 0; |
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 ){ |
ERROR_DECLARE; |
size_t length; |
netif_device_ref device; |
// printf( "\nNETIF message %d", method ); |
switch( method ){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NETIF_PROBE_AUTO: |
return netif_probe_auto_message( arg1, arg2, arg3, result1, result2, result3 ); |
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 )); |
// TODO back phone |
device->ll_registered = callid; |
return EOK; |
case NET_NETIF_SEND: |
return netif_send_message( arg1, arg2, arg3, result1, result2, result3 ); |
case NET_NETIF_START: |
return netif_start_message( arg1, arg2, arg3, result1, result2, result3 ); |
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 )); |
case NET_NETIF_STOP: |
return netif_stop_message( arg1, arg2, arg3, result1, result2, result3 ); |
} |
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 ]; |
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*/ NULL, NULL, client_connection, netif_initialize ); |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/netif_device_id_type.h |
---|
0,0 → 1,51 |
/* |
* Copyright (c) 2008 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 "../int_map.h" |
#ifndef __NET_NETIF_DEVICE_ID_TYPE_H__ |
#define __NET_NETIF_DEVICE_ID_TYPE_H__ |
#define DEVICE_MAP_DECLARE INT_MAP_DECLARE |
#define DEVICE_MAP_IMPLEMENT INT_MAP_IMPLEMENT |
typedef int netif_device_id_t; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/lo.c |
---|
0,0 → 1,167 |
/* |
* Copyright (c) 2008 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 <errno.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/mman.h> |
#include "../err.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "netif.h" |
#define DEFAULT_MTU 1500 |
#define NAME "lo - loopback interface" |
netif_globals_t netif_globals; |
void change_status( netif_device_ref device, netif_status_t status ); |
int change_status_message( netif_device_id_t device_id, netif_status_t status ); |
int netif_create( netif_device_id_t device_id, netif_device_ref * device ); |
int netif_call( ipc_callid_t callid ); |
int netif_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 ); |
void change_status( netif_device_ref device, netif_status_t status ){ |
device->status = status; |
ll_message( device, NET_LL_DEVICE_STATUS_CHANGED, device->status, NULL, NULL, NULL, NULL ); |
} |
int change_status_message( netif_device_id_t device_id, netif_status_t status ){ |
ERROR_DECLARE; |
netif_device_ref device; |
ERROR_PROPAGATE( netif_device_find( device_id, & device )); |
change_status( device, status ); |
return EOK; |
} |
int netif_create( netif_device_id_t device_id, netif_device_ref * device ){ |
ERROR_DECLARE; |
if( netif_device_map_count( & netif_globals.netif_device_map ) > 0 ){ |
return EXDEV; |
}else{ |
* device = ( netif_device_ref ) malloc( sizeof( netif_device_t )); |
if( !( * device )) return ENOMEM; |
// ( ** device ).device_id = netif_device_id_generate( 1 ); |
( ** device ).device_id = device_id; |
( ** device ).ll_registered = NULL; |
netif_device_stats_null( &(( ** device ).stats )); |
( ** device ).status = 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 ))){ |
free( * device ); |
* device = NULL; |
return ERROR_CODE; |
} |
} |
return EOK; |
} |
int netif_call( ipc_callid_t callid ){ |
return EOK; |
} |
int netif_initialize( void ){ |
int phonehash; |
return REGISTER_ME( SERVICE_LO, & phonehash ); |
} |
void netif_print_name( void ){ |
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 ){ |
ERROR_DECLARE; |
netif_device_ref device; |
ERROR_PROPAGATE( netif_create( arg1, & device )); |
networking_message( NET_NETWORKING_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
return EOK; |
} |
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
ERROR_DECLARE; |
netif_device_ref device; |
ERROR_PROPAGATE( netif_create( arg1, & device )); |
return EOK; |
} |
int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
ERROR_DECLARE; |
netif_device_ref device; |
ERROR_PROPAGATE( netif_device_find( arg1, & device )); |
if( device->status == 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 ); |
return EOK; |
}else{ |
return EPERM; |
} |
} |
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
return change_status_message( arg1, 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_status_message( arg1, NETIF_STOPPED ); |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/netif.h |
---|
0,0 → 1,118 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __NET_NETIF_H__ |
#define __NET_NETIF_H__ |
#include "netif_device_id_type.h" |
#define networking_message( ... ) \ |
if( netif_globals.networking_phone ) ipc_call_sync_3_3( netif_globals.networking_phone, __VA_ARGS__ ) |
#define ll_message( device, message, arg2, arg3, result1, result2, result3 ) \ |
if(( device )->ll_registered ) async_msg_3(( device )->ll_registered, ( message ), ( device )->device_id, arg2, arg3 ) |
typedef enum netif_status{ |
NETIF_NULL = 0, |
NETIF_STOPPED, |
NETIF_ACTIVE, |
NETIF_CARRIER_LOST |
} netif_status_t; |
typedef struct netif_device_stats netif_device_stats_t; |
typedef netif_device_stats_t * netif_device_stats_ref; |
typedef struct netif_device netif_device_t; |
typedef netif_device_t * netif_device_ref; |
typedef struct netif_globals netif_globals_t; |
DEVICE_MAP_DECLARE( netif_device_map, netif_device_t ); |
// based on linux_kernel/include/linux/netdevice.h |
struct netif_device_stats{ |
unsigned long rx_packets; /* total packets received */ |
unsigned long tx_packets; /* total packets transmitted */ |
unsigned long rx_bytes; /* total bytes received */ |
unsigned long tx_bytes; /* total bytes transmitted */ |
unsigned long rx_errors; /* bad packets received */ |
unsigned long tx_errors; /* packet transmit problems */ |
unsigned long rx_dropped; /* no space in linux buffers */ |
unsigned long tx_dropped; /* no space available in linux */ |
unsigned long multicast; /* multicast packets received */ |
unsigned long collisions; |
/* detailed rx_errors: */ |
unsigned long rx_length_errors; |
unsigned long rx_over_errors; /* receiver ring buff overflow */ |
unsigned long rx_crc_errors; /* recved pkt with crc error */ |
unsigned long rx_frame_errors; /* recv'd frame alignment error */ |
unsigned long rx_fifo_errors; /* recv'r fifo overrun */ |
unsigned long rx_missed_errors; /* receiver missed packet */ |
/* detailed tx_errors */ |
unsigned long tx_aborted_errors; |
unsigned long tx_carrier_errors; |
unsigned long tx_fifo_errors; |
unsigned long tx_heartbeat_errors; |
unsigned long tx_window_errors; |
/* for cslip etc */ |
unsigned long rx_compressed; |
unsigned long tx_compressed; |
}; |
struct netif_device{ |
netif_device_id_t device_id; |
ipc_callid_t ll_registered; |
netif_device_stats_t stats; |
netif_status_t status; |
int flags; |
int mtu; |
}; |
struct netif_globals{ |
int networking_phone; |
netif_device_map_t netif_device_map; |
}; |
int netif_device_find( netif_device_id_t device_id, netif_device_ref * device ); |
void netif_device_stats_null( netif_device_stats_ref stats ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/Makefile |
---|
0,0 → 1,82 |
# |
# Copyright (c) 2005 Martin Decky |
# 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. |
# |
NETIF = netif |
## Setup toolchain |
# |
LIBC_PREFIX = ../../../lib/libc |
SOFTINT_PREFIX = ../../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
LIBS = $(LIBC_PREFIX)/libc.a |
## Sources |
# |
OUTPUT = lo #dp8390_isa |
SOURCES = \ |
$(NETIF).c \ |
../module.c \ |
../modules.c |
DEFS += -D NETWORKING_$(NETWORKING) -D $(NETIF)_call=module_call -D $(NETIF)_message=module_message -D $(NETIF)_start_module=module_start -D $(NETIF)_print_name=module_print_name |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
OBJECTS += $(addsuffix .o,$(basename $(OUTPUT))) |
DISASMS := $(addsuffix .disasm,$(basename $(OUTPUT))) |
.PHONY: all clean depend disasm |
all: $(OUTPUT) $(DISAMS) |
-include Makefile.depend |
clean: |
-rm -f $(OUTPUT) $(addsuffix .map,$(basename $(SOURCES))) $(DISASMS) Makefile.depend |
depend: |
$(CC) $(DEFS) $(CFLAGS) -M $(addsuffix .c,$(basename $(OUTPUT))) $(SOURCES) > Makefile.depend |
$(OUTPUT): $(OBJECTS) $(LIBS) |
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $@.map |
disasm: $(DISASMS) |
%.disasm: $@ |
$(OBJDUMP) -d $< >$@ |
%.o: %.S |
$(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@ |
%.o: %.s |
$(AS) $(AFLAGS) $< -o $@ |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/module.c |
---|
0,0 → 1,92 |
/* |
* Copyright (c) 2008 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 <stdio.h> |
#include <task.h> |
#include <ipc/ipc.h> |
#include "err.h" |
#include "modules.h" |
extern int module_call( ipc_callid_t callid ); |
extern int module_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 ); |
extern void module_print_name( void ); |
extern int module_start( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )); |
void client_connection( ipc_callid_t iid, ipc_call_t * icall ); |
int main( int argc, char * argv[] ); |
/** Default thread for new connections. |
*/ |
void client_connection( ipc_callid_t iid, ipc_call_t * icall ){ |
ipc_callid_t callid; |
ipc_call_t call; |
ipcarg_t arg1, arg2, arg3; |
int res; |
/* Accept the connection */ |
ipc_answer_0( iid, EOK ); |
while( true ){ |
callid = async_get_call( & call ); |
arg1 = 0; |
arg2 = 0; |
arg3 = 0; |
res = module_call( callid ); |
if( res == EOK ){ |
res = module_message( callid, IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 ); |
} |
ipc_answer_2( callid, res, arg1, arg2 ); |
} |
} |
/** Starts the module. |
* Parameters are ignored. |
*/ |
int main( int argc, char * argv[] ){ |
ERROR_DECLARE; |
printf("\nTask %d - ", task_get_id()); |
module_print_name(); |
if( ERROR_OCCURED( module_start( client_connection ))){ |
printf( " - ERROR %i", ERROR_CODE ); |
return ERROR_CODE; |
} |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/ip.c |
---|
32,6 → 32,7 |
/** @file |
*/ |
#include <async.h> |
#include <errno.h> |
#include <stdio.h> |
39,28 → 40,37 |
#include <ipc/services.h> |
//#include <sys/mman.h> |
#include "../err.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "../netif/netif_device_id_type.h" |
#include "ip.h" |
struct { |
ipc_callid_t tcp_accepted; |
} ip_globals; |
ip_globals_t ip_globals; |
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
/** Initializes the module. |
*/ |
int ip_initialize( void ){ |
ip_netifs_initialize( & ip_globals.netifs ); |
return EOK; |
} |
int ip_call( ipc_callid_t callid ){ |
ip_globals.tcp_accepted = callid; |
return EOK; |
} |
int ip_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 ){ |
int ip_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 ){ |
ERROR_DECLARE; |
ip_netif_ref ip_netif; |
// printf( "\nIP message %d", method ); |
switch( method ){ |
// case IPC_M_CONNECT_ME_TO: |
// case IPC_M_CONNECT_TO_ME: |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_IP_ECHO: |
68,7 → 78,24 |
if( result2 ) * result2 = arg2; |
if( result3 ) * result3 = arg3; |
return EOK; |
case NET_IL_DEVICE: |
ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t )); |
if( ! ip_netif ) return ENOMEM; |
ip_netif->device_id = arg1; |
ip_netif->phone = connect_to_service( arg2 ); |
if( ERROR_OCCURED( ipc_call_sync_1_0( ip_netif->phone, NET_LL_REGISTER, arg1 ))){ |
free( ip_netif ); |
return ERROR_CODE; |
} |
if( ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){ |
free( ip_netif ); |
return ERROR_CODE; |
} |
return EOK; |
case NET_IP_TCP_REGISTER: |
ip_globals.tcp_phone = ipc_connect_to_me( callid, 0, 0, 0, 0 ); |
return EOK; |
} |
return ENOTSUP; |
} |
/branches/network/uspace/srv/net/ip/Makefile |
---|
44,8 → 44,11 |
SOURCES = \ |
$(NAME)_module.c \ |
$(NAME).c \ |
../module.c \ |
../modules.c |
DEFS += -D NETWORKING_$(NETWORKING) -D $(NAME)_call=module_call -D $(NAME)_message=module_message -D $(NAME)_start_module=module_start -D $(NAME)_print_name=module_print_name |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
.PHONY: all clean depend disasm |
75,4 → 78,4 |
$(AS) $(AFLAGS) $< -o $@ |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -D NETWORKING_$(NETWORKING) -c $< -o $@ |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
/branches/network/uspace/srv/net/ip/ip.h |
---|
39,9 → 39,30 |
#include <ipc/ipc.h> |
#include "../netif/netif_device_id_type.h" |
typedef struct ip_netif ip_netif_t; |
typedef ip_netif_t * ip_netif_ref; |
typedef struct ip_globals ip_globals_t; |
DEVICE_MAP_DECLARE( ip_netifs, ip_netif_t ) |
struct ip_netif{ |
netif_device_id_t device_id; |
int phone; |
// TODO configuration |
}; |
struct ip_globals{ |
int networking_phone; |
int tcp_phone; |
ip_netifs_t netifs; |
}; |
int ip_initialize( void ); |
int ip_call( ipc_callid_t callid ); |
int ip_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 ); |
int ip_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 ); |
#endif |
/branches/network/uspace/srv/net/ip/ip_module.c |
---|
32,52 → 32,36 |
/** @file |
*/ |
#include <async.h> |
#include <errno.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
//#include <sys/mman.h> |
#include "../modules.h" |
#include "ip.h" |
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ); |
int main( int argc, char * argv[] ); |
#define NAME "IP protocol" |
/** Default thread for new connections. |
*/ |
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ){ |
ipc_callid_t callid; |
ipc_call_t call; |
ipcarg_t arg1, arg2, arg3; |
int res; |
void ip_print_name( void ); |
int ip_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )); |
/* Accept the connection */ |
ipc_answer_0( iid, EOK ); |
extern ip_globals_t ip_globals; |
while( true ){ |
callid = async_get_call( & call ); |
arg1 = 0; |
arg2 = 0; |
arg3 = 0; |
res = ip_call( callid ); |
if( res == EOK ){ |
res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 ); |
void ip_print_name( void ){ |
printf( NAME ); |
} |
ipc_answer_2( callid, res, arg1, arg2 ); |
} |
} |
/** Starts the module. |
* Parameters are ignored. |
*/ |
int main( int argc, char * argv[] ){ |
int ip_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){ |
services_t need[ 2 ]; |
int * need_phone[ 2 ]; |
printf("ip : HelenOS IP network protocol\n"); |
return start_service( SERVICE_IP, NULL, NULL, client_connection, ip_initialize ); |
need[ 0 ] = SERVICE_NETWORKING; |
need[ 1 ] = NULL; |
need_phone[ 0 ] = & ip_globals.networking_phone; |
need_phone[ 1 ] = NULL; |
return start_service( SERVICE_IP, need, need_phone, client_connection, ip_initialize ); |
} |
/** @} |
/branches/network/uspace/srv/net/networking_startup/networking_startup.c |
---|
0,0 → 1,92 |
/* |
* Copyright (c) 2008 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 <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" |
#define NAME "Networking startup" |
int main( int argc, char * argv[] ); |
task_id_t spawn( const char * fname ); |
int main( int argc, char * argv[] ){ |
ERROR_DECLARE; |
ipcarg_t arg1; |
int networking_phone; |
printf( "Task %d - " NAME, task_get_id()); |
// run self tests |
ERROR_PROPAGATE( self_test()); |
// start networking service |
if( ! spawn( "/sbin/networking" )){ |
printf( "\n" NAME "Could not spawn networking" ); |
return EINVAL; |
} |
// start networking |
networking_phone = connect_to_service( SERVICE_NETWORKING ); |
if( ERROR_OCCURED( ipc_call_sync_0_0( networking_phone, NET_NETWORKING_STARTUP ))){ |
printf( "\n" NAME " - ERROR %d\n", ERROR_CODE ); |
return ERROR_CODE; |
} |
printf( "\n" NAME " - OK\n" ); |
return EOK; |
} |
task_id_t spawn( const char * fname ){ |
const 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 |
/branches/network/uspace/srv/net/networking_startup/Makefile |
---|
0,0 → 1,80 |
# |
# Copyright (c) 2005 Martin Decky |
# 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. |
# |
## Setup toolchain |
# |
LIBC_PREFIX = ../../../lib/libc |
SOFTINT_PREFIX = ../../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
include ../../../../Makefile.config |
LIBS = $(LIBC_PREFIX)/libc.a |
## Sources |
# |
OUTPUT = networking_startup |
SOURCES = \ |
networking_startup.c \ |
../modules.c \ |
../measured_strings.c \ |
../self_test.c |
DEFS += -D NETWORKING_$(NETWORKING) |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
.PHONY: all clean depend disasm |
all: $(OUTPUT) $(OUTPUT).disasm |
-include Makefile.depend |
clean: |
-rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend |
depend: |
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend |
$(OUTPUT): $(OBJECTS) $(LIBS) |
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map |
disasm: $(OUTPUT).disasm |
$(OUTPUT).disasm: $(OUTPUT) |
$(OBJDUMP) -d $< >$@ |
%.o: %.S |
$(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@ |
%.o: %.s |
$(AS) $(AFLAGS) $< -o $@ |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/self_test.c |
---|
0,0 → 1,288 |
/* |
* Copyright (c) 2008 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 "configuration.h" |
#if NET_SELF_TEST |
#include <errno.h> |
#include <malloc.h> |
#include <stdio.h> |
#include "int_map.h" |
#include "char_map.h" |
#include "generic_char_map.h" |
#include "measured_strings.h" |
#include "self_test.h" |
#define TEST( name, function_call, result ); { \ |
printf( "\n\t%s", ( name )); \ |
if(( function_call ) != ( result )){ \ |
printf( "\tERROR" ); \ |
}else{ \ |
printf( "\tOK" ); \ |
} \ |
} |
#if NET_SELF_TEST_INT_MAP |
INT_MAP_DECLARE( int_map, int ); |
INT_MAP_IMPLEMENT( int_map, int ); |
#endif |
#if NET_SELF_TEST_GENERIC_FIELD |
GENERIC_FIELD_DECLARE( int_field, int ) |
GENERIC_FIELD_IMPLEMENT( int_field, int ) |
#endif |
#if NET_SELF_TEST_GENERIC_CHAR_MAP |
GENERIC_CHAR_MAP_DECLARE( int_char_map, int ) |
GENERIC_CHAR_MAP_IMPLEMENT( int_char_map, int ) |
#endif |
int self_test( void ){ |
int * x, * y, * z, * u, * v, * w; |
#if NET_SELF_TEST_MEASURED_STRINGS |
measured_string_ref string; |
printf( "\nMeasured strings test" ); |
string = measured_string_create_bulk( "I am a measured string!", -1 ); |
printf( "\n%x, %s at %x of %d", string, string->value, string->value, string->length ); |
printf( "\nOK" ); |
#endif |
#if NET_SELF_TEST_CHAR_MAP |
char_map_t cm; |
printf( "\nChar map test" ); |
TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 3 ), EINVAL ); |
TEST( "initialize", char_map_initialize( & cm ), EOK ); |
TEST( "get_value", char_map_get_value( & cm ), CHAR_MAP_NULL ); |
TEST( "exclude bla null", char_map_exclude( & cm, "bla" ), CHAR_MAP_NULL ); |
TEST( "find bla null", char_map_find( & cm, "bla" ), CHAR_MAP_NULL ); |
TEST( "add bla 1 eok", char_map_add( & cm, "bla", 1 ), EOK ); |
TEST( "find bla 1", char_map_find( & cm, "bla" ), 1 ); |
TEST( "add bla 10 eexists", char_map_add( & cm, "bla", 10 ), EEXISTS ); |
TEST( "update bla 2 eok", char_map_update( & cm, "bla", 2 ), EOK ); |
TEST( "find bla 2", char_map_find( & cm, "bla" ), 2 ); |
TEST( "update ucho 2 eok", char_map_update( & cm, "ucho", 2 ), EOK ); |
TEST( "exclude bla 2", char_map_exclude( & cm, "bla" ), 2 ); |
TEST( "exclude bla null", char_map_exclude( & cm, "bla" ), CHAR_MAP_NULL ); |
TEST( "find ucho 2", char_map_find( & cm, "ucho" ), 2 ); |
TEST( "update ucho 3 eok", char_map_update( & cm, "ucho", 3 ), EOK ); |
TEST( "find ucho 3", char_map_find( & cm, "ucho" ), 3 ); |
TEST( "add blabla 5 eok", char_map_add( & cm, "blabla", 5 ), EOK ); |
TEST( "find blabla 5", char_map_find( & cm, "blabla" ), 5 ); |
TEST( "add bla 6 eok", char_map_add( & cm, "bla", 6 ), EOK ); |
TEST( "find bla 6", char_map_find( & cm, "bla" ), 6 ); |
TEST( "exclude bla 6", char_map_exclude( & cm, "bla" ), 6 ); |
TEST( "find bla null", char_map_find( & cm, "bla" ), CHAR_MAP_NULL ); |
TEST( "find blabla 5", char_map_find( & cm, "blabla" ), 5 ); |
TEST( "add auto 7 eok", char_map_add( & cm, "auto", 7 ), EOK ); |
TEST( "find auto 7", char_map_find( & cm, "auto" ), 7 ); |
TEST( "add kara 8 eok", char_map_add( & cm, "kara", 8 ), EOK ); |
TEST( "find kara 8", char_map_find( & cm, "kara" ), 8 ); |
TEST( "add nic 9 eok", char_map_add( & cm, "nic", 9 ), EOK ); |
TEST( "find nic 9", char_map_find( & cm, "nic" ), 9 ); |
TEST( "find blabla 5", char_map_find( & cm, "blabla" ), 5 ); |
printf( "\n\tdestroy" ); |
char_map_destroy( & cm ); |
TEST( "update ucho 3 einval", char_map_update( & cm, "ucho", 3 ), EINVAL ); |
printf( "\nOK" ); |
#endif |
#if NET_SELF_TEST_INT_MAP |
int_map_t im; |
x = ( int * ) malloc( sizeof( int )); |
y = ( int * ) malloc( sizeof( int )); |
z = ( int * ) malloc( sizeof( int )); |
u = ( int * ) malloc( sizeof( int )); |
v = ( int * ) malloc( sizeof( int )); |
w = ( int * ) malloc( sizeof( int )); |
im.magic = 0; |
printf( "\nInt map test" ); |
TEST( "add 1 x einval", int_map_add( & im, 1, x ), EINVAL ); |
TEST( "count -1", int_map_count( & im ), -1 ); |
TEST( "initialize", int_map_initialize( & im ), EOK ); |
TEST( "count 0", int_map_count( & im ), 0 ); |
TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
TEST( "add 1 x 0", int_map_add( & im, 1, x ), 0 ); |
TEST( "find 1 x", int_map_find( & im, 1 ), x ); |
int_map_exclude( & im, 1 ); |
TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
TEST( "add 1 y 1", int_map_add( & im, 1, y ), 1 ); |
TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
TEST( "add 4 z 2", int_map_add( & im, 4, z ), 2 ); |
TEST( "get 2 z", int_map_get_index( & im, 2 ), z ); |
TEST( "find 4 z", int_map_find( & im, 4 ), z ); |
TEST( "find 1 y", int_map_find( & im, 1 ), y ); |
TEST( "count 3", int_map_count( & im ), 3 ); |
TEST( "add 2 u 3", int_map_add( & im, 2, u ), 3 ); |
TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
TEST( "add 3 v 4", int_map_add( & im, 3, v ), 4 ); |
TEST( "find 3 v", int_map_find( & im, 3 ), v ); |
TEST( "get 4 v", int_map_get_index( & im, 4 ), v ); |
TEST( "add 6 w 5", int_map_add( & im, 6, w ), 5 ); |
TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
TEST( "count 6", int_map_count( & im ), 6 ); |
int_map_exclude( & im, 1 ); |
TEST( "find 1 null", int_map_find( & im, 1 ), NULL ); |
TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
int_map_exclude( & im, 7 ); |
TEST( "find 2 u", int_map_find( & im, 2 ), u ); |
TEST( "find 6 w", int_map_find( & im, 6 ), w ); |
int_map_exclude_index( & im, 4 ); |
TEST( "get 4 null", int_map_get_index( & im, 4 ), NULL ); |
TEST( "find 3 null", int_map_find( & im, 3 ), NULL ); |
printf( "\n\tdestroy" ); |
int_map_destroy( & im ); |
TEST( "count -1", int_map_count( & im ), -1 ); |
printf( "\nOK" ); |
#endif |
#if NET_SELF_TEST_GENERIC_FIELD |
int_field_t gf; |
x = ( int * ) malloc( sizeof( int )); |
y = ( int * ) malloc( sizeof( int )); |
z = ( int * ) malloc( sizeof( int )); |
u = ( int * ) malloc( sizeof( int )); |
v = ( int * ) malloc( sizeof( int )); |
w = ( int * ) malloc( sizeof( int )); |
gf.magic = 0; |
printf( "\nGeneric field test" ); |
TEST( "add x einval", int_field_add( & gf, x ), EINVAL ); |
TEST( "count -1", int_field_count( & gf ), -1 ); |
TEST( "initialize", int_field_initialize( & gf ), EOK ); |
TEST( "count 0", int_field_count( & gf ), 0 ); |
TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
TEST( "add x 0", int_field_add( & gf, x ), 0 ); |
TEST( "get 0 x", int_field_get_index( & gf, 0 ), x ); |
int_field_exclude_index( & gf, 0 ); |
TEST( "get 0 null", int_field_get_index( & gf, 0 ), NULL ); |
TEST( "add y 1", int_field_add( & gf, y ), 1 ); |
TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
TEST( "add z 2", int_field_add( & gf, z ), 2 ); |
TEST( "get 2 z", int_field_get_index( & gf, 2 ), z ); |
TEST( "get 1 y", int_field_get_index( & gf, 1 ), y ); |
TEST( "count 3", int_field_count( & gf ), 3 ); |
TEST( "add u 3", int_field_add( & gf, u ), 3 ); |
TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
TEST( "add v 4", int_field_add( & gf, v ), 4 ); |
TEST( "get 4 v", int_field_get_index( & gf, 4 ), v ); |
TEST( "add w 5", int_field_add( & gf, w ), 5 ); |
TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
TEST( "count 6", int_field_count( & gf ), 6 ); |
int_field_exclude_index( & gf, 1 ); |
TEST( "get 1 null", int_field_get_index( & gf, 1 ), NULL ); |
TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
int_field_exclude_index( & gf, 7 ); |
TEST( "get 3 u", int_field_get_index( & gf, 3 ), u ); |
TEST( "get 5 w", int_field_get_index( & gf, 5 ), w ); |
int_field_exclude_index( & gf, 4 ); |
TEST( "get 4 null", int_field_get_index( & gf, 4 ), NULL ); |
printf( "\n\tdestroy" ); |
int_field_destroy( & gf ); |
TEST( "count -1", int_field_count( & gf ), -1 ); |
printf( "\nOK" ); |
#endif |
#if NET_SELF_TEST_GENERIC_CHAR_MAP |
int_char_map_t icm; |
x = ( int * ) malloc( sizeof( int )); |
y = ( int * ) malloc( sizeof( int )); |
z = ( int * ) malloc( sizeof( int )); |
u = ( int * ) malloc( sizeof( int )); |
v = ( int * ) malloc( sizeof( int )); |
w = ( int * ) malloc( sizeof( int )); |
icm.magic = 0; |
printf( "\nGeneric char map test" ); |
TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", z ), EINVAL ); |
TEST( "initialize", int_char_map_initialize( & icm ), EOK ); |
printf( "\n\texclude bla null" ); |
int_char_map_exclude( & icm, "bla" ); |
TEST( "find bla null", int_char_map_find( & icm, "bla" ), NULL ); |
TEST( "add bla x eok", int_char_map_add( & icm, "bla", x ), EOK ); |
TEST( "find bla x", int_char_map_find( & icm, "bla" ), x ); |
TEST( "add bla y eexists", int_char_map_add( & icm, "bla", y ), EEXISTS ); |
printf( "\n\texclude bla y" ); |
int_char_map_exclude( & icm, "bla" ); |
printf( "\n\texclude bla null" ); |
int_char_map_exclude( & icm, "bla" ); |
TEST( "add blabla v eok", int_char_map_add( & icm, "blabla", v ), EOK ); |
TEST( "find blabla v", int_char_map_find( & icm, "blabla" ), v ); |
TEST( "add bla w eok", int_char_map_add( & icm, "bla", w ), EOK ); |
TEST( "find bla w", int_char_map_find( & icm, "bla" ), w ); |
printf( "\n\texclude bla" ); |
int_char_map_exclude( & icm, "bla" ); |
TEST( "find bla null", int_char_map_find( & icm, "bla" ), NULL ); |
TEST( "find blabla v", int_char_map_find( & icm, "blabla" ), v ); |
TEST( "add auto u eok", int_char_map_add( & icm, "auto", u ), EOK ); |
TEST( "find auto u", int_char_map_find( & icm, "auto" ), u ); |
printf( "\n\tdestroy" ); |
int_char_map_destroy( & icm ); |
TEST( "add ucho z einval", int_char_map_add( & icm, "ucho", z ), EINVAL ); |
printf( "\nOK" ); |
#endif |
return EOK; |
} |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/Makefile |
---|
0,0 → 1,73 |
# |
# Copyright (c) 2005 Martin Decky |
# 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. |
# |
include ../../../Makefile.config |
DIRS = \ |
netif \ |
networking \ |
networking_startup |
DIRS_MODULAR = ip \ |
tcp \ |
# arp \ |
# rarp \ |
# icmp \ |
# udp \ |
# socket |
DIRS_ALL = $(DIRS) $(DIRS_MODULAR) |
ifndef ($(NETWORKING)) |
NETWORKING = modular |
endif |
ifeq ($(NETWORKING), modular) |
BUILDS := $(addsuffix .build,$(DIRS_ALL)) |
else |
BUILDS := $(addsuffix .build,$(DIRS)) |
endif |
CLEANS := $(addsuffix .clean,$(DIRS_ALL)) |
.PHONY: all build $(BUILDS) $(CLEANS) clean distclean |
all: $(BUILDS) |
build: $(BUILDS) |
clean: $(CLEANS) |
find $(DIRS_ALL) -name '*.o' -follow -exec rm \{\} \; |
distclean: clean |
$(CLEANS): |
-$(MAKE) -C $(basename $@) clean ARCH=$(ARCH) |
$(BUILDS): |
$(MAKE) -C $(basename $@) all ARCH=$(ARCH) COMPILER=$(COMPILER) NETWORKING=$(NETWORKING) |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/int_map.h |
---|
0,0 → 1,192 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __NET_INT_MAP_H__ |
#define __NET_INT_MAP_H__ |
#include <errno.h> |
#include <malloc.h> |
#include <string.h> |
#define INT_MAP_MAGIC_VALUE 0x11223344 |
#define INT_MAP_ITEM_MAGIC_VALUE 0x55667788 |
#define INT_MAP_DECLARE( name, type ) \ |
\ |
typedef struct name name##_t; \ |
typedef name##_t * name##_ref; \ |
typedef struct name##_item name##_item_t; \ |
typedef name##_item_t * name##_item_ref; \ |
\ |
struct name##_item{ \ |
int key; \ |
type * value; \ |
int magic; \ |
}; \ |
\ |
struct name{ \ |
int size; \ |
int next; \ |
name##_item_ref items; \ |
int magic; \ |
}; \ |
\ |
int name##_add( name##_ref map, int key, type * value ); \ |
int name##_count( name##_ref map ); \ |
void name##_destroy( name##_ref map ); \ |
void name##_exclude( name##_ref map, int key ); \ |
void name##_exclude_index( name##_ref map, int index ); \ |
type * name##_find( name##_ref map, int key ); \ |
type * name##_get_index( name##_ref map, int index ); \ |
int name##_initialize( name##_ref map ); \ |
int name##_is_valid( name##_ref map ); \ |
void name##_item_destroy( name##_item_ref item ); \ |
int name##_item_is_valid( name##_item_ref item ); |
#define INT_MAP_IMPLEMENT( name, type ) \ |
\ |
int name##_add( name##_ref map, int key, type * value ){ \ |
if( name##_is_valid( map )){ \ |
if( map->next == ( map->size - 1 )){ \ |
name##_item_ref tmp; \ |
\ |
tmp = ( name##_item_ref ) malloc( sizeof( name##_item_t ) * 2 * map->size ); \ |
if( ! tmp ) return ENOMEM; \ |
map->size *= 2; \ |
memcpy( tmp, map->items, sizeof( name##_item_t ) * map->next ); \ |
free( map->items ); \ |
map->items = tmp; \ |
} \ |
map->items[ map->next ].key = key; \ |
map->items[ map->next ].value = value; \ |
map->items[ map->next ].magic = INT_MAP_ITEM_MAGIC_VALUE; \ |
++ map->next; \ |
map->items[ map->next ].magic = 0; \ |
return map->next - 1; \ |
} \ |
return EINVAL; \ |
} \ |
\ |
int name##_count( name##_ref map ){ \ |
return name##_is_valid( map ) ? map->next : -1; \ |
} \ |
\ |
void name##_destroy( name##_ref map ){ \ |
if( name##_is_valid( map )){ \ |
int index; \ |
\ |
map->magic = 0; \ |
for( index = 0; index < map->next; ++ index ){ \ |
if( name##_item_is_valid( &( map->items[ index ] ))){ \ |
name##_item_destroy( &( map->items[ index ] )); \ |
} \ |
} \ |
free( map->items ); \ |
} \ |
} \ |
\ |
void name##_exclude( name##_ref map, int key ){ \ |
if( name##_is_valid( map )){ \ |
int index; \ |
\ |
for( index = 0; index < map->next; ++ index ){ \ |
if( name##_item_is_valid( &( map->items[ index ] )) && ( map->items[ index ].key == key )){ \ |
name##_item_destroy( &( map->items[ index ] )); \ |
} \ |
} \ |
} \ |
} \ |
\ |
void name##_exclude_index( name##_ref map, int index ){ \ |
if( name##_is_valid( map ) && ( index >= 0 ) && ( index < map->next ) && name##_item_is_valid( &( map->items[ index ] ))){ \ |
name##_item_destroy( &( map->items[ index ] )); \ |
} \ |
} \ |
\ |
type * name##_find( name##_ref map, int key ){ \ |
if( name##_is_valid( map )){ \ |
int index; \ |
\ |
for( index = 0; index < map->next; ++ index ){ \ |
if( name##_item_is_valid( &( map->items[ index ] )) && ( map->items[ index ].key == key )){ \ |
return map->items[ index ].value; \ |
} \ |
} \ |
} \ |
return NULL; \ |
} \ |
\ |
type * name##_get_index( name##_ref map, int index ){ \ |
if( name##_is_valid( map ) && ( index >= 0 ) && ( index < map->next ) && name##_item_is_valid( &( map->items[ index ] ))){ \ |
return map->items[ index ].value; \ |
} \ |
return NULL; \ |
} \ |
\ |
int name##_initialize( name##_ref map ){ \ |
if( ! map ) return EINVAL; \ |
map->size = 2; \ |
map->next = 0; \ |
map->items = ( name##_item_ref ) malloc( sizeof( name##_item_t ) * map->size ); \ |
if( ! map->items ) return ENOMEM; \ |
map->items[ map->next ].magic = 0; \ |
map->magic = INT_MAP_MAGIC_VALUE; \ |
return EOK; \ |
} \ |
\ |
int name##_is_valid( name##_ref map ){ \ |
return map && ( map->magic == INT_MAP_MAGIC_VALUE ); \ |
} \ |
\ |
void name##_item_destroy( name##_item_ref item ){ \ |
if( name##_item_is_valid( item )){ \ |
item->magic = 0; \ |
if( item->value ){ \ |
free( item->value ); \ |
item->value = NULL; \ |
} \ |
} \ |
} \ |
\ |
int name##_item_is_valid( name##_item_ref item ){ \ |
return item && ( item->magic == INT_MAP_ITEM_MAGIC_VALUE ); \ |
} |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/err.h |
---|
0,0 → 1,49 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __NET_ERR_H__ |
#define __NET_ERR_H__ |
#include <errno.h> |
#define ERROR_CODE error_check_return_value |
#define ERROR_DECLARE int ERROR_CODE |
#define ERROR_OCCURED( value ) (( ERROR_CODE = ( value )) != EOK ) |
#define ERROR_PROPAGATE( value ) if( ERROR_OCCURED( value )) return ERROR_CODE |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/self_test.h |
---|
0,0 → 1,56 |
/* |
* Copyright (c) 2008 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 |
*/ |
#ifndef __SELF_TEST_H__ |
#define __SELF_TEST_H__ |
#include "configuration.h" |
#if NET_SELF_TEST |
int self_test( void ); |
#else |
#include <errno.h> |
#define self_test() EOK |
#endif |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/Makefile |
---|
46,7 → 46,7 |
srv/fs/tmpfs \ |
srv/vfs \ |
srv/devmap \ |
srv/net/networking \ |
srv/net \ |
app/tetris \ |
app/tester \ |
app/klog \ |
69,17 → 69,6 |
CFLAGS += -DCONFIG_MIPS_FPU |
endif |
ifeq ($(NETWORKING), modular) |
DIRS += srv/net/ip \ |
srv/net/tcp |
# srv/net/arp \ |
# srv/net/rarp \ |
# srv/net/icmp \ |
# srv/net/udp \ |
# srv/net/socket \ |
# srv/net/drivers/ne2k_isa |
endif |
BUILDS := $(addsuffix .build,$(DIRS)) |
CLEANS := $(addsuffix .clean,$(DIRS)) |
/branches/network/boot/arch/ia32/Makefile.inc |
---|
50,8 → 50,10 |
$(USPACEDIR)/app/tester/tester \ |
$(USPACEDIR)/app/klog/klog \ |
$(USPACEDIR)/app/bdsh/bdsh \ |
$(USPACEDIR)/srv/net/networking/networking |
# $(USPACEDIR)/srv/net/drivers/ne2k_isa |
$(USPACEDIR)/srv/net/networking/networking \ |
$(USPACEDIR)/srv/net/networking_startup/networking_startup \ |
$(USPACEDIR)/srv/net/netif/lo |
# $(USPACEDIR)/srv/net/netif/dp8390_isa |
ifeq ($(NETWORKING), modular) |
RD_TASKS += $(USPACEDIR)/srv/net/ip/ip \ |
/branches/network/Makefile |
---|
118,7 → 118,7 |
ifneq ($(MACHINE),) |
$(MAKE) -C kernel ARCH=$(KARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG) MACHINE=$(MACHINE) |
else |
$(MAKE) -C kernel ARCH=$(KARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG) |
$(MAKE) -C kernel ARCH=$(KARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG) NETWORKING=$(NETWORKING) |
endif |
$(MAKE) -C uspace ARCH=$(UARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG) NETWORKING=$(NETWORKING) |
ifneq ($(IMAGE),) |