/branches/network/uspace/srv/net/il/il_messages.h |
---|
0,0 → 1,59 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup net_il |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __NET_IL_MESSAGES_H__ |
#define __NET_IL_MESSAGES_H__ |
#include <ipc/ipc.h> |
typedef enum{ |
/* ( device_id, nil_service ) */ |
NET_IL_DEVICE = NET_IL_FIRST, |
/* ( device_id, state ) */ |
NET_IL_DEVICE_STATE, |
/* ( device_id ), packet_send */ |
NET_IL_RECEIVED, |
/* ( device_id ), measured_strings_send( address ) */ |
// NET_IL_MY_ADDR, |
/* ( packet_id ) */ |
NET_IL_SEND, |
} il_messages; |
#define IL_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * call ) |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/arp_wrappers.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/arp_messages.h |
---|
0,0 → 1,61 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup arp |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __NET_ARP_MESSAGES__ |
#define __NET_ARP_MESSAGES__ |
#include <ipc/ipc.h> |
#include "../../messages.h" |
typedef enum{ |
/* ( device_id, nil_service, proto ), measured_strings_send( proto_addr ) */ |
NET_ARP_DEVICE = NET_ARP_FIRST, |
/* ( device_id, protocol ), measured_strings_send( target ), measured_strings_return( translation ) */ |
NET_ARP_TRANSLATE, |
/* ( device_id ) */ |
NET_ARP_CLEAR_DEVICE, |
/* () */ |
NET_ARP_CLEAN_CACHE, |
} arp_messages; |
/** Returns the protocol service message parameter. |
*/ |
#define ARP_GET_NETIF( call ) ( services_t ) IPC_GET_ARG2( * call ) |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/arp/arp.c |
---|
40,6 → 40,7 |
#include <mem.h> |
#include <rwlock.h> |
#include <stdio.h> |
#include <task.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
50,8 → 51,8 |
#include "../../include/byteorder.h" |
#include "../../include/device.h" |
#include "../../include/arp_messages.h" |
#include "../../include/nil_messages.h" |
#include "../../include/arp_interface.h" |
#include "../../include/nil_interface.h" |
#include "../../include/protocol_map.h" |
#include "../../structures/measured_strings.h" |
58,16 → 59,33 |
#include "../../structures/packet/packet.h" |
#include "../../structures/packet/packet_client.h" |
#include "../il_messages.h" |
#include "arp.h" |
#include "arp_header.h" |
#include "arp_oc.h" |
#include "arp_module.h" |
#include "arp_wrappers.h" |
#include "arp_messages.h" |
/** ARP global data. |
*/ |
arp_globals_t arp_globals; |
int arp_device_req( int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ); |
int arp_translate_req( int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data ); |
/** Clears the whole cache. |
* @returns EOK on success. |
*/ |
int arp_clean_cache_req( int arp_phone ); |
/** Clears the device specific data from the cache. |
* @param device_id The device identifier. Input parameter. |
* @returns EOK on success. |
* @returns ENOENT if the device is not found in the cache. |
*/ |
int arp_clear_device_req( int arp_phone, device_id_t device_id ); |
/** Creates new protocol specific data. |
* @param proto Protocol specific data. Output parameter. |
* @param service Protocol module service. Input parameter. |
134,7 → 152,11 |
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t ) |
int arp_clear_device_wrapper( device_id_t device_id ){ |
int arp_task_get_id( void ){ |
return task_get_id(); |
} |
int arp_clear_device_req( int arp_phone, device_id_t device_id ){ |
arp_device_ref device; |
rwlock_write_lock( & arp_globals.lock ); |
144,12 → 166,12 |
return ENOENT; |
} |
clear_device( device ); |
printf( "\nDevice %d cleared", device_id ); |
printf( "Device %d cleared\n", device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
int arp_clean_cache_wrapper( void ){ |
int arp_clean_cache_req( int arp_phone ){ |
int count; |
arp_device_ref device; |
164,11 → 186,11 |
} |
arp_cache_clear( & arp_globals.cache ); |
rwlock_write_unlock( & arp_globals.lock ); |
printf( "\nCache cleaned" ); |
printf( "Cache cleaned\n" ); |
return EOK; |
} |
int arp_device_wrapper( device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ){ |
int arp_device_req( int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ){ |
ERROR_DECLARE; |
measured_string_ref tmp; |
181,7 → 203,7 |
return ERROR_CODE; |
} |
int arp_translate_wrapper( device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data ){ |
int arp_translate_req( int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data ){ |
measured_string_ref tmp; |
rwlock_read_lock( & arp_globals.lock ); |
238,7 → 260,7 |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( device ){ |
if( device->service != service ){ |
printf( "\nDevice %d already exists", device->device_id ); |
printf( "Device %d already exists\n", device->device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
return EEXIST; |
} |
260,7 → 282,7 |
return index; |
} |
} |
printf( "\nCache of the existing device %d cleaned", device->device_id ); |
printf( "Cache of the existing device %d cleaned\n", device->device_id ); |
}else{ |
index = hardware_map( service ); |
if( ! index ) return ENOENT; |
327,7 → 349,7 |
free( device ); |
return ERROR_CODE; |
} |
printf( "\nNew device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d", device->device_id, device->hardware, device->service ); |
printf( "New device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d\n", device->device_id, device->hardware, device->service ); |
} |
rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
351,7 → 373,7 |
// 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_get_4( arp_globals.networking_phone, device->addr_len, device->prefix, length, device->suffix ); |
packet = packet_get_4( arp_globals.net_phone, device->addr_len, device->prefix, length, device->suffix ); |
if( ! packet ) return NULL; |
header = ( arp_header_ref ) packet_suffix( packet, length ); |
header->hardware = htons( device->hardware ); |
428,7 → 450,7 |
packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
}else{ |
pq_release( arp_globals.networking_phone, packet_get_id( packet )); |
pq_release( arp_globals.net_phone, packet_get_id( packet )); |
} |
} |
return EOK; |
449,6 → 471,10 |
arp_protos_clear( & device->protos ); |
} |
int arp_connect_module( services_t service ){ |
return EOK; |
} |
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
456,7 → 482,7 |
measured_string_ref translation; |
char * data; |
// printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_ARP_FIRST ); |
// printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_ARP_FIRST ); |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
463,7 → 489,7 |
return EOK; |
case NET_ARP_DEVICE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), ARP_GET_PROTO( call ), address ))){ |
if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), ARP_GET_NETIF( call ), address ))){ |
free( address ); |
free( data ); |
} |
471,7 → 497,7 |
case NET_ARP_TRANSLATE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
rwlock_read_lock( & arp_globals.lock ); |
translation = arp_translate_message( IPC_GET_DEVICE( call ), ARP_GET_PROTO( call ), address ); |
translation = arp_translate_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), address ); |
free( address ); |
free( data ); |
if( ! translation ){ |
482,9 → 508,9 |
rwlock_read_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
case NET_ARP_CLEAR_DEVICE: |
return arp_clear_device_wrapper( IPC_GET_DEVICE( call )); |
return arp_clear_device_req( 0, IPC_GET_DEVICE( call )); |
case NET_ARP_CLEAN_CACHE: |
return arp_clean_cache_wrapper(); |
return arp_clean_cache_req( 0 ); |
} |
return ENOTSUP; |
} |
501,7 → 527,7 |
ipc_answer_0( iid, EOK ); |
break; |
case NET_IL_RECEIVED: |
if( ! ERROR_OCCURRED( packet_translate( arp_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){ |
if( ! ERROR_OCCURRED( packet_translate( arp_globals.net_phone, & packet, IPC_GET_PACKET( icall )))){ |
rwlock_read_lock( & arp_globals.lock ); |
ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( icall ), packet ); |
rwlock_read_unlock( & arp_globals.lock ); |
/branches/network/uspace/srv/net/il/arp/arp.h |
---|
160,7 → 160,7 |
struct arp_globals{ |
/** Networking module phone. |
*/ |
int networking_phone; |
int net_phone; |
/** Safety lock. |
*/ |
rwlock_t lock; |
/branches/network/uspace/srv/net/il/arp/arp_module.c |
---|
46,6 → 46,8 |
#include "../../err.h" |
#include "../../modules.h" |
#include "../../include/net_interface.h" |
#include "../../structures/packet/packet.h" |
#include "arp.h" |
58,7 → 60,7 |
/** Prints the module name. |
* @see NAME |
*/ |
void arp_print_name( void ); |
void module_print_name( void ); |
/** Starts the ARP module. |
* Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop. |
67,23 → 69,24 |
* @returns Other error codes as defined for the arp_initialize() function. |
* @returns Other error codes as defined for the REGISTER_ME() macro function. |
*/ |
int arp_start_module( async_client_conn_t client_connection ); |
int module_start( async_client_conn_t client_connection ); |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
/** ARP module global data. |
*/ |
extern arp_globals_t arp_globals; |
void arp_print_name( void ){ |
void module_print_name( void ){ |
printf( "%s", NAME ); |
} |
int arp_start_module( async_client_conn_t client_connection ){ |
int module_start( 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 ); |
arp_globals.net_phone = net_connect_module( SERVICE_NETWORKING ); |
ERROR_PROPAGATE( pm_init()); |
if( ERROR_OCCURRED( arp_initialize()) |
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_ARP, & phonehash ))){ |
97,5 → 100,9 |
return EOK; |
} |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
return arp_message( callid, call, answer, answer_count ); |
} |
/** @} |
*/ |
/branches/network/uspace/srv/net/il/arp/Makefile |
---|
43,8 → 43,9 |
$(STRUCTURES)char_map.c \ |
$(STRUCTURES)measured_strings.c \ |
$(STRUCTURES)packet/packet.c \ |
$(STRUCTURES)packet/packet_client.c |
$(STRUCTURES)/packet/packet_client.c \ |
$(STRUCTURES)/packet/packet_remote.c \ |
$(NET_BASE)nil/nil_remote.c \ |
$(NET_BASE)net/net_remote.c |
NET_DEFS += -D ARP_BUNDLE=1 |
include $(NET_BASE)Makefile.module |
/branches/network/uspace/srv/net/il/arp/arp_remote.c |
---|
0,0 → 1,83 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup arp |
* @{ |
*/ |
/** @file |
*/ |
#include <async.h> |
#include <errno.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../include/device.h" |
#include "../../include/arp_interface.h" |
#include "../../structures/measured_strings.h" |
#include "arp_messages.h" |
int arp_device_req( int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ){ |
aid_t message_id; |
ipcarg_t result; |
message_id = async_send_3( arp_phone, NET_ARP_DEVICE, device_id, protocol, netif, NULL ); |
measured_strings_send( arp_phone, address, 1 ); |
async_wait_for( message_id, & result ); |
return result; |
} |
int arp_translate_req( int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data ){ |
return generic_translate_req( arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data ); |
} |
int arp_clear_device_req( int arp_phone, device_id_t device_id ){ |
return async_req_1_0( arp_phone, NET_ARP_CLEAR_DEVICE, device_id ); |
} |
int arp_clean_cache_req( int arp_phone ){ |
return async_req_0_0( arp_phone, NET_ARP_CLEAN_CACHE ); |
} |
int arp_connect_module( services_t service ){ |
return connect_to_service( SERVICE_ARP ); |
} |
int arp_task_get_id( void ){ |
return 0; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip_messages.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip_remote.c |
---|
0,0 → 1,67 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup ip |
* @{ |
*/ |
/** @file |
*/ |
#include <ipc/services.h> |
#include <ipc/services.h> |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../include/device.h" |
#include "../../include/ip_interface.h" |
#include "../../structures/packet/packet_client.h" |
#include "../il_messages.h" |
int ip_bind_service( services_t service, services_t me, async_client_conn_t receiver ){ |
return bind_service( service, 0, me, 0, receiver ); |
} |
int ip_device_req( int ip_phone, device_id_t device_id, services_t service ){ |
return generic_device_req( ip_phone, NET_IL_DEVICE, device_id, 0, service ); |
} |
int ip_send_msg( int ip_phone, device_id_t device_id, packet_t packet, services_t sender ){ |
return generic_send_msg( ip_phone, NET_IL_SEND, -1, packet_get_id( packet ), sender ); |
} |
int ip_connect_module( services_t service ){ |
return connect_to_service( SERVICE_IP ); |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/il/ip/ip.c |
---|
44,17 → 44,23 |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../include/net_interface.h" |
#include "../../include/sockaddr.h" |
#include "../../include/socket.h" |
#include "../../include/device.h" |
#include "../../include/arp_messages.h" |
#include "../../include/nil_messages.h" |
#include "../../include/arp_interface.h" |
#include "../../include/nil_interface.h" |
#include "../../include/il_interface.h" |
#include "../../include/ip_interface.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/module_map.h" |
#include "../../structures/packet/packet_client.h" |
#include "../../nil/nil_messages.h" |
#include "../il_messages.h" |
#include "ip.h" |
#include "ip_messages.h" |
#include "ip_module.h" |
#define DEFAULT_IPV 4 |
62,10 → 68,6 |
#define ARP_NAME "arp" |
#define ARP_FILENAME "/srv/arp" |
#define IPC_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * 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 ) |
72,9 → 74,9 |
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 ); |
int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ); |
int ip_register( int il_phone, int protocol, int phone ); |
/** Initializes the module. |
*/ |
84,92 → 86,60 |
ERROR_PROPAGATE( ip_netifs_initialize( & ip_globals.netifs )); |
ERROR_PROPAGATE( ip_protos_initialize( & ip_globals.protos )); |
ERROR_PROPAGATE( modules_initialize( & ip_globals.modules )); |
ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, 0 )); |
ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, arp_task_get_id(), arp_connect_module )); |
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 ){ |
int ip_device_req( int il_phone, 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; |
ipcarg_t result; |
int index; |
ip_netif_ref ip_netif; |
measured_string_t names[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }}; |
measured_string_ref configuration; |
int count = 9; |
char * data; |
int index; |
configuration = & names[ 0 ]; |
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_OCCURRED( measured_strings_send( ip_globals.networking_phone, configuration, count )) |
|| ERROR_OCCURRED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){ |
async_wait_for( message, NULL ); |
free( ip_netif ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
if( ERROR_OCCURRED( result )){ |
if( settings ){ |
free( settings ); |
free( data ); |
}; |
free( ip_netif ); |
return ERROR_CODE; |
} |
if( settings ){ |
if( settings[ 0 ].value ){ |
ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 ); |
ERROR_PROPAGATE( net_get_device_conf_req( ip_globals.net_phone, ip_netif->device_id, & configuration, count, & data )); |
if( configuration ){ |
if( configuration[ 0 ].value ){ |
ip_netif->ipv = strtol( configuration[ 0 ].value, NULL, 0 ); |
}else{ |
ip_netif->ipv = DEFAULT_IPV; |
} |
ip_netif->dhcp = ! strncmp( settings[ 1 ].value, "dhcp", 4 ); |
ip_netif->dhcp = ! strncmp( configuration[ 1 ].value, "dhcp", 4 ); |
if( ip_netif->dhcp ){ |
// TODO dhcp |
free( settings ); |
free( data ); |
net_free_settings( configuration, data ); |
free( ip_netif ); |
return ENOTSUP; |
}else if( ip_netif->ipv == 4 ){ |
if( ERROR_OCCURRED( inet_pton( AF_INET, settings[ 2 ].value, ( uint8_t * ) & ip_netif->address )) |
|| ERROR_OCCURRED( 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( settings ); |
free( data ); |
if( ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 2 ].value, ( uint8_t * ) & ip_netif->address )) |
|| ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 3 ].value, ( uint8_t * ) & ip_netif->netmask )) |
|| ( inet_pton( AF_INET, configuration[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL ) |
|| ( inet_pton( AF_INET, configuration[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL ) |
|| ( inet_pton( AF_INET, configuration[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL ) |
|| ( inet_pton( AF_INET, configuration[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){ |
net_free_settings( configuration, data ); |
free( ip_netif ); |
return EINVAL; |
} |
}else{ |
// TODO ipv6 |
free( settings ); |
free( data ); |
net_free_settings( configuration, data ); |
free( ip_netif ); |
return ENOTSUP; |
} |
if( settings[ 8 ].value ){ |
ip_netif->arp = get_running_module( & ip_globals.modules, settings[ 8 ].value ); |
if( configuration[ 8 ].value ){ |
ip_netif->arp = get_running_module( & ip_globals.modules, configuration[ 8 ].value ); |
if( ! ip_netif->arp ){ |
printf( "\nFailed to start the arp %s", settings[ 8 ].value ); |
free( settings ); |
free( data ); |
printf( "Failed to start the arp %s\n", configuration[ 8 ].value ); |
net_free_settings( configuration, data ); |
free( ip_netif ); |
return EINVAL; |
} |
176,12 → 146,11 |
}else{ |
ip_netif->arp = NULL; |
} |
free( settings ); |
free( data ); |
net_free_settings( configuration, data ); |
} |
ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver ); |
if( ip_netif->phone < 0 ){ |
printf( "\nFailed to contact the nil service %d", service ); |
printf( "Failed to contact the nil service %d\n", service ); |
free( ip_netif ); |
return ip_netif->phone; |
} |
200,23 → 169,23 |
} |
if( ip_netif->arp ) ++ ip_netif->arp->usage; |
// print the settings |
printf( "\nNew device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d", ip_netif->device_id, ip_netif->phone, ip_netif->ipv ); |
printf( "\n\tconfiguration\t= %s", ip_netif->dhcp ? "dhcp" : "static" ); |
printf( "New device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d\n", ip_netif->device_id, ip_netif->phone, ip_netif->ipv ); |
printf( "\tconfiguration\t= %s\n", ip_netif->dhcp ? "dhcp" : "static" ); |
// TODO ipv6 addresses |
data = malloc( INET_ADDRSTRLEN ); |
if( data ){ |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN ); |
printf( "\n\taddress\t= %s", data ); |
printf( "\taddress\t= %s\n", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN ); |
printf( "\n\tnetmask\t= %s", data ); |
printf( "\tnetmask\t= %s\n", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN ); |
printf( "\n\tgateway\t= %s", data ); |
printf( "\tgateway\t= %s\n", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN ); |
printf( "\n\tbroadcast\t= %s", data ); |
printf( "\tbroadcast\t= %s\n", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN ); |
printf( "\n\tdns1\t= %s", data ); |
printf( "\tdns1\t= %s\n", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN ); |
printf( "\n\tdns2\t= %s", data ); |
printf( "\tdns2\t= %s\n", data ); |
free( data ); |
} |
return EOK; |
254,20 → 223,22 |
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 )); |
result = ip_device_state_msg( 0, IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call )); |
ipc_answer_0( callid, result ); |
break; |
// TODO packer received |
case NET_IL_RECEIVED: |
case NET_NIL_RECEIVED: |
if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( & call )))){ |
//result = ip_receive_message( IPC_GET_DEVICE( call ), packet ); |
if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( & call )))){ |
//result = il_receive_msg( 0, IPC_GET_DEVICE( call ), packet ); |
} |
ipc_answer_0( callid, result ); |
break; |
} |
} |
} |
int ip_state_message( device_id_t device_id, device_state_t state ){ |
int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){ |
ERROR_DECLARE; |
ip_netif_ref netif; |
279,12 → 250,12 |
netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
if( ! netif ) return ENOENT; |
// TODO state |
printf( "\nip - device %d changed state to %d\n", device_id, state ); |
printf( "ip - device %d changed state to %d\n\n", device_id, state ); |
if( netif->arp ){ |
address.value = ( char * ) & netif->gateway; |
address.length = CONVERT_SIZE( in_addr_t, char, 1 ); |
ERROR_PROPAGATE( arp_translate_req( netif->arp->phone, netif->device_id, SERVICE_IP, & address, & translation, & data )); |
printf( "\n\tgateway translated to\t= %X:%X:%X:%X:%X:%X", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
printf( "\tgateway translated to\t= %X:%X:%X:%X:%X:%X\n", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
free( translation ); |
free( data ); |
} |
291,7 → 262,16 |
return EOK; |
} |
int ip_register_message( int protocol, int phone ){ |
int ip_bind_service( services_t service, services_t me, async_client_conn_t receiver ){ |
//TODO receive function |
return EOK; |
} |
int ip_connect_module( services_t service ){ |
return EOK; |
} |
int ip_register( int il_phone, int protocol, int phone ){ |
ip_proto_ref proto; |
int index; |
304,14 → 284,14 |
free( proto ); |
return index; |
} |
printf( "\nNew protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d", proto->protocol, proto->phone ); |
printf( "New protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d\n", proto->protocol, proto->phone ); |
return EOK; |
} |
int ip_send_message( device_id_t device_id, packet_t packet ){ |
int ip_send_msg( int il_phone, device_id_t device_id, packet_t packet, services_t target ){ |
// TODO send packet |
printf( "Packet to send via %d: %s", device_id, packet_get_data( packet )); |
pq_release( ip_globals.networking_phone, packet_get_id( packet )); |
printf( "Packet to send via %d: %s\n", device_id, packet_get_data( packet )); |
pq_release( ip_globals.net_phone, packet_get_id( packet )); |
return EOK; |
} |
324,16 → 304,13 |
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 )); |
return ip_device_req( 0, 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_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
return ip_send_message( IPC_GET_DEVICE( call ), packet ); |
return ip_register( 0, IL_GET_PROTO( call ), IPC_GET_PHONE( call )); |
case NET_IL_SEND: |
ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
return ip_send_msg( 0, IPC_GET_DEVICE( call ), packet, 0 ); |
} |
return ENOTSUP; |
} |
/branches/network/uspace/srv/net/il/ip/Makefile |
---|
31,6 → 31,9 |
NET_BASE = ../../ |
STRUCTURES = $(NET_BASE)structures/ |
## Sources |
# |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME)_module.c \ |
41,9 → 44,11 |
$(STRUCTURES)measured_strings.c \ |
$(STRUCTURES)module_map.c \ |
$(STRUCTURES)packet/packet.c \ |
$(STRUCTURES)packet/packet_client.c \ |
$(NET_BASE)sockaddr.c |
$(STRUCTURES)/packet/packet_client.c \ |
$(NET_BASE)sockaddr.c \ |
$(STRUCTURES)/packet/packet_remote.c \ |
$(NET_BASE)il/arp/arp_remote.c \ |
$(NET_BASE)nil/nil_remote.c \ |
$(NET_BASE)net/net_remote.c |
NET_DEFS += -D IP_BUNDLE=1 |
include $(NET_BASE)Makefile.module |
/branches/network/uspace/srv/net/il/ip/ip.h |
---|
77,7 → 77,7 |
}; |
struct ip_globals{ |
int networking_phone; |
int net_phone; |
ip_netifs_t netifs; |
ip_protos_t protos; |
modules_t modules; |
/branches/network/uspace/srv/net/il/ip/ip_module.c |
---|
42,6 → 42,8 |
#include "../../err.h" |
#include "../../modules.h" |
#include "../../include/net_interface.h" |
#include "../../structures/packet/packet.h" |
#include "ip.h" |
49,22 → 51,23 |
#define NAME "IP protocol" |
void ip_print_name( void ); |
int ip_start_module( async_client_conn_t client_connection ); |
void module_print_name( void ); |
int module_start( async_client_conn_t client_connection ); |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
extern ip_globals_t ip_globals; |
void ip_print_name( void ){ |
void module_print_name( void ){ |
printf( "%s", NAME ); |
} |
int ip_start_module( async_client_conn_t client_connection ){ |
int module_start( 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 ); |
ip_globals.net_phone = net_connect_module( SERVICE_NETWORKING ); |
ERROR_PROPAGATE( pm_init()); |
if( ERROR_OCCURRED( ip_initialize()) |
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_IP, & phonehash ))){ |
78,5 → 81,9 |
return EOK; |
} |
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
return ip_message( callid, call, answer, answer_count ); |
} |
/** @} |
*/ |