37,9 → 37,9 |
|
#include <async.h> |
#include <malloc.h> |
#include <mem.h> |
#include <rwlock.h> |
#include <stdio.h> |
#include <string.h> |
|
#include <ipc/ipc.h> |
#include <ipc/services.h> |
192,6 → 192,7 |
ipc_call_t answer; |
ipcarg_t result; |
arp_proto_ref proto; |
int index; |
|
rwlock_write_lock( & arp_globals.lock ); |
// an existing device? |
213,14 → 214,17 |
rwlock_write_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
} |
if( ERROR_OCCURRED( arp_protos_add( & device->protos, proto->service, proto ))){ |
index = arp_protos_add( & device->protos, proto->service, proto ); |
if( index < 0 ){ |
rwlock_write_unlock( & arp_globals.lock ); |
free( proto ); |
return ERROR_CODE; |
return result; |
} |
} |
printf( "\nCache of the existing device %d cleaned", device->device_id ); |
}else{ |
index = protocol_map( service, protocol ); |
if( ! index ) return ENOENT; |
// create a new device |
device = ( arp_device_ref ) malloc( sizeof( arp_device_t )); |
if( ! device ){ |
227,6 → 231,7 |
rwlock_write_unlock( & arp_globals.lock ); |
return ENOMEM; |
} |
device->hardware = index; |
device->device_id = device_id; |
if( ERROR_OCCURRED( arp_protos_initialize( & device->protos )) |
|| ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){ |
234,15 → 239,22 |
free( device ); |
return ERROR_CODE; |
} |
if( ERROR_OCCURRED( arp_protos_add( & device->protos, proto->service, proto ))){ |
index = arp_protos_add( & device->protos, proto->service, proto ); |
if( index < 0 ){ |
rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return ERROR_CODE; |
return index; |
} |
device->service = service; |
// bind the new one |
device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver ); |
if( device->phone < 0 ){ |
rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
return EREFUSED; |
} |
// get packet dimensions |
if( ERROR_OCCURRED( async_req_1_4( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){ |
rwlock_write_unlock( & arp_globals.lock ); |
292,7 → 304,7 |
free( device ); |
return ERROR_CODE; |
} |
printf( "\nNew device registered:\n\tid\t= %d\n\ttype\t= %x\n\tservice\t= %d", device->device_id, device->hardware, device->service ); |
printf( "\nNew device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d", device->device_id, device->hardware, device->service ); |
} |
rwlock_write_unlock( & arp_globals.lock ); |
return EOK; |
345,7 → 357,7 |
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 ); |
bzero((( uint8_t * ) header ) + length, device->addr->length ); |
length += device->addr->length; |
memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length )); |
428,7 → 440,7 |
rwlock_read_unlock( & arp_globals.lock ); |
}else{ |
rwlock_read_unlock( & arp_globals.lock ); |
packet_release( arp_globals.networking_phone, packet_get_id( packet )); |
pq_release( arp_globals.networking_phone, packet_get_id( packet )); |
} |
} |
return EOK; |
453,13 → 465,13 |
int count; |
arp_proto_ref proto; |
|
count = arp_protos_count( & device->protos ); |
while( count > 0 ){ |
for( count = arp_protos_count( & device->protos ) - 1; count >= 0; -- count ){ |
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; |
if( proto ){ |
if( proto->addr ) free( proto->addr ); |
if( proto->addr_data ) free( proto->addr_data ); |
arp_addr_destroy( & proto->addresses ); |
} |
} |
arp_protos_clear( & device->protos ); |
} |
469,8 → 481,7 |
arp_device_ref device; |
|
rwlock_write_lock( & arp_globals.lock ); |
count = arp_cache_count( & arp_globals.cache ); |
while( count > 0 ){ |
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 ); |