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 ); |