Subversion Repositories HelenOS

Rev

Rev 4501 | Rev 4582 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4501 Rev 4558
Line 234... Line 234...
234
    ERROR_DECLARE;
234
    ERROR_DECLARE;
235
 
235
 
236
    arp_device_ref  device;
236
    arp_device_ref  device;
237
    arp_proto_ref   proto;
237
    arp_proto_ref   proto;
238
    int             index;
238
    int             index;
-
 
239
    hw_type_t       hardware;
239
 
240
 
240
    rwlock_write_lock( & arp_globals.lock );
241
    rwlock_write_lock( & arp_globals.lock );
241
    // an existing device?
242
    // an existing device?
242
    device = arp_cache_find( & arp_globals.cache, device_id );
243
    device = arp_cache_find( & arp_globals.cache, device_id );
243
    if( device ){
244
    if( device ){
Line 264... Line 265...
264
                return index;
265
                return index;
265
            }
266
            }
266
            printf( "New protocol added:\n\tdevice id\t= %d\n\tproto\t= %d", device_id, protocol );
267
            printf( "New protocol added:\n\tdevice id\t= %d\n\tproto\t= %d", device_id, protocol );
267
        }
268
        }
268
    }else{
269
    }else{
269
        index = hardware_map( service );
270
        hardware = hardware_map( service );
270
        if( ! index ) return ENOENT;
271
        if( ! hardware ) return ENOENT;
271
        // create a new device
272
        // create a new device
272
        device = ( arp_device_ref ) malloc( sizeof( arp_device_t ));
273
        device = ( arp_device_ref ) malloc( sizeof( arp_device_t ));
273
        if( ! device ){
274
        if( ! device ){
274
            rwlock_write_unlock( & arp_globals.lock );
275
            rwlock_write_unlock( & arp_globals.lock );
275
            return ENOMEM;
276
            return ENOMEM;
276
        }
277
        }
277
        device->hardware = index;
278
        device->hardware = hardware;
278
        device->device_id = device_id;
279
        device->device_id = device_id;
279
        if( ERROR_OCCURRED( arp_protos_initialize( & device->protos ))
280
        if( ERROR_OCCURRED( arp_protos_initialize( & device->protos ))
280
        || ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){
281
        || ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){
281
            rwlock_write_unlock( & arp_globals.lock );
282
            rwlock_write_unlock( & arp_globals.lock );
282
            free( device );
283
            free( device );
Line 289... Line 290...
289
            free( device );
290
            free( device );
290
            return index;
291
            return index;
291
        }
292
        }
292
        device->service = service;
293
        device->service = service;
293
        // bind the new one
294
        // bind the new one
294
        device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_globals.client_connection );
295
        device->phone = bind_service( device->service, ( ipcarg_t ) device->device_id, SERVICE_ARP, 0, arp_globals.client_connection );
295
        if( device->phone < 0 ){
296
        if( device->phone < 0 ){
296
            rwlock_write_unlock( & arp_globals.lock );
297
            rwlock_write_unlock( & arp_globals.lock );
297
            arp_protos_destroy( & device->protos );
298
            arp_protos_destroy( & device->protos );
298
            free( device );
299
            free( device );
299
            return EREFUSED;
300
            return EREFUSED;
Line 361... Line 362...
361
    if( ! header ){
362
    if( ! header ){
362
        pq_release( arp_globals.net_phone, packet_get_id( packet ));
363
        pq_release( arp_globals.net_phone, packet_get_id( packet ));
363
        return NULL;
364
        return NULL;
364
    }
365
    }
365
    header->hardware = htons( device->hardware );
366
    header->hardware = htons( device->hardware );
366
    header->hardware_length = device->addr->length;
367
    header->hardware_length = ( uint8_t ) device->addr->length;
367
    header->protocol = htons( protocol_map( device->service, protocol ));
368
    header->protocol = htons( protocol_map( device->service, protocol ));
368
    header->protocol_length = proto->addr->length;
369
    header->protocol_length = ( uint8_t ) proto->addr->length;
369
    header->operation = htons( ARPOP_REQUEST );
370
    header->operation = htons( ARPOP_REQUEST );
370
    length = sizeof( arp_header_t );
371
    length = sizeof( arp_header_t );
371
    memcpy((( uint8_t * ) header ) + length, device->addr->value, device->addr->length );
372
    memcpy((( uint8_t * ) header ) + length, device->addr->value, device->addr->length );
372
    length += device->addr->length;
373
    length += device->addr->length;
373
    memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length );
374
    memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length );
Line 400... Line 401...
400
    if( length <= sizeof( arp_header_t )) return EINVAL;
401
    if( length <= sizeof( arp_header_t )) return EINVAL;
401
    device = arp_cache_find( & arp_globals.cache, device_id );
402
    device = arp_cache_find( & arp_globals.cache, device_id );
402
    if( ! device ) return ENOENT;
403
    if( ! device ) return ENOENT;
403
    header = ( arp_header_ref ) packet_get_data( packet );
404
    header = ( arp_header_ref ) packet_get_data( packet );
404
    if(( ntohs( header->hardware ) != device->hardware )
405
    if(( ntohs( header->hardware ) != device->hardware )
-
 
406
    // TODO how remove conversion from int '2' to uint?
405
    || ( length < sizeof( arp_header_t ) + ( header->hardware_length + header->protocol_length ) * 2 )){
407
    || ( length < sizeof( arp_header_t ) + ( header->hardware_length + header->protocol_length ) * 2u )){
406
        return EINVAL;
408
        return EINVAL;
407
    }
409
    }
408
    proto = arp_protos_find( & device->protos, protocol_unmap( device->service, ntohs( header->protocol )));
410
    proto = arp_protos_find( & device->protos, protocol_unmap( device->service, ntohs( header->protocol )));
409
    if( ! proto ) return ENOENT;
411
    if( ! proto ) return ENOENT;
410
    src_hw = (( uint8_t * ) header ) + sizeof( arp_header_t );
412
    src_hw = (( uint8_t * ) header ) + sizeof( arp_header_t );