50,6 → 50,7 |
|
#include "../../include/byteorder.h" |
#include "../../include/device.h" |
#include "../../include/arp_messages.h" |
#include "../../include/nil_messages.h" |
#include "../../include/protocol_map.h" |
|
60,13 → 61,9 |
#include "arp.h" |
#include "arp_header.h" |
#include "arp_oc.h" |
//#include "arp_messages.h" |
#include "arp_module.h" |
#include "arp_wrappers.h" |
|
/** Returns the protocol service message parameter. |
*/ |
#define ARP_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
|
/** ARP global data. |
*/ |
arp_globals_t arp_globals; |
120,23 → 117,11 |
*/ |
int arp_receive_message( device_id_t device_id, packet_t packet ); |
|
/** 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_message( device_id_t device_id ); |
|
/** Clears the device specific data. |
* @param device The device specific data. |
*/ |
void clear_device( arp_device_ref device ); |
|
/** Clears the whole cache. |
* @returns EOK on success. |
*/ |
int arp_clean_cache_message( void ); |
|
/** Processes IPC messages from the registered device driver modules in an infinite loop. |
* @param iid The message identifier. Input parameter. |
* @param icall The message parameters. Input/output parameter. |
149,6 → 134,73 |
|
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t ) |
|
int arp_clear_device_wrapper( device_id_t device_id ){ |
arp_device_ref device; |
|
rwlock_write_lock( & arp_globals.lock ); |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ){ |
rwlock_write_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
clear_device( device ); |
printf( "\nDevice %d cleared", device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
|
int arp_clean_cache_wrapper( void ){ |
int count; |
arp_device_ref device; |
|
rwlock_write_lock( & arp_globals.lock ); |
for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){ |
device = arp_cache_get_index( & arp_globals.cache, count ); |
if( device ){ |
clear_device( device ); |
if( device->addr_data ) free( device->addr_data ); |
if( device->broadcast_data ) free( device->broadcast_data ); |
} |
} |
arp_cache_clear( & arp_globals.cache ); |
rwlock_write_unlock( & arp_globals.lock ); |
printf( "\nCache cleaned" ); |
return EOK; |
} |
|
int arp_device_wrapper( device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ){ |
ERROR_DECLARE; |
|
measured_string_ref tmp; |
|
tmp = measured_string_copy( address ); |
if( ERROR_OCCURRED( arp_device_message( device_id, netif, protocol, tmp ))){ |
free( tmp->value ); |
free( tmp ); |
} |
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 ){ |
measured_string_ref tmp; |
|
rwlock_read_lock( & arp_globals.lock ); |
tmp = arp_translate_message( device_id, protocol, address ); |
if( tmp ){ |
* translation = measured_string_copy( tmp ); |
rwlock_read_unlock( & arp_globals.lock ); |
if( * translation ){ |
* data = ( ** translation ).value; |
return EOK; |
}else{ |
return ENOMEM; |
} |
}else{ |
rwlock_read_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
} |
|
int arp_initialize( void ){ |
ERROR_DECLARE; |
|
382,21 → 434,6 |
return EOK; |
} |
|
int arp_clear_device_message( device_id_t device_id ){ |
arp_device_ref device; |
|
rwlock_write_lock( & arp_globals.lock ); |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ){ |
rwlock_write_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
clear_device( device ); |
printf( "\nDevice %d cleared", device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
|
void clear_device( arp_device_ref device ){ |
int count; |
arp_proto_ref proto; |
412,25 → 449,6 |
arp_protos_clear( & device->protos ); |
} |
|
int arp_clean_cache_message( void ){ |
int count; |
arp_device_ref device; |
|
rwlock_write_lock( & arp_globals.lock ); |
for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){ |
device = arp_cache_get_index( & arp_globals.cache, count ); |
if( device ){ |
clear_device( device ); |
if( device->addr_data ) free( device->addr_data ); |
if( device->broadcast_data ) free( device->broadcast_data ); |
} |
} |
arp_cache_clear( & arp_globals.cache ); |
rwlock_write_unlock( & arp_globals.lock ); |
printf( "\nCache cleaned" ); |
return EOK; |
} |
|
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
|
464,9 → 482,9 |
rwlock_read_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
case NET_ARP_CLEAR_DEVICE: |
return arp_clear_device_message( IPC_GET_DEVICE( call )); |
return arp_clear_device_wrapper( IPC_GET_DEVICE( call )); |
case NET_ARP_CLEAN_CACHE: |
return arp_clean_cache_message(); |
return arp_clean_cache_wrapper(); |
} |
return ENOTSUP; |
} |