/branches/network/uspace/srv/net/arp/arp_oc.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/arp/arp_module.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/arp/Makefile |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/arp/arp_header.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/arp/arp.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/arp/arp.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/arp/arp_module.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/measured_strings.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/measured_strings.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/networking_startup/networking_startup.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/networking_startup/Makefile |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/packet.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/packet.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tcp/tcp.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tcp/tcp_module.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tcp/Makefile |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tcp/tcp_module.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tcp/tcp.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/int_map.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/char_map.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/generic_field.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/packet_queue.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/char_map.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/generic_char_map.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/ip.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/Makefile |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/ip.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/ip_module.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/ip_module.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/ip_messages.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/ip/ip_header.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/packet_queue.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tl/tcp/tcp_module.h |
---|
0,0 → 1,48 |
/* |
* 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_TCP_MODULE_H__ |
#define __NET_TCP_MODULE_H__ |
#include <ipc/ipc.h> |
int tcp_initialize( void ); |
int tcp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tl/tcp/tcp.c |
---|
0,0 → 1,86 |
/* |
* 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 "../../err.h" |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../structures/packet/packet.h" |
#include "../../il/ip/ip_messages.h" |
#include "tcp.h" |
#include "tcp_module.h" |
tcp_globals_t tcp_globals; |
/** Initializes the module. |
*/ |
int tcp_initialize( void ){ |
ERROR_DECLARE; |
ipcarg_t arg1, arg2; |
packet_t packet; |
printf( "\nTCP - testing to send to IP:\t" ); |
ERROR_PROPAGATE( ip_echo( tcp_globals.ip_phone, 12, 34, 0, 0, 0, & arg1, & arg2, NULL, NULL, NULL )); |
if(( arg1 != 12 ) || ( arg2 != 34 )) return EINVAL; |
printf( "OK\n" ); |
printf( "\nTCP - testing to send packet to IP:\t" ); |
packet = packet_create( 20, 30, 20 ); |
if( ! packet ) return ENOMEM; |
packet_copy_data( packet, "Hi, this is TCP", 16 ); |
ERROR_PROPAGATE( ip_send( tcp_globals.ip_phone, -1, packet )); |
printf( "\tOK\n" ); |
return EOK; |
} |
int tcp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
} |
return ENOTSUP; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tl/tcp/tcp.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 |
*/ |
#ifndef __NET_TCP_H__ |
#define __NET_TCP_H__ |
typedef struct tcp_globals tcp_globals_t; |
struct tcp_globals{ |
int ip_phone; |
int networking_phone; |
}; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tl/tcp/tcp_module.c |
---|
0,0 → 1,78 |
/* |
* 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 "../../err.h" |
#include "../../modules.h" |
#include "../../include/protocols.h" |
#include "tcp.h" |
#include "tcp_module.h" |
#define NAME "TCP protocol" |
void tcp_print_name( void ); |
int tcp_start_module( async_client_conn_t client_connection ); |
extern tcp_globals_t tcp_globals; |
void tcp_print_name( void ){ |
printf( NAME ); |
} |
int tcp_start_module( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
ipcarg_t phonehash; |
async_set_client_connection( client_connection ); |
tcp_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
tcp_globals.ip_phone = bind_service( SERVICE_IP, IPPROTO_TCP, 0, 0, client_connection ); |
ERROR_PROPAGATE( tcp_initialize()); |
ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash )); |
async_manager(); |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tl/tcp/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. |
# |
NAME = tcp |
## Setup toolchain |
# |
LIBC_PREFIX = ../../../../lib/libc |
SOFTINT_PREFIX = ../../../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
LIBS = $(LIBC_PREFIX)/libc.a |
## Sources |
# |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME)_module.c \ |
$(NAME).c \ |
../../module.c \ |
../../modules.c \ |
../../structures/packet/packet.c |
DEFS += -D TCP_BUNDLE=1 -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 |
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/tl/tcp |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/tl/udp |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/nil/ethernet |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/measured_strings.c |
---|
0,0 → 1,249 |
/* |
* 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 |
* A character string with measured length implementation file. |
* @see measured_strings.h |
*/ |
#include <errno.h> |
#include <malloc.h> |
#include <stdio.h> |
#include <string.h> |
#include <unistd.h> |
#include <ipc/ipc.h> |
#include "../err.h" |
#include "../modules.h" |
#include "measured_strings.h" |
/** Computes the lengths of the measured strings in the given array. |
* @param strings The measured strings array to be processed. Input parameter. |
* @param count The measured strings array size. Input parameter. |
* @returns The computed sizes array. |
* @returns NULL if there is no memory left. |
*/ |
size_t * prepare_lengths( const 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 ); |
// append terminating zero explicitly - to be safe |
memcpy( new->value, string, new->length ); |
new->value[ new->length ] = '\0'; |
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(( ! ipc_data_write_receive( & callid, & length )) |
|| ( 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; |
( * data )[ lengths[ count ] - 1 ] = '\0'; |
* 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 ){ |
if(( ! ipc_data_write_receive( & callid, & length )) |
|| ( length != lengths[ index ] )){ |
free( * data ); |
free( * strings ); |
free( lengths ); |
return EINVAL; |
} |
ERROR_PROPAGATE( ipc_data_write_finalize( callid, next, lengths[ index ] )); |
( * strings)[ index ].value = next; |
next += lengths[ index ]; |
* next = '\0'; |
++ next; |
}else{ |
( * strings )[ index ].value = NULL; |
} |
} |
free( lengths ); |
return EOK; |
} |
int measured_strings_reply( const 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(( ! ipc_data_read_receive( & callid, & length )) |
|| ( length != sizeof( size_t ) * ( count + 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 ){ |
if(( ! ipc_data_read_receive( & callid, & length )) |
|| ( length != strings[ index ].length )){ |
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 ){ |
ERROR_PROPAGATE( ipc_data_read_start( phone, next, lengths[ index ] )); |
( * strings )[ index ].value = next; |
next += lengths[ index ]; |
* next = '\0'; |
++ next; |
}else{ |
( * strings )[ index ].value = NULL; |
} |
} |
free( lengths ); |
return EOK; |
} |
int measured_strings_send( int phone, const 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 )); |
} |
} |
return EOK; |
} |
size_t * prepare_lengths( const 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 |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/char_map.h |
---|
0,0 → 1,155 |
/* |
* 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 |
* A character string to integer map header file. |
*/ |
#ifndef __CHAR_MAP_H__ |
#define __CHAR_MAP_H__ |
/** An invalid assigned value used also if an entry does not exist. |
*/ |
#define CHAR_MAP_NULL ( -1 ) |
/** A type definition of a character string to integer map. |
* @see char_map |
*/ |
typedef struct char_map char_map_t; |
/** A type definition of a character string to integer map pointer. |
* @see char_map |
*/ |
typedef char_map_t * char_map_ref; |
/** A character string to integer map item. |
* This structure recursivelly contains itself as a character by character tree. |
* The actually mapped character string consists o fall the parent characters and the actual one. |
*/ |
struct char_map{ |
/** An actually mapped character. |
*/ |
char c; |
/** A stored integral value. |
*/ |
int value; |
/** A next character array size. |
*/ |
int size; |
/** The first free position in the next character array. |
*/ |
int next; |
/** The next character array. |
*/ |
char_map_ref * items; |
/** The consistency check magic value. |
*/ |
int magic; |
}; |
/** Adds the value with the key to the map. |
* @param map The character string to integer map. Input/output parameter. |
* @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter. |
* @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter. |
* @param value The integral value to be stored for the key character string. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the map is not valid. |
* @returns EINVAL if the identifier parameter is NULL. |
* @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\0) character. |
* @returns EEXIST if the key character string is already used. |
* @returns Other error codes as defined for the char_map_add_item() function. |
*/ |
int char_map_add( char_map_ref map, const char * identifier, size_t length, const int value ); |
/** Clears and destroys the map. |
* @param map The character string to integer map. Input/output parameter. |
*/ |
void char_map_destroy( char_map_ref map ); |
/** Excludes the value assigned to the key from the map. |
* The entry is cleared from the map. |
* @param map The character string to integer map. Input/output parameter. |
* @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter. |
* @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter. |
* @returns The integral value assigned to the key character string. |
* @returns CHAR_MAP_NULL if the key is not assigned a value. |
*/ |
int char_map_exclude( char_map_ref map, const char * identifier, size_t length ); |
/** Returns the value assigned to the key from the map. |
* @param map The character string to integer map. Input parameter. |
* @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter. |
* @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter. |
* @returns The integral value assigned to the key character string. |
* @returns CHAR_MAP_NULL if the key is not assigned a value. |
*/ |
int char_map_find( const char_map_ref map, const char * identifier, size_t length ); |
/** Returns the value assigned to the map. |
* @param map The character string to integer map. Input parameter. |
* @returns The integral value assigned to the map. |
* @returns CHAR_MAP_NULL if the map is not assigned a value. |
*/ |
int char_map_get_value( const char_map_ref map ); |
/** Initializes the map. |
* @param map The character string to integer map. Input/output parameter. |
* @returns EOK on success. |
* @returns EINVAL if the map parameter is NULL. |
* @returns ENOMEM if there is no memory left. |
*/ |
int char_map_initialize( char_map_ref map ); |
/** Adds or updates the value with the key to the map. |
* @param map The character string to integer map. Input/output parameter. |
* @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter. |
* @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter. |
* @param value The integral value to be stored for the key character string. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the map is not valid. |
* @returns EINVAL if the identifier parameter is NULL. |
* @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\0) character. |
* @returns EEXIST if the key character string is already used. |
* @returns Other error codes as defined for the char_map_add_item() function. |
*/ |
int char_map_update( char_map_ref map, const char * identifier, size_t length, const int value ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/measured_strings.h |
---|
0,0 → 1,136 |
/* |
* 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 |
* A character string with measured length header file. |
* This structure has been designed for serialization of character strings between modules. |
*/ |
#ifndef __MEASURED_STRINGS_H__ |
#define __MEASURED_STRINGS_H__ |
/** A type definition of a character string with measured length. |
* @see measured_string |
*/ |
typedef struct measured_string measured_string_t; |
/** A type definition of a character string with measured length pointer. |
* @see measured_string |
*/ |
typedef measured_string_t * measured_string_ref; |
/** A character string with measured length. |
* This structure has been designed for serialization of character strings between modules. |
*/ |
struct measured_string{ |
/** The character string data. |
*/ |
char * value; |
/** The character string length. |
*/ |
size_t length; |
}; |
/** Creates a new measured string bundled with a copy of the given string itself as one memory block. |
* If the measured string is being freed, whole memory block is freed. |
* The measured string should be used only as a constant. |
* @param string The initial character string to be stored. Input parameter. |
* @param length The length of the given string without the terminating zero ('/0') character. If the length is zero (0), the actual length is computed. The given length is used and appended with the terminating zero ('\0') character otherwise. Input parameter. |
* @returns The new bundled charecter string with measured length. |
* @returns NULL if there is no memory left. |
*/ |
measured_string_ref measured_string_create_bulk( const char * string, size_t length ); |
/** Receives a measured strings array from a calling module. |
* Creates the array and the data memory blocks. |
* This method should be used only while processing IPC messages as the array size has to be negotiated in advance. |
* @param strings The received measured strings array. Output parameter. |
* @param data The measured strings data. This memory block stores the actual character strings. Output parameter. |
* @param count The size of the measured strings array. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the strings or data parameter is NULL. |
* @returns EINVAL if the count parameter is zero (0). |
* @returns EINVAL if the sent array differs in size. |
* @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur). |
* @returns ENOMEM if there is no memory left. |
* @returns Other error codes as defined for the ipc_data_write_finalize() function. |
*/ |
int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count ); |
/** Replies the given measured strings array to a calling module. |
* This method should be used only while processing IPC messages as the array size has to be negotiated in advance. |
* @param strings The measured strings array to be transferred. Input parameter. |
* @param count The measured strings array size. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the strings parameter is NULL. |
* @returns EINVAL if the count parameter is zero (0). |
* @returns EINVAL if the calling module does not accept the given array size. |
* @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur). |
* @returns Other error codes as defined for the ipc_data_read_finalize() function. |
*/ |
int measured_strings_reply( const measured_string_ref strings, size_t count ); |
/** Receives a measured strings array from another module. |
* Creates the array and the data memory blocks. |
* This method should be used only following other IPC messages as the array size has to be negotiated in advance. |
* @param phone The other module phone. Input parameter. |
* @param strings The returned measured strings array. Output parameter. |
* @param data The measured strings data. This memory block stores the actual character strings. Output parameter. |
* @param count The size of the measured strings array. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the strings or data parameter is NULL. |
* @returns EINVAL if the phone or count parameter is not positive (<=0). |
* @returns EINVAL if the sent array differs in size. |
* @returns ENOMEM if there is no memory left. |
* @returns Other error codes as defined for the ipc_data_read_start() function. |
*/ |
int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count ); |
/** Sends the given measured strings array to another module. |
* This method should be used only following other IPC messages as the array size has to be negotiated in advance. |
* @param phone The other module phone. Input parameter. |
* @param strings The measured strings array to be transferred. Input parameter. |
* @param count The measured strings array size. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the strings parameter is NULL. |
* @returns EINVAL if the phone or count parameter is not positive (<=0). |
* @returns Other error codes as defined for the ipc_data_write_start() function. |
*/ |
int measured_strings_send( int phone, const measured_string_ref strings, size_t count ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/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 |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/packet/packet_queue.h |
---|
0,0 → 1,61 |
/* |
* 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_PACKET_QUEUE__ |
#define __NET_PACKET_QUEUE__ |
#include "packet.h" |
typedef struct pq_item pq_item_t; |
typedef pq_item * pq_item_ref; |
typedef pq_item_ref pq_head_t; |
typedef pq_head * pq_head_ref; |
struct pq_item{ |
int order; |
size_t metric; |
packet_t packet; |
pq_item_ref previous; |
pq_item_ref next; |
}; |
pq_head_t pq_create( packet_t packet, int order, size_t metric ); |
pq_item_ref pq_add( pq_head_ref queue, packet_t packet, int order, size_t metric ); |
void pq_destroy( pq_head_t queue ); |
#endif |
/** @} |
*/ |
/branches/network/uspace/srv/net/structures/packet/packet.c |
---|
0,0 → 1,158 |
/* |
* 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 <unistd.h> |
#include <string.h> |
#include <ipc/ipc.h> |
#include <sys/mman.h> |
#include "../../err.h" |
#include "packet.h" |
#define PACKET_MAGIC_VALUE 0x11227788 |
struct packet{ |
size_t length; |
size_t max_prefix; |
size_t max_content; |
size_t data_start; |
size_t data_end; |
int magic_value; |
}; |
int packet_is_valid( packet_t packet ); |
packet_t packet_create( size_t max_prefix, size_t max_content, size_t max_sufix ){ |
size_t length; |
packet_t packet; |
length = max_prefix + max_content + max_sufix; |
packet = ( packet_t ) mmap( NULL, sizeof( struct packet ) + length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0 ); |
if( packet == MAP_FAILED ) return NULL; |
packet->length = length; |
packet->max_prefix = max_prefix; |
packet->max_content = max_content; |
packet->data_start = sizeof( struct packet ) + packet->max_prefix; |
packet->data_end = packet->data_start; |
packet->magic_value = PACKET_MAGIC_VALUE; |
return packet; |
} |
int packet_is_valid( packet_t packet ){ |
return packet && ( packet->magic_value == PACKET_MAGIC_VALUE ); |
} |
packet_t packet_copy( packet_t packet ){ |
packet_t new; |
if( ! packet_is_valid( packet )) return NULL; |
new = ( packet_t ) mmap( NULL, packet->length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0 ); |
if( new == MAP_FAILED ) return NULL; |
memcpy( new, packet, packet->length ); |
return new; |
} |
int packet_copy_data( packet_t packet, void * data, size_t length ){ |
if( ! packet_is_valid( packet )) return EINVAL; |
if( packet->data_start + length >= (( size_t ) packet ) + packet->length ) return ENOMEM; |
memcpy( packet + packet->data_start, data, length ); |
if( packet->data_start + length > packet->data_end ){ |
packet->data_end = packet->data_start + length; |
} |
return EOK; |
} |
void * packet_prepend( packet_t packet, size_t length ){ |
if(( ! packet_is_valid( packet )) || ( packet->data_start - sizeof( struct packet ) < length )) return NULL; |
packet->data_start -= length; |
return packet + packet->data_start; |
} |
void * packet_append( packet_t packet, size_t length ){ |
if(( ! packet_is_valid( packet )) || ( packet->data_end + length >= (( size_t ) packet ) + packet->length )) return NULL; |
packet->data_end += length; |
return packet + packet->data_end - length; |
} |
int packet_trim( packet_t packet, size_t prefix, size_t sufix ){ |
if(( ! packet_is_valid( packet )) || ( prefix + sufix > packet->data_end - packet->data_start )) return EINVAL; |
packet->data_start += prefix; |
packet->data_end -= sufix; |
return EOK; |
} |
int packet_send( packet_t packet, int phone ){ |
if( ! packet_is_valid( packet )) return EINVAL; |
return ipc_share_out_start( phone, packet, PROTO_READ | PROTO_WRITE ); |
} |
int packet_receive( packet_ref packet ){ |
ERROR_DECLARE; |
ipc_callid_t callid; |
size_t size; |
int flags; |
if( ! packet ) return EINVAL; |
if( ! ipc_share_out_receive( & callid, & size, & flags )) return EINVAL; |
* packet = ( packet_t ) as_get_mappable_page( size ); |
if( !( * packet )) return ENOMEM; |
if( ERROR_OCCURED( ipc_share_out_finalize( callid, * packet ))){ |
munmap( * packet, size ); |
return ERROR_CODE; |
} |
return EOK; |
} |
int packet_destroy( packet_t packet ){ |
if( ! packet_is_valid( packet )) return EINVAL; |
return munmap( packet, sizeof( struct packet ) + packet->length ); |
} |
size_t packet_get_data_length( packet_t packet ){ |
if( ! packet_is_valid( packet )) return 0; |
return packet->data_end - packet->data_start; |
} |
void * packet_get_data( packet_t packet ){ |
if( ! packet_is_valid( packet )) return NULL; |
return packet + packet->data_start; |
} |
/** @} |
*/ |
/branches/network/uspace/srv/net/structures/packet/packet_queue.c |
---|
0,0 → 1,110 |
/* |
* 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 <malloc.h> |
#include "../../configuration.h" |
#include "packet.h" |
#include "packet_queue.h" |
#define PQ_MAGIC_VALUE 0x23465968; |
static inline int pq_is_valid( pq_item_ref item ); |
pq_item_ref pq_add( pq_head * queue, packet_t packet, int order, size_t metric ){ |
pq_item_ref item; |
pq_item_ref tmp; |
tmp = pq_create( packet, order, metric ); |
if( ! tmp ) return NULL; |
item = queue; |
while( pq_is_valid( item )){ |
if( item->order < order ){ |
if( item->next && pq_is_valid( item->next )){ |
item = item->next; |
}else{ |
item->next = tmp; |
tmp->previous = item; |
return tmp; |
} |
}else{ |
tmp->previous = item->previous; |
tmp->next = item; |
item->previous = tmp; |
if( tmp->previous ){ |
tmp->previous->next = tmp; |
}else{ |
* queue = tmp; |
} |
return tmp; |
} |
} |
} |
pq_head pq_create( packet_t packet, int order, size_t metric ){ |
pq_item_ref item; |
item = ( pq_item_ref ) malloc( sizeof( pq_item_t )); |
if( ! item ) return NULL; |
item->order = order; |
item->metric = metric; |
item->packet = packet; |
item->previous = NULL; |
item->next = NULL; |
item->magic_value = PQ_MAGIC_VALUE; |
return item; |
} |
void pq_destroy( pq_head queue ){ |
pq_item_ref actual; |
pq_item_ref next; |
actual = queue; |
while( pq_is_valid( actual )){ |
next = actual->next; |
actual->magic_value = 0; |
free( actual ); |
actual = next; |
} |
} |
static inline int pq_is_valid( pq_item_ref item ){ |
return item && ( item->magic_value == PQ_MAGIC_VALUE ); |
} |
/** @} |
*/ |
/branches/network/uspace/srv/net/structures/packet/packet.h |
---|
0,0 → 1,62 |
/* |
* 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_PACKET_H__ |
#define __NET_PACKET_H__ |
#define PACKET_PREPEND( packet, type ) ( type * ) packet_prepend(( packet ), sizeof( type )) |
#define PACKET_APPEND( packet, type ) ( type * ) packet_append(( packet ), sizeof( type )) |
#define PACKET_TRIM( packet, prefix, sufix ) packet_trim(( packet ), sizeof( prefix ), sizeof( sufix )) |
typedef struct packet * packet_t; |
typedef packet_t * packet_ref; |
packet_t packet_create( size_t max_prefix, size_t max_content, size_t max_sufix ); |
void * packet_prepend( packet_t packet, size_t length ); |
void * packet_append( packet_t packet, size_t length ); |
packet_t packet_copy( packet_t packet ); |
int packet_copy_data( packet_t packet, void * data, size_t length ); |
// TODO protocol identification? |
int packet_send( packet_t packet, int phone ); |
int packet_receive( packet_ref packet ); |
int packet_trim( packet_t packet, size_t prefix, size_t sufix ); |
int packet_destroy( packet_t packet ); |
size_t packet_get_data_length( packet_t packet ); |
void * packet_get_data( packet_t packet ); |
#endif |
/** @} |
*/ |
/branches/network/uspace/srv/net/structures/packet |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/char_map.c |
---|
0,0 → 1,210 |
/* |
* 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 |
* A character string to integer map implementation file. |
*/ |
#include <errno.h> |
#include <malloc.h> |
#include <unistd.h> |
#include <string.h> |
#include "char_map.h" |
/** An internal magic value for a consistency check. |
*/ |
#define CHAR_MAP_MAGIC_VALUE 0x12345611 |
/** Adds the value with the key to the map. |
* Creates new nodes to map the key. |
* @param map The character string to integer map. Input/output parameter. |
* @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter. |
* @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter. |
* @param value The integral value to be stored for the key character string. Input parameter. |
* @returns EOK on success. |
* @returns ENOMEM if there is no memory left. |
* @returns EEXIST if the key character string is already used. |
*/ |
int char_map_add_item( char_map_ref map, const char * identifier, size_t length, const int value ); |
/** Returns the node assigned to the key from the map. |
* @param map The character string to integer map. Input parameter. |
* @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter. |
* @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter. |
* @returns The node holding the integral value assigned to the key character string. |
* @returns NULL if the key is not assigned a node. |
*/ |
char_map_ref char_map_find_node( const char_map_ref map, const char * identifier, const size_t length ); |
/** Checks if the map is valid. |
* @param map The character string to integer map. Input parameter. |
* @returns TRUE if the map is valid. |
* @returns FALSE otherwise. |
*/ |
int char_map_is_valid( const char_map_ref map ); |
int char_map_add( char_map_ref map, const char * identifier, size_t length, const int value ){ |
if( char_map_is_valid( map ) && ( identifier ) && (( length ) || ( * identifier ))){ |
int index; |
for( index = 0; index < map->next; ++ index ){ |
if( map->items[ index ]->c == * identifier ){ |
++ identifier; |
if( length ) -- length; |
if( length || ( * identifier )){ |
return char_map_add( map->items[ index ], identifier, length, 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, length, value ); |
} |
return EINVAL; |
} |
int char_map_add_item( char_map_ref map, const char * identifier, size_t length, 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( length ) -- length; |
++ map->next; |
if( length || ( * identifier )){ |
map->items[ map->next - 1 ]->value = CHAR_MAP_NULL; |
return char_map_add_item( map->items[ map->next - 1 ], identifier, length, value ); |
}else{ |
map->items[ map->next - 1 ]->value = value; |
} |
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, size_t length ){ |
char_map_ref node; |
node = char_map_find_node( map, identifier, length ); |
if( node ){ |
int value; |
value = node->value; |
node->value = CHAR_MAP_NULL; |
return value; |
} |
return CHAR_MAP_NULL; |
} |
int char_map_find( const char_map_ref map, const char * identifier, size_t length ){ |
char_map_ref node; |
node = char_map_find_node( map, identifier, length ); |
return node ? node->value : CHAR_MAP_NULL; |
} |
char_map_ref char_map_find_node( const char_map_ref map, const char * identifier, size_t length ){ |
if( ! char_map_is_valid( map )) return NULL; |
if( length ) -- length; |
if( length || ( * 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, length ); |
} |
} |
return NULL; |
} |
return map; |
} |
int char_map_get_value( const 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( const char_map_ref map ){ |
return map && ( map->magic == CHAR_MAP_MAGIC_VALUE ); |
} |
int char_map_update( char_map_ref map, const char * identifier, const size_t length, const int value ){ |
char_map_ref node; |
// if( ! char_map_is_valid( map )) return EINVAL; |
node = char_map_find_node( map, identifier, length ); |
if( node ){ |
node->value = value; |
return EOK; |
}else{ |
return char_map_add( map, identifier, length, value ); |
} |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/generic_char_map.h |
---|
0,0 → 1,138 |
/* |
* 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 "../err.h" |
#include "char_map.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, const size_t length, type * value ); \ |
int name##_count( name##_ref map ); \ |
void name##_destroy( name##_ref map ); \ |
void name##_exclude( name##_ref map, const char * name, const size_t length ); \ |
type * name##_find( name##_ref map, const char * name, const size_t length ); \ |
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, const size_t length, 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, length, 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, const size_t length ){ \ |
if( name##_is_valid( map )){ \ |
int index; \ |
\ |
index = char_map_exclude( & map->names, name, length ); \ |
if( index != CHAR_MAP_NULL ){ \ |
name##_items_exclude_index( & map->values, index ); \ |
} \ |
} \ |
} \ |
\ |
type * name##_find( name##_ref map, const char * name, const size_t length ){ \ |
if( name##_is_valid( map )){ \ |
int index; \ |
\ |
index = char_map_find( & map->names, name, length ); \ |
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 |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/structures/int_map.h |
---|
0,0 → 1,209 |
/* |
* 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 ); \ |
void name##_clear( name##_ref map ); \ |
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; \ |
} \ |
\ |
void name##_clear( 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 ] )); \ |
} \ |
} \ |
map->next = 0; \ |
map->items[ map->next ].magic = 0; \ |
/* map->magic = INT_MAP_MAGIC_VALUE;*/ \ |
} \ |
} \ |
\ |
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 |
Added: svn:mergeinfo |
/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; |
int networking_phone; |
printf( "\nTask %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_NET_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 \ |
../../self_test.c \ |
../../structures/measured_strings.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/networking/startup |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/networking/networking.c |
---|
44,15 → 44,16 |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../char_map.h" |
#include "../err.h" |
#include "../generic_char_map.h" |
#include "../measured_strings.h" |
#include "../messages.h" |
#include "../modules.h" |
//#include "../self_test.h" |
#include "../ip/ip_messages.h" |
#include "../structures/char_map.h" |
#include "../structures/generic_char_map.h" |
#include "../structures/measured_strings.h" |
#include "../il/ip/ip_messages.h" |
#include "../netif/device.h" |
#if IP_BUNDLE |
/branches/network/uspace/srv/net/networking/Makefile |
---|
42,9 → 42,9 |
OUTPUT = networking |
SOURCES = \ |
networking.c \ |
../char_map.c \ |
../measured_strings.c \ |
../modules.c |
../modules.c \ |
../structures/char_map.c \ |
../structures/measured_strings.c |
# ../self_test.c |
DEFS += -D NETWORKING_$(NETWORKING) |
/branches/network/uspace/srv/net/il/arp/arp_header.h |
---|
0,0 → 1,55 |
/* |
* 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 arp |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __NET_ARP_HEADER_H__ |
#define __NET_ARP_HEADER_H__ |
#include <sys/types.h> |
typedef struct arp_header arp_header_t; |
typedef arp_header_t * arp_header_ref; |
struct arp_header{ |
uint16_t hardware; |
uint16_t protocol; |
uint8_t hardware_length; |
uint8_t protocol_length; |
uint16_t operation; |
}; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/arp.c |
---|
0,0 → 1,429 |
/* |
* 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 arp |
* @{ |
*/ |
/** @file |
*/ |
#include <as.h> |
#include <async.h> |
#include <malloc.h> |
#include <stdio.h> |
#include <string.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../include/protocol_map.h" |
#include "../../netif/device.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet.h" |
#include "arp.h" |
#include "arp_header.h" |
#include "arp_oc.h" |
//#include "arp_messages.h" |
#include "arp_module.h" |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
arp_globals_t arp_globals; |
DEVICE_MAP_IMPLEMENT( arp_cache, arp_device_t ) |
INT_MAP_IMPLEMENT( arp_protos, arp_proto_t ) |
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t ) |
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address ); |
int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address ); |
measured_string_ref arp_translate_message( device_id_t device, services_t protocol, measured_string_ref target ); |
int arp_receive_message( device_id_t device_id, packet_t packet ); |
int arp_clear_device_message( device_id_t device_id ); |
void clear_device( arp_device_ref device ); |
int arp_clean_cache_message( void ); |
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
/** Initializes the ARP module. |
*/ |
int arp_initialize( void ){ |
arp_cache_initialize( & arp_globals.cache ); |
return EOK; |
} |
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address ){ |
ERROR_DECLARE; |
* proto = ( arp_proto_ref ) malloc( sizeof( arp_proto_t )); |
if( !( * proto )) return ENOMEM; |
( ** proto ).service = service; |
( ** proto ).addr = address; |
( ** proto ).addr_data = address->value; |
if( ERROR_OCCURED( arp_addr_initialize( &( ** proto).addresses ))){ |
free( * proto ); |
return ERROR_CODE; |
} |
return EOK; |
} |
int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address ){ |
ERROR_DECLARE; |
arp_device_ref device; |
aid_t message; |
ipc_call_t answer; |
ipcarg_t result; |
arp_proto_ref proto; |
// an existing device? |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( device ){ |
if( device->service != service ) return EEXIST; |
proto = arp_protos_find( & device->protos, protocol ); |
if( proto ){ |
free( proto->addr ); |
free( proto->addr_data ); |
proto->addr = address; |
proto->addr_data = address->value; |
}else{ |
ERROR_PROPAGATE( arp_proto_create( & proto, protocol, address )); |
if( ERROR_OCCURED( arp_protos_add( & device->protos, proto->service, proto ))){ |
free( proto ); |
return ERROR_CODE; |
} |
} |
return EOK; |
}else{ |
// create a new device |
device = ( arp_device_ref ) malloc( sizeof( arp_device_t )); |
if( ! device ) return ENOMEM; |
device->device_id = device_id; |
if( ERROR_OCCURED( arp_protos_initialize( & device->protos )) |
|| ERROR_OCCURED( arp_proto_create( & proto, protocol, address ))){ |
free( device ); |
return ERROR_CODE; |
} |
if( ERROR_OCCURED( arp_protos_add( & device->protos, proto->service, proto ))){ |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
} |
device->service = service; |
// bind the new one |
device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver ); |
// get packet dimensions |
if( ERROR_OCCURED( async_req_1_3( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->prefix, & device->content, & device->sufix ))){ |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
} |
// get hardware address |
message = async_send_1( device->phone, NET_NIL_ADDR, device->device_id, & answer ); |
if( ERROR_OCCURED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){ |
arp_protos_destroy( & device->protos ); |
free( device ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
if( ERROR_OCCURED( result )){ |
free( device->addr ); |
free( device->addr_data ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
} |
// get broadcast address |
message = async_send_1( device->phone, NET_NIL_BROADCAST_ADDR, device->device_id, & answer ); |
if( ERROR_OCCURED( measured_strings_return( device->phone, & device->broadcast_addr, & device->broadcast_data, 1 ))){ |
free( device->addr ); |
free( device->addr_data ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
// add to the cache |
if( ERROR_OCCURED( result ) |
|| ERROR_OCCURED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){ |
free( device->addr ); |
free( device->addr_data ); |
free( device->broadcast_addr ); |
free( device->broadcast_data ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
} |
} |
return EOK; |
} |
measured_string_ref arp_translate_message( device_id_t device_id, services_t protocol, measured_string_ref target ){ |
// ERROR_DECLARE; |
arp_device_ref device; |
arp_proto_ref proto; |
measured_string_ref addr; |
size_t length; |
packet_t packet; |
arp_header_ref header; |
if( ! target ) return NULL; |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ) return NULL; |
proto = arp_protos_find( & device->protos, protocol ); |
if(( ! proto ) || ( proto->addr->length != target->length )) return NULL; |
addr = arp_addr_find( & proto->addresses, target->value, target->length ); |
if( addr ) return addr; |
// ARP packet content size = header + ( address + translation ) * 2 |
length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2; |
if( length > device->content ){ |
return NULL; |
} |
packet = packet_create( device->prefix, length, device->sufix ); |
if( ! packet ) return NULL; |
header = ( arp_header_ref ) packet_append( packet, length ); |
header->hardware = device->hardware; |
header->hardware_length = device->addr->length; |
header->protocol = protocol_map( device->service, protocol ); |
header->protocol_length = proto->addr->length; |
header->operation = ARPOP_REQUEST; |
length = sizeof( arp_header_t ); |
memcpy((( uint8_t * ) header ) + length, device->addr->value, device->addr->length ); |
length += device->addr->length; |
memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length ); |
length += proto->addr->length; |
memset((( uint8_t * ) header ) + length, 0, device->addr->length ); |
length += device->addr->length; |
memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
// TODO send to the device->broadcast_addr as arp protocol |
packet_send( packet, device->phone ); |
return NULL; |
} |
int arp_receive_message( device_id_t device_id, packet_t packet ){ |
ERROR_DECLARE; |
size_t length; |
arp_header_ref header; |
arp_device_ref device; |
arp_proto_ref proto; |
// arp_addr_ref addr; |
measured_string_ref hw_source; |
/* measured_string_t proto_target; |
aid_t message; |
ipcarg_t result; |
int index; |
ipc_call_t answer; |
*/ int8_t * src_hw; |
int8_t * src_proto; |
int8_t * des_hw; |
int8_t * des_proto; |
length = packet_get_data_length( packet ); |
if( length <= sizeof( arp_header_t )) return EINVAL; |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ) return ENOENT; |
header = ( arp_header_ref ) packet_get_data( packet ); |
if( header->hardware != device->hardware ) return EINVAL; |
if( length < sizeof( arp_header_t ) + ( header->hardware_length + header->protocol_length ) * 2 ) return EINVAL; |
proto = arp_protos_find( & device->protos, protocol_unmap( device->service, header->protocol )); |
if( ! proto ) return ENOENT; |
src_hw = (( int8_t * ) header ) + sizeof( arp_header_t ); |
src_proto = src_hw + header->hardware_length; |
des_hw = src_proto + header->protocol_length; |
des_proto = des_hw + header->hardware_length; |
hw_source = arp_addr_find( & proto->addresses, src_proto, header->protocol_length ); |
// exists? |
if( hw_source ){ |
if( hw_source->length != header->hardware_length ) return EINVAL; |
memcpy( hw_source->value, src_hw, header->hardware_length ); |
} |
// is my protocol address? |
/* proto_target.value = des_proto; |
proto_target.length = header->protocol_length; |
// TODO send necessary? |
message = async_send_0( proto->phone, NET_IL_MY_ADDR, & answer ); |
if( ERROR_OCCURED( measured_strings_send( device->phone, & proto_target, 1 ))){ |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
if( result == EOK ){ |
*/ if( proto->addr->length != header->hardware_length ) return EINVAL; |
if( ! strncmp( proto->addr->value, des_proto, proto->addr->length )){ |
// not already upadted? |
if( ! hw_source ){ |
hw_source = measured_string_create_bulk( src_hw, header->hardware_length ); |
if( ! hw_source ) return ENOMEM; |
ERROR_PROPAGATE( arp_addr_add( & proto->addresses, src_proto, header->protocol_length, hw_source )); |
} |
if( header->operation == ARPOP_REQUEST ){ |
header->operation = ARPOP_REPLY; |
/* for( index = 0; index + header->hardware_length < header->protocol_length; index += header->hardware_length ){ |
memcpy( src_hw, src_proto + index, header->hardware_length ); |
memcpy( src_proto + index, des_proto + index, header->hardware_length ); |
memcpy( des_proto + index, src_hw, header->hardware_length ); |
} |
memcpy( src_hw, src_proto + index, header->hardware_length - header->protocol_length ); |
memcpy( src_proto + index, des_proto + index, header->hardware_length - header->protocol_length ); |
memcpy( des_proto + index, src_hw, header->hardware_length - header->protocol_length ); |
memcpy( src_hw, des_hw, header->hardware_length ); |
memcpy( des_hw, hw_source->value, hw_source->length ); |
*/ memcpy( des_proto, src_proto, header->protocol_length ); |
memcpy( src_proto, proto->addr->value, header->protocol_length ); |
memcpy( src_hw, des_hw, header->hardware_length ); |
memcpy( des_hw, hw_source->value, hw_source->length ); |
// TODO send to the hw_source as arp protocol |
packet_send( packet, device->phone ); |
} |
} |
return EOK; |
} |
int arp_clear_device_message( device_id_t device_id ){ |
arp_device_ref device; |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ) return ENOENT; |
clear_device( device ); |
return EOK; |
} |
void clear_device( arp_device_ref device ){ |
int count; |
arp_proto_ref proto; |
count = arp_protos_count( & device->protos ); |
while( count > 0 ){ |
proto = arp_protos_get_index( & device->protos, count ); |
if( proto->addr ) free( proto->addr ); |
if( proto->addr_data ) free( proto->addr_data ); |
arp_addr_destroy( & proto->addresses ); |
-- count; |
} |
arp_protos_clear( & device->protos ); |
} |
int arp_clean_cache_message( void ){ |
int count; |
arp_device_ref device; |
count = arp_cache_count( & arp_globals.cache ); |
while( count > 0 ){ |
device = arp_cache_get_index( & arp_globals.cache, count ); |
if( device ){ |
clear_device( device ); |
if( device->broadcast_addr ) free( device->broadcast_addr ); |
if( device->broadcast_data ) free( device->broadcast_data ); |
} |
} |
arp_cache_clear( & arp_globals.cache ); |
return EOK; |
} |
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
// packet_t packet; |
measured_string_ref address; |
measured_string_ref translation; |
char * data; |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_ARP_DEVICE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
if( ERROR_OCCURED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_PROTO( call ), address ))){ |
free( address ); |
free( data ); |
} |
return ERROR_CODE; |
case NET_ARP_TRANSLATE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
translation = arp_translate_message( IPC_GET_DEVICE( call ), IPC_GET_PROTO( call ), address ); |
free( address ); |
free( data ); |
if( ! translation ) return ENOENT; |
return measured_strings_reply( translation, 1 ); |
case NET_ARP_CLEAR_DEVICE: |
return arp_clear_device_message( IPC_GET_DEVICE( call )); |
case NET_ARP_CLEAN_CACHE: |
return arp_clean_cache_message(); |
} |
return ENOTSUP; |
} |
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
ERROR_DECLARE; |
ipc_callid_t callid; |
ipc_call_t call; |
// int result; |
packet_t packet; |
/* |
* Accept the connection |
* - Answer the first IPC_M_CONNECT_ME_TO call. |
*/ |
//TODO auto accept? |
//ipc_answer_0( iid, EOK ); |
while( true ){ |
callid = async_get_call( & call ); |
switch( IPC_GET_METHOD( call )){ |
case NET_IL_DEVICE_STATE: |
//TODO clear device if off? |
break; |
case NET_IL_RECEIVED: |
if( ! ERROR_OCCURED( packet_receive( & packet ))){ |
ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( & call ), packet ); |
} |
ipc_answer_0( callid, ERROR_CODE ); |
break; |
default: |
ipc_answer_0( callid, ENOTSUP ); |
} |
} |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/arp.h |
---|
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 arp |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __NET_ARP_H__ |
#define __NET_ARP_H__ |
#include <ipc/ipc.h> |
#include "../../netif/device.h" |
#include "../../structures/generic_char_map.h" |
#include "../../structures/int_map.h" |
#include "../../structures/measured_strings.h" |
typedef struct arp_globals arp_globals_t; |
typedef arp_globals_t * arp_globals_ref; |
typedef struct arp_device arp_device_t; |
typedef arp_device_t * arp_device_ref; |
typedef struct arp_proto arp_proto_t; |
typedef arp_proto_t * arp_proto_ref; |
DEVICE_MAP_DECLARE( arp_cache, arp_device_t ) |
INT_MAP_DECLARE( arp_protos, arp_proto_t ) |
GENERIC_CHAR_MAP_DECLARE( arp_addr, measured_string_t ) |
struct arp_device{ |
device_id_t device_id; |
ipcarg_t hardware; |
ipcarg_t protocol; |
ipcarg_t prefix; |
ipcarg_t content; |
ipcarg_t sufix; |
measured_string_ref addr; |
char * addr_data; |
measured_string_ref broadcast_addr; |
char * broadcast_data; |
services_t service; |
int phone; |
arp_protos_t protos; |
}; |
struct arp_proto{ |
services_t service; |
// int phone; |
measured_string_ref addr; |
char * addr_data; |
arp_addr_t addresses; |
}; |
struct arp_globals{ |
int networking_phone; |
arp_cache_t cache; |
}; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/arp_module.c |
---|
0,0 → 1,75 |
/* |
* 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 arp |
* @{ |
*/ |
/** @file |
*/ |
#include <async.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../err.h" |
#include "../../modules.h" |
#include "arp.h" |
#include "arp_module.h" |
#define NAME "ARP protocol" |
void arp_print_name( void ); |
int arp_start_module( async_client_conn_t client_connection ); |
extern arp_globals_t arp_globals; |
void arp_print_name( void ){ |
printf( NAME ); |
} |
int arp_start_module( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
ipcarg_t phonehash; |
async_set_client_connection( client_connection ); |
arp_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
ERROR_PROPAGATE( arp_initialize()); |
ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash )); |
async_manager(); |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/arp_oc.h |
---|
0,0 → 1,136 |
/* |
* 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 arp |
* @{ |
*/ |
/** @file |
* ARP operation codes according to the online IANA - Address Resolution Protocol (ARP) Parameters - <http://www.iana.org/assignments/arp-parameters/arp-parameters.xml>, cited January 14 2009. |
* Names according to the linux src/include/linux/if_arp.h header file. |
*/ |
#ifndef __NET_ARP_ARPOP_H__ |
#define __NET_ARP_ARPOP_H__ |
/** REQUEST operation code. |
*/ |
#define ARPOP_REQUEST 1 |
/** REPLY operation code. |
*/ |
#define ARPOP_REPLY 2 |
/** Reverse request operation code. |
*/ |
#define ARPOP_RREQUEST 3 |
/** Reverse reply operation code. |
*/ |
#define ARPOP_RREPLY 4 |
/** DRARP-Request operation code. |
*/ |
#define ARPOP_DRARP_Request 5 |
/** DRARP-Reply operation code. |
*/ |
#define ARPOP_DRARP_Reply 6 |
/** DRARP-Error operation code. |
*/ |
#define ARPOP_DRARP_Error 7 |
/** InARP-Request operation code. |
*/ |
#define ARPOP_InREQUEST 8 |
/** InARP-Reply operation code. |
*/ |
#define ARPOP_InREPLY 9 |
/** ARP-NAK operation code. |
*/ |
#define ARPOP_NAK 10 |
/** MARS-Request operation code. |
*/ |
#define ARPOP_MARS_Request 11 |
/** MARS-Multi operation code. |
*/ |
#define ARPOP_MARS_Multi 12 |
/** MARS-MServ operation code. |
*/ |
#define ARPOP_MARS_MServ 13 |
/** MARS-Join operation code. |
*/ |
#define ARPOP_MARS_Join 14 |
/** MARS-Leave operation code. |
*/ |
#define ARPOP_MARS_Leave 15 |
/** MARS-NAK operation code. |
*/ |
#define ARPOP_MARS_NAK 16 |
/** MARS-Unserv operation code. |
*/ |
#define ARPOP_MARS_Unserv 17 |
/** MARS-SJoin operation code. |
*/ |
#define ARPOP_MARS_SJoin 18 |
/** MARS-SLeave operation code. |
*/ |
#define ARPOP_MARS_SLeave 19 |
/** MARS-Grouplist-Request operation code. |
*/ |
#define ARPOP_MARS_Grouplist_Request 20 |
/** MARS-Grouplist-Reply operation code. |
*/ |
#define ARPOP_MARS_Grouplist_Reply 21 |
/** MARS-Redirect-Map operation code. |
*/ |
#define ARPOP_MARS_Redirect_Map 22 |
/** MAPOS-UNARP operation code. |
*/ |
#define ARPOP_MAPOS_UNARP 23 |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/Makefile |
---|
0,0 → 1,84 |
# |
# 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. |
# |
NAME = arp |
## Setup toolchain |
# |
LIBC_PREFIX = ../../../../lib/libc |
SOFTINT_PREFIX = ../../../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
LIBS = $(LIBC_PREFIX)/libc.a |
## Sources |
# |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME)_module.c \ |
$(NAME).c \ |
../../module.c \ |
../../modules.c \ |
../../structures/char_map.c \ |
../../structures/measured_strings.c \ |
../../structures/packet/packet.c |
DEFS += -D ARP_BUNDLE=1 -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 |
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/il/arp/arp_module.h |
---|
0,0 → 1,48 |
/* |
* 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 arp |
* @{ |
*/ |
/** |
* @file |
*/ |
#ifndef __NET_ARP_MODULE_H__ |
#define __NET_ARP_MODULE_H__ |
#include <ipc/ipc.h> |
int arp_initialize( void ); |
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/il/rarp |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/il/icmp |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/il/ip/ip_module.h |
---|
0,0 → 1,48 |
/* |
* 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_IP_MODULE_H__ |
#define __NET_IP_MODULE_H__ |
#include <ipc/ipc.h> |
int ip_initialize( void ); |
int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip_messages.h |
---|
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 |
*/ |
#ifndef __NET_IP_MESSAGES_H__ |
#define __NET_IP_MESSAGES_H__ |
#include <ipc/ipc.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "../../structures/packet/packet.h" |
#if IP_BUNDLE |
int ip_device_message( device_id_t device_id, services_t service ); |
int ip_echo_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t * res1, ipcarg_t * res2, ipcarg_t * res3, ipcarg_t * res4, ipcarg_t * res5 ); |
int ip_send_message( device_id_t device_id, packet_t packet ); |
#define ip_device( ip_phone, device_id, service ) \ |
ip_device_message(( device_id ), ( service )) |
#define ip_echo( ip_phone, arg1, arg2, arg3, arg4, arg5, answer1, answer2, answer3, answer4, answer5 ) \ |
ip_echo_message(( arg1 ), ( arg2 ), ( arg3 ), ( arg4 ), ( arg5 ), ( answer1 ), ( answer2 ), ( answer3 ), ( answer4 ), ( answer5 )) |
#define ip_send( ip_phone, device_id, packet ) \ |
ip_send_message(( device_id ), ( packet )); |
#else |
#define ip_device( ip_phone, device_id, service ) \ |
ipc_sync_send_2_0( ip_phone, NET_IP_DEVICE, ( device_id ), ( service )) |
#define ip_echo( ip_phone, arg1, arg2, arg3, arg4, arg5, answer1, answer2, answer3, answer4, answer5 ) \ |
async_req_5_5( ip_phone, NET_IP_ECHO, ( arg1 ), ( arg2 ), ( arg3 ), ( arg4 ), ( arg5 ), ( answer1 ), ( answer2 ), ( answer3 ), ( answer4 ), ( answer5 )) |
#define ip_send( ip_phone, device_id, packet ) \ |
{ \ |
ERROR_DECLARE; \ |
\ |
aid_t message; \ |
ipc_call_t answer; \ |
ipcarg_t result; \ |
\ |
message = async_send_1(( ip_phone ), NET_IP_SEND, ( device_id ), & answer ); \ |
if( ERROR_OCCURED( packet_send(( packet ), ( ip_phone )))){ \ |
async_wait_for( message, NULL ); \ |
result = ERROR_CODE; \ |
}else{ \ |
async_wait_for( message, & result ); \ |
} \ |
result; \ |
} |
#endif |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip_header.h |
---|
0,0 → 1,260 |
/* |
* 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 |
* Interent protocol header and options definitions. |
* Names according to the linux src/include/linux/ip.h header file. |
*/ |
#ifndef __NET_IP_HEADER_H__ |
#define __NET_IP_HEADER_H__ |
#include <byteorder.h> |
#include <types.h> |
typedef struct ip_header ip_header_t; |
typedef ip_header_t * ip_header_ref; |
/** Internet header. |
* The variable options should be included after the header itself and indicated by the increased header length value. |
*/ |
struct ip_header{ |
#ifdef ARCH_IS_BIG_ENDIAN |
/** The Version field indicates the format of the internet header. |
*/ |
uint8_t:4 version; |
/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
* Note that the minimum value for a~correct header is~5. |
*/ |
uint8_t:4 ihl; |
#else |
/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
* Note that the minimum value for a~correct header is~5. |
*/ |
uint8_t:4 ihl; |
/** The Version field indicates the format of the internet header. |
*/ |
uint8_t:4 version; |
#endif |
/** The Type of Service provides an indication of the abstract parameters of the quality of service desired. |
* These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network. |
* Several networks offer service precedence, which somehow treats high precedence traffic as more important than other traffic (generally by accepting only traffic above a~certain precedence at time of high load). |
* The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput. |
*/ |
uint8_t tos; |
/** Total Length is the length of the datagram, measured in octets, including internet header and data. |
* This field allows the length of a~datagram to be up to 65,535~octets. |
*/ |
uint16_t total_length; |
/** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram. |
*/ |
unit16_t identification; |
#ifdef ARCH_IS_BIG_ENDIAN |
/** Various control flags. |
*/ |
uint_16:3 flags; |
/** This field indicates where in the datagram this fragment belongs. |
*/ |
uint_16:13 fragment_offset; |
#else |
/** This field indicates where in the datagram this fragment belongs. |
*/ |
uint_16:13 fragment_offset; |
/** Various control flags. |
*/ |
uint_16:3 flags; |
#endif |
/** This field indicates the maximum time the datagram is allowed to remain in the internet system. |
* If this field contains the value zero, then the datagram must be destroyed. |
* This field is modified in internet header processing. |
* The time is measured in units of seconds, but since every module that processes a~datagram must decrease the TTL by at least one even if it process the datagram in less than a~second, the TTL must be thought of only as an upper bound on the time a~datagram may exist. |
* The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime. |
*/ |
uint8_t ttl; |
/** This field indicates the next level protocol used in the data portion of the internet datagram. |
*/ |
uint8_t protocol; |
/** A checksum on the header only. |
* Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed. |
* The checksum algorithm is: The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header. |
* For purposes of computing the checksum, the value of the checksum field is zero. |
*/ |
uint16_t header_checksum; |
/** The source address. |
*/ |
uint32_t source_address; |
/** The destination address. |
*/ |
uint32_t destination_address; |
}; |
typedef struct ip_option ip_option_t; |
typedef ip_option * ip_option_ref; |
/** Internet option header. |
* Only type field is always valid. |
* Other fields' validity depends on the option type. |
*/ |
struct ip_option{ |
/** A single octet of option-type. |
*/ |
uint8_t type; |
/** An option length octet. |
*/ |
uint8_t length; |
/** A~pointer. |
*/ |
uint8_t pointer; |
#ifdef ARCH_IS_BIG_ENDIAN |
/** The number of IP modules that cannot register timestamps due to lack of space. |
*/ |
uint8_t:4 overflow; |
/** Various internet timestamp control flags. |
*/ |
uint8_t:4 flags; |
#else |
/** Various internet timestamp control flags. |
*/ |
uint8_t:4 flags; |
/** The number of IP modules that cannot register timestamps due to lack of space. |
*/ |
uint8_t:4 overflow; |
#endif |
}; |
#define IPTOS_TOS_MASK 0x1E |
#define IPTOS_PRECEDENCE_SHIFT 5 |
#define IPTOS_DELAY_SHIFT 4 |
#define IPTOS_TROUGHPUT_SHIFT 3 |
#define IPTOS_RELIABILITY_SHIFT 2 |
#define IPTOS_COST_SHIFT 1 |
#define IPTOS_NORMALDELAY ( 0x0 << IPTOS_DELAY_SHIFT ) |
#define IPTOS_LOWDELAY ( 0x1 << IPTOS_DELAY_SHIFT ) |
#define IPTOS_NORMALTHROUGHPUT ( 0x0 << IPTOS_THROUGHPUT_SHIFT ) |
#define IPTOS_THROUGHPUT ( 0x1 << IPTOS_THROUGHPUT_SHIFT ) |
#define IPTOS_NORMALRELIABILITY ( 0x0 << IPTOS_RELIABILITY_SHIFT ) |
#define IPTOS_RELIABILITY ( 0x1 << IPTOS_RELIABILITY_SHIFT ) |
#define IPTOS_NORMALCOST ( 0x0 << IPTOS_COST_SHIFT ) |
#define IPTOS_MICNCOST ( 0x1 << IPTOS_COST_SHIFT ) |
#define IPTOS_PREC_MASK 0xE0 |
#define IPTOS_PREC_ROUTINE ( 0x0 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPTOS_PREC_PRIORITY ( 0x1 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPTOS_PREC_IMMEDIATE ( 0x2 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPTOS_PREC_FLASH ( 0x3 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPTOS_PREC_FLASHOVERRIDE ( 0x4 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPTOS_PREC_CRITIC_ECP ( 0x5 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPTOS_PREC_INTERNETCONTROL ( 0x6 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPTOS_PREC_NETCONTROL ( 0x7 << IPTOS_PRECEDENCE_SHIFT ) |
#define IPFLAG_FRAGMENT_SHIFT 1 |
#define IPFLAG_FRAGMENTED_SHIFT 0 |
#define IPFLAG_MAY_FRAGMENT ( 0x0 << IPFLAG_FRAGMENT_SHIFT ) |
#define IPFLAG_DONT_FRAGMENT ( 0x1 << IPFLAG_FRAGMENT_SHIFT ) |
#define IPFLAG_LAST_FRAGMENT ( 0x0 << IPFLAG_FRAGMENTED_SHIFT ) |
#define IPFLAG_MORE_FRAGMENTS ( 0x1 << IPFLAG_FRAGMENTED_SHIFT ) |
#define IPOPT_COPY_SHIFT 7 |
#define IPOPT_CLASS_SHIFT 5 |
#define IPOPT_NUMBER_SHIFT 0 |
#define IPOPT_CLASS_MASK 0x60 |
#define IPOPT_NUMBER_MASK 0x1F |
#define IPOPT_COPY ( 1 << IPOPT_COPY_SHIFT ) |
#define IPOPT_TYPE( copy, class, number ) ((( copy ) & IPOPT_COPY ) | (( class ) & IPOPT_CLASS_MASK ) | (( number << IPOPT_NUMBER_SHIFT ) & IPOPT_NUMBER_MASK )) |
#define IPOPT_COPIED( o ) (( o ) & IPOPT_COPY ) |
#define IPOPT_CLASS( o ) (( o ) & IPOPT_CLASS_MASK ) |
#define IPOPT_NUMBER( o ) (( o ) & IPOPT_NUMBER_MASK ) |
#define IPOPT_CONTROL ( 1 << IPOPT_CLASS_SHIFT ) |
#define IPOPT_RESERVED1 ( 2 << IPOPT_CLASS_SHIFT ) |
#define IPOPT_MEASUREMENT ( 3 << IPOPT_CLASS_SHIFT ) |
#define IPOPT_RESERVED2 ( 4 << IPOPT_CLASS_SHIFT ) |
//#define IPOPT_END_OF_LIST 0x0 |
#define IPOPT_END IPOPT_TYPE( 0, IPOPT_CONTROL, 0 ) |
//#define IPOPT_NO_OPERATION 0x1 |
#define IPOPT_NOOP IPOPT_TYPE( 0, IPOPT_CONTROL, 1 ) |
//#define IPOPT_SECURITY 0x82 |
#define IPOPT_SEC IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 2 ) |
#define IPOPT_SEC_LENGTH 11 |
#define IPOPT_SEC_UNCLASIFIED 0x0 |
#define IPOPT_SEC_CONFIDENTIAL 0xF035 |
#define IPOPT_SEC_EFTO 0x789A |
#define IPOPT_SEC_MMMM 0xBC4D |
#define IPOPT_SEC_PROG 0x5E26 |
#define IPOPT_SEC_RESTRICTED 0xAF13 |
#define IPOPT_SEC_SECRET 0xD788 |
#define IPOPT_SEC_TOP_SECRET 0x6BC5 |
//#define IPOPT_LOOSE_SOURCE 0x83 |
#define IPOPT_LSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 3 ) |
//#define IPOPT_STRICT_SOURCE 0x89 |
#define IPOPT_SSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 9 ) |
//#define IPOPT_RECORD_ROUTE 0x07 |
#define IPOPT_RR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 7 ) |
//#define IPOPT_STREAM_IDENTIFIER 0x88 |
#define IPOPT_SID IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 8 ) |
#define IPOPT_SID_LENGTH 4 |
//#define IPOPT_INTERNET_TIMESTAMP 0x44 |
#define IPOPT_TIMESTAMP IPOPT_TYPE( IPOPT_COPY, IPOPT_MEASUREMENT, 4 ) |
#define IPOPT_CIPSO IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 5 ) |
#define IPVERSION 4 |
#define MAXTTL 255 |
#define IPDEFTTL 64 |
#define IPOPT_OPTVAL 0 |
#define IPOPT_OLEN 1 |
#define IPOPT_OFFSET 2 |
#define IPOPT_MINOFF 4 |
#define MAX_IPOPTLEN 40 |
#define IPOPT_NOP IPOPT_NOOP |
#define IPOPT_EOL IPOPT_END |
#define IPOPT_TS IPOPT_TIMESTAMP |
#define IPOPT_TS_TSONLY 0 /* timestamps only */ |
#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ |
#define IPOPT_TS_PRESPEC 3 /* specified modules only */ |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip.c |
---|
0,0 → 1,279 |
/* |
* 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 <as.h> |
#include <async.h> |
#include <errno.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../include/sockaddr.h" |
#include "../../include/socket.h" |
#include "../../netif/device.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet.h" |
#include "ip.h" |
#include "ip_messages.h" |
#include "ip_module.h" |
#define DEFAULT_IPV 4 |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * call ) |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
ip_globals_t ip_globals; |
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
INT_MAP_IMPLEMENT( ip_protos, ip_proto_t ) |
int ip_register_message( int protocol, int phone ); |
int ip_state_message( device_id_t device_id, device_state_t state ); |
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
/** Initializes the module. |
*/ |
int ip_initialize( void ){ |
ip_netifs_initialize( & ip_globals.netifs ); |
ip_protos_initialize( & ip_globals.protos ); |
return EOK; |
} |
int ip_echo_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t * answer1, ipcarg_t * answer2, ipcarg_t * answer3, ipcarg_t * answer4, ipcarg_t * answer5 ){ |
if( answer1 ) * answer1 = arg1; |
if( answer2 ) * answer2 = arg2; |
if( answer3 ) * answer3 = arg3; |
if( answer4 ) * answer4 = arg4; |
if( answer5 ) * answer5 = arg5; |
return EOK; |
} |
int ip_device_message( device_id_t device_id, services_t service ){ |
ERROR_DECLARE; |
ip_netif_ref ip_netif; |
aid_t message; |
ipc_call_t answer; |
measured_string_t configuration[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }}; |
int count = 9; |
measured_string_ref settings; |
char * data; |
ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t )); |
if( ! ip_netif ) return ENOMEM; |
ip_netif->device_id = device_id; |
// get configuration |
// TODO mapping |
message = async_send_2( ip_globals.networking_phone, NET_NET_GET_DEVICE_CONF, ip_netif->device_id, count, & answer ); |
// send names and get settings |
if( ERROR_OCCURED( measured_strings_send( ip_globals.networking_phone, configuration, count )) |
|| ERROR_OCCURED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){ |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
if( settings ){ |
if( settings[ 0 ].value ){ |
ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 ); |
}else{ |
ip_netif->ipv = DEFAULT_IPV; |
} |
ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" ); |
if( ip_netif->dhcp ){ |
// TODO dhcp |
free( ip_netif ); |
return ENOTSUP; |
}else if( ip_netif->ipv == 4 ){ |
if( ERROR_OCCURED( inet_pton( AF_INET, settings[ 2 ].value, ( uint8_t * ) & ip_netif->address )) |
|| ERROR_OCCURED( inet_pton( AF_INET, settings[ 3 ].value, ( uint8_t * ) & ip_netif->netmask )) |
|| ( inet_pton( AF_INET, settings[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL ) |
|| ( inet_pton( AF_INET, settings[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL ) |
|| ( inet_pton( AF_INET, settings[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL ) |
|| ( inet_pton( AF_INET, settings[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){ |
free( ip_netif ); |
return EINVAL; |
} |
}else{ |
// TODO ipv6 |
free( ip_netif ); |
return ENOTSUP; |
} |
// TODO ARP module |
} |
// TODO arp module |
free( settings ); |
free( data ); |
// end request |
// TODO mapping |
async_wait_for( message, NULL ); |
// print the settings |
printf( "\n -IPV =\t%d", ip_netif->ipv ); |
printf( "\n -configuration =\t%s", ip_netif->dhcp ? "dhcp" : "static" ); |
// TODO ipv6 |
data = malloc( INET_ADDRSTRLEN ); |
if( data ){ |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN ); |
printf( "\n -address =\t%s", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN ); |
printf( "\n -netmask =\t%s", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN ); |
printf( "\n -gateway =\t%s", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN ); |
printf( "\n -broadcast =\t%s", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN ); |
printf( "\n -dns1 =\t%s", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN ); |
printf( "\n -dns2 =\t%s", data ); |
free( data ); |
} |
// TODO mapping |
ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver ); |
if( ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){ |
free( ip_netif ); |
return ERROR_CODE; |
} |
return EOK; |
} |
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
ERROR_DECLARE; |
ipc_callid_t callid; |
ipc_call_t call; |
// ipc_call_t answer; |
// int count; |
int result; |
packet_t packet; |
/* |
* Accept the connection |
* - Answer the first IPC_M_CONNECT_ME_TO call. |
*/ |
ipc_answer_0( iid, EOK ); |
while( true ){ |
/* // refresh data |
count = 0; |
IPC_SET_RETVAL( answer, 0 ); |
// just to be precize |
IPC_SET_RETVAL( answer, 0 ); |
IPC_SET_ARG1( answer, 0 ); |
IPC_SET_ARG2( answer, 0 ); |
IPC_SET_ARG3( answer, 0 ); |
IPC_SET_ARG4( answer, 0 ); |
IPC_SET_ARG5( answer, 0 ); |
*/ |
callid = async_get_call( & call ); |
switch( IPC_GET_METHOD( call )){ |
case NET_IL_DEVICE_STATE: |
case NET_NIL_DEVICE_STATE: |
result = ip_state_message( IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call )); |
ipc_answer_0( callid, result ); |
// TODO packer received |
case NET_IL_RECEIVED: |
case NET_NIL_RECEIVED: |
if( ERROR_OCCURED( result = packet_receive( & packet ))){ |
ipc_answer_0( callid, ERROR_CODE ); |
continue; |
} |
//result = ip_receive_message( IPC_GET_DEVICE( call ), packet ); |
packet_destroy( packet ); |
ipc_answer_0( callid, result ); |
} |
} |
} |
int ip_state_message( device_id_t device_id, device_state_t state ){ |
// TODO state |
printf( "\nip - device %d changed state to %d\n", device_id, state ); |
return EOK; |
} |
int ip_register_message( int protocol, int phone ){ |
ERROR_DECLARE; |
ip_proto_ref proto; |
proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t )); |
if( ! proto ) return ENOMEM; |
proto->protocol = protocol; |
proto->phone = phone; |
if( ERROR_OCCURED( ip_protos_add( & ip_globals.protos, proto->protocol, proto ))){ |
free( proto ); |
return ERROR_CODE; |
} |
return EOK; |
} |
int ip_send_message( device_id_t device_id, packet_t packet ){ |
// TODO send packet |
printf( "Packet to send via %d: %s", device_id, packet_get_data( packet )); |
return EOK; |
} |
int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
packet_t packet; |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_IP_ECHO: |
* answer_count = 5; |
return ip_echo_message( IPC_GET_ARG1( * call ), IPC_GET_ARG2( * call ), IPC_GET_ARG3( * call ), IPC_GET_ARG4( * call ), IPC_GET_ARG5( * call ), & IPC_GET_ARG1( * answer ), & IPC_GET_ARG2( * answer ), & IPC_GET_ARG3( * answer ), & IPC_GET_ARG4( * answer ), & IPC_GET_ARG5( * answer ) ); |
case NET_IL_DEVICE: |
return ip_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call )); |
case IPC_M_CONNECT_TO_ME: |
return ip_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
case NET_IP_SEND: |
ERROR_PROPAGATE( packet_receive( & packet )); |
return ip_send_message( IPC_GET_DEVICE( call ), packet ); |
} |
return ENOTSUP; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/Makefile |
---|
0,0 → 1,84 |
# |
# 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. |
# |
NAME = ip |
## Setup toolchain |
# |
LIBC_PREFIX = ../../../../lib/libc |
SOFTINT_PREFIX = ../../../../lib/softint |
include $(LIBC_PREFIX)/Makefile.toolchain |
LIBS = $(LIBC_PREFIX)/libc.a |
## Sources |
# |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME)_module.c \ |
$(NAME).c \ |
../../module.c \ |
../../modules.c \ |
../../structures/measured_strings.c \ |
../../structures/packet/packet.c \ |
../../sockaddr.c |
DEFS += -D IP_BUNDLE=1 -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 |
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/il/ip/ip.h |
---|
0,0 → 1,85 |
/* |
* 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_IP_H__ |
#define __NET_IP_H__ |
#include <ipc/ipc.h> |
#include "../../include/sockaddr.h" |
#include "../../netif/device.h" |
typedef struct ip_netif ip_netif_t; |
typedef ip_netif_t * ip_netif_ref; |
typedef struct ip_proto ip_proto_t; |
typedef ip_proto_t * ip_proto_ref; |
typedef struct ip_globals ip_globals_t; |
DEVICE_MAP_DECLARE( ip_netifs, ip_netif_t ) |
INT_MAP_DECLARE( ip_protos, ip_proto_t ) |
struct ip_netif{ |
device_id_t device_id; |
int phone; |
int ipv; |
int dhcp; |
in_addr_t address; |
in_addr_t netmask; |
in_addr_t gateway; |
in_addr_t broadcast; |
in_addr_t dns1; |
in_addr_t dns2; |
// TODO modules |
}; |
struct ip_proto{ |
int protocol; |
int phone; |
}; |
struct ip_globals{ |
int networking_phone; |
ip_netifs_t netifs; |
ip_protos_t protos; |
}; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip_module.c |
---|
0,0 → 1,75 |
/* |
* 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 "../../err.h" |
#include "../../modules.h" |
#include "ip.h" |
#include "ip_module.h" |
#define NAME "IP protocol" |
void ip_print_name( void ); |
int ip_start_module( async_client_conn_t client_connection ); |
extern ip_globals_t ip_globals; |
void ip_print_name( void ){ |
printf( NAME ); |
} |
int ip_start_module( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
ipcarg_t phonehash; |
async_set_client_connection( client_connection ); |
ip_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
ERROR_PROPAGATE( ip_initialize()); |
ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
async_manager(); |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/netif/lo.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/Makefile |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/netif/device.h |
---|
34,11 → 34,11 |
* @file |
*/ |
#include "../int_map.h" |
#ifndef __NET_DEVICE_ID_TYPE_H__ |
#define __NET_DEVICE_ID_TYPE_H__ |
#include "../structures/int_map.h" |
#define DEVICE_MAP_DECLARE INT_MAP_DECLARE |
#define DEVICE_MAP_IMPLEMENT INT_MAP_IMPLEMENT |
/branches/network/uspace/srv/net/netif/netif.c |
---|
43,8 → 43,9 |
#include "../err.h" |
#include "../messages.h" |
#include "../modules.h" |
#include "../packet.h" |
#include "../structures/packet/packet.h" |
#include "device.h" |
#include "netif.h" |
/branches/network/uspace/srv/net/netif/lo/lo.c |
---|
0,0 → 1,202 |
/* |
* 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 "../../err.h" |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet.h" |
#include "../netif.h" |
#define DEFAULT_MTU 1500 |
#define NAME "lo - loopback interface" |
netif_globals_t netif_globals; |
int change_state_message( device_id_t device_id, device_state_t state ); |
int create( device_id_t device_id, device_ref * device ); |
int initialize( void ); |
void netif_print_name( void ); |
int probe_auto_message( void ); |
int probe_message( device_id_t device_id, int irq, int io ); |
int send_message( device_id_t device_id, packet_t packet ); |
int start_message( device_id_t device_id ); |
int stop_message( device_id_t device_id ); |
int change_state_message( device_id_t device_id, device_state_t state ){ |
ERROR_DECLARE; |
device_ref device; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != state ){ |
device->state = state; |
nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL, NULL, NULL, NULL ); |
} |
return EOK; |
} |
int create( device_id_t device_id, device_ref * device ){ |
ERROR_DECLARE; |
if( device_map_count( & netif_globals.device_map ) > 0 ){ |
return EXDEV; |
}else{ |
* device = ( device_ref ) malloc( sizeof( device_t )); |
if( !( * device )) return ENOMEM; |
( ** device ).device_id = device_id; |
( ** device ).nil_phone = -1; |
( ** device ).specific = NULL; |
null_device_stats( &(( ** device ).stats )); |
( ** device ).state = NETIF_STOPPED; |
( ** device ).flags = NULL; |
( ** device ).mtu = DEFAULT_MTU; |
if( ERROR_OCCURED( device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ))){ |
free( * device ); |
* device = NULL; |
return ERROR_CODE; |
} |
} |
return EOK; |
} |
int initialize( void ){ |
ipcarg_t phonehash; |
return REGISTER_ME( SERVICE_LO, & phonehash ); |
} |
void netif_print_name( void ){ |
printf( NAME ); |
} |
int probe_auto_message( void ){ |
/* ERROR_DECLARE; |
device_ref device; |
ERROR_PROPAGATE( create( arg1, & device )); |
ipc_call_sync_3_3( netif_globals.networking_phone, NET_NET_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
*/ return ENOTSUP; |
} |
int probe_message( device_id_t device_id, int irq, int io ){ |
ERROR_DECLARE; |
device_ref device; |
aid_t message; |
ipc_call_t answer; |
measured_string_t configuration[ 1 ] = {{ "MTU", 3 }}; |
int count = 1; |
measured_string_ref settings; |
char * data; |
// create a new device |
ERROR_PROPAGATE( create( device_id, & device )); |
// get configuration |
message = async_send_2( netif_globals.networking_phone, NET_NET_GET_DEVICE_CONF, device->device_id, count, & answer ); |
// send names and get settings |
if( ERROR_OCCURED( measured_strings_send( netif_globals.networking_phone, configuration, count )) |
|| ERROR_OCCURED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){ |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
// MTU is the first one |
if( settings && ( settings[ 0 ].value )){ |
device->mtu = strtoul( settings[ 0 ].value, NULL, 0 ); |
}else{ |
device->mtu = DEFAULT_MTU; |
} |
// print the settings |
printf("\n -MTU =\t%d", device->mtu ); |
free( settings ); |
free( data ); |
// end request |
async_wait_for( message, NULL ); |
return EOK; |
} |
int send_message( device_id_t device_id, packet_t packet ){ |
ERROR_DECLARE; |
device_ref device; |
size_t length; |
aid_t message; |
ipc_call_t answer; |
ipcarg_t result; |
packet_t received; |
ERROR_PROPAGATE( find_device( device_id, & device )); |
if( device->state != NETIF_ACTIVE ) return EPERM; |
++ device->stats.tx_packets; |
++ device->stats.rx_packets; |
length = packet_get_data_length( packet ); |
device->stats.tx_bytes += length; |
device->stats.rx_bytes += length; |
received = packet_copy( packet ); |
packet_destroy( packet ); |
if( ! received ){ |
++ device->stats.rx_dropped; |
return EOK; |
} |
message = async_send_1( device->nil_phone, NET_NIL_RECEIVED, ( device_id ), & answer ); |
if( ERROR_OCCURED( packet_send( received, device->nil_phone ))){ |
++ device->stats.rx_dropped; |
} |
async_wait_for( message, & result ); |
if( result != EOK ) ++ device->stats.rx_dropped; |
return EOK; |
} |
int start_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_ACTIVE ); |
} |
int stop_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_STOPPED ); |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/netif/lo/Makefile |
---|
0,0 → 1,84 |
# |
# 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 |
SOURCES = \ |
../$(NETIF).c \ |
../../module.c \ |
../../modules.c \ |
../../structures/measured_strings.h \ |
../../structures/packet/packet.c |
DEFS += -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/Makefile |
---|
26,19 → 26,20 |
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
# |
include ../../../Makefile.config |
include ../../Makefile.config |
DIRS = \ |
netif \ |
netif/lo \ |
networking \ |
networking_startup |
networking/startup |
DIRS_MODULAR = ip \ |
tcp \ |
arp \ |
# rarp \ |
# icmp \ |
# udp \ |
DIRS_MODULAR = il/ip \ |
tl/tcp \ |
il/arp \ |
# nil/ethernet \ |
# il/rarp \ |
# il/icmp \ |
# tl/udp \ |
# socket |
DIRS_ALL = $(DIRS) $(DIRS_MODULAR) |