38,7 → 38,7 |
#include <async.h> |
#include <malloc.h> |
#include <mem.h> |
#include <rwlock.h> |
#include <fibril_sync.h> |
#include <stdio.h> |
#include <string.h> |
#include <task.h> |
140,15 → 140,15 |
int arp_clear_device_req( int arp_phone, device_id_t device_id ){ |
arp_device_ref device; |
|
rwlock_write_lock( & arp_globals.lock ); |
fibril_rwlock_write_lock( & arp_globals.lock ); |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
clear_device( device ); |
printf( "Device %d cleared\n", device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
|
156,7 → 156,7 |
int count; |
arp_device_ref device; |
|
rwlock_write_lock( & arp_globals.lock ); |
fibril_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 ){ |
166,7 → 166,7 |
} |
} |
arp_cache_clear( & arp_globals.cache ); |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
printf( "Cache cleaned\n" ); |
return EOK; |
} |
187,11 → 187,11 |
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 ); |
fibril_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 ); |
fibril_rwlock_read_unlock( & arp_globals.lock ); |
if( * translation ){ |
* data = ( ** translation ).value; |
return EOK; |
199,7 → 199,7 |
return ENOMEM; |
} |
}else{ |
rwlock_read_unlock( & arp_globals.lock ); |
fibril_rwlock_read_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
} |
207,11 → 207,11 |
int arp_initialize( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
|
rwlock_initialize( & arp_globals.lock ); |
rwlock_write_lock( & arp_globals.lock ); |
fibril_rwlock_initialize( & arp_globals.lock ); |
fibril_rwlock_write_lock( & arp_globals.lock ); |
arp_globals.client_connection = client_connection; |
ERROR_PROPAGATE( arp_cache_initialize( & arp_globals.cache )); |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
|
238,13 → 238,13 |
int index; |
hw_type_t hardware; |
|
rwlock_write_lock( & arp_globals.lock ); |
fibril_rwlock_write_lock( & arp_globals.lock ); |
// an existing device? |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( device ){ |
if( device->service != service ){ |
printf( "Device %d already exists\n", device->device_id ); |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
return EEXIST; |
} |
proto = arp_protos_find( & device->protos, protocol ); |
255,12 → 255,12 |
proto->addr_data = address->value; |
}else{ |
if( ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
} |
index = arp_protos_add( & device->protos, proto->service, proto ); |
if( index < 0 ){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
free( proto ); |
return index; |
} |
272,7 → 272,7 |
// create a new device |
device = ( arp_device_ref ) malloc( sizeof( arp_device_t )); |
if( ! device ){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
return ENOMEM; |
} |
device->hardware = hardware; |
279,13 → 279,13 |
device->device_id = device_id; |
if( ERROR_OCCURRED( arp_protos_initialize( & device->protos )) |
|| ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
free( device ); |
return ERROR_CODE; |
} |
index = arp_protos_add( & device->protos, proto->service, proto ); |
if( index < 0 ){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return index; |
294,7 → 294,7 |
// bind the new one |
device->phone = bind_service( device->service, ( ipcarg_t ) device->device_id, SERVICE_ARP, 0, arp_globals.client_connection ); |
if( device->phone < 0 ){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return EREFUSED; |
301,7 → 301,7 |
} |
// get packet dimensions |
if( ERROR_OCCURRED( nil_packet_size_req( device->phone, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
308,7 → 308,7 |
} |
// get hardware address |
if( ERROR_OCCURRED( nil_get_addr( device->phone, device_id, & device->addr, & device->addr_data ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
315,7 → 315,7 |
} |
// get broadcast address |
if( ERROR_OCCURRED( nil_get_broadcast_addr( device->phone, device_id, & device->broadcast_addr, & device->broadcast_data ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
free( device->addr ); |
free( device->addr_data ); |
arp_protos_destroy( & device->protos ); |
323,7 → 323,7 |
return ERROR_CODE; |
} |
if( ERROR_OCCURRED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
free( device->addr ); |
free( device->addr_data ); |
free( device->broadcast_addr ); |
334,7 → 334,7 |
} |
printf( "New device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d\n\tproto\t= %d\n", device->device_id, device->hardware, device->service, protocol ); |
} |
rwlock_write_unlock( & arp_globals.lock ); |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
} |
|
488,16 → 488,16 |
return ERROR_CODE; |
case NET_ARP_TRANSLATE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
rwlock_read_lock( & arp_globals.lock ); |
fibril_rwlock_read_lock( & arp_globals.lock ); |
translation = arp_translate_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), address ); |
free( address ); |
free( data ); |
if( ! translation ){ |
rwlock_read_unlock( & arp_globals.lock ); |
fibril_rwlock_read_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
ERROR_CODE = measured_strings_reply( translation, 1 ); |
rwlock_read_unlock( & arp_globals.lock ); |
fibril_rwlock_read_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
case NET_ARP_CLEAR_DEVICE: |
return arp_clear_device_req( 0, IPC_GET_DEVICE( call )); |
508,7 → 508,7 |
return EOK; |
case NET_IL_RECEIVED: |
if( ! ERROR_OCCURRED( packet_translate( arp_globals.net_phone, & packet, IPC_GET_PACKET( call )))){ |
rwlock_read_lock( & arp_globals.lock ); |
fibril_rwlock_read_lock( & arp_globals.lock ); |
do{ |
next = pq_detach( packet ); |
ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( call ), packet ); |
515,7 → 515,7 |
if( ERROR_CODE != 1 ) pq_release( arp_globals.net_phone, packet_get_id( packet )); |
packet = next; |
}while( packet ); |
rwlock_read_unlock( & arp_globals.lock ); |
fibril_rwlock_read_unlock( & arp_globals.lock ); |
} |
return ERROR_CODE; |
} |