Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3665 → Rev 3666

/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,10 → 47,17
#endif
#endif
 
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 );
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( 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 );
}
ipc_answer_2( callid, EOK, arg1, arg2 );
}
void tcp_print_name( void ){
printf( NAME );
}
 
/** 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 $@