Subversion Repositories HelenOS

Rev

Rev 3912 | Rev 4163 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3846 mejdrech 1
/*
3912 mejdrech 2
 * Copyright (c) 2009 Lukas Mejdrech
3846 mejdrech 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup arp
30
 *  @{
31
 */
32
 
33
/** @file
3912 mejdrech 34
 *  ARP module implementation.
35
 *  @see arp.h
3846 mejdrech 36
 */
37
 
38
#include <async.h>
39
#include <malloc.h>
3991 mejdrech 40
#include <rwlock.h>
3846 mejdrech 41
#include <stdio.h>
42
#include <string.h>
43
 
44
#include <ipc/ipc.h>
45
#include <ipc/services.h>
46
 
3886 mejdrech 47
#include "../../err.h"
48
#include "../../messages.h"
49
#include "../../modules.h"
3846 mejdrech 50
 
3886 mejdrech 51
#include "../../include/protocol_map.h"
52
#include "../../netif/device.h"
3846 mejdrech 53
 
3886 mejdrech 54
#include "../../structures/measured_strings.h"
55
#include "../../structures/packet/packet.h"
3901 mejdrech 56
#include "../../structures/packet/packet_client.h"
3886 mejdrech 57
 
3846 mejdrech 58
#include "arp.h"
59
#include "arp_header.h"
60
#include "arp_oc.h"
61
//#include "arp_messages.h"
62
#include "arp_module.h"
63
 
3912 mejdrech 64
/** Returns the device identifier message parameter.
65
 */
3846 mejdrech 66
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
3912 mejdrech 67
 
68
/** Returns the packet identifier message parameter.
69
 */
3901 mejdrech 70
#define IPC_GET_PACKET( call )      ( packet_id_t ) IPC_GET_ARG2( * call )
3912 mejdrech 71
 
72
/** Returns the protocol service message parameter.
73
 */
3846 mejdrech 74
#define IPC_GET_PROTO( call )       ( services_t ) IPC_GET_ARG2( * call )
3912 mejdrech 75
 
76
/** Returns the device driver service message parameter.
77
 */
3846 mejdrech 78
#define IPC_GET_SERVICE( call )     ( services_t ) IPC_GET_ARG3( * call )
79
 
3912 mejdrech 80
/** ARP global data.
81
 */
3846 mejdrech 82
arp_globals_t   arp_globals;
83
 
3912 mejdrech 84
/** Creates new protocol specific data.
85
 *  @param proto Protocol specific data. Output parameter.
86
 *  @param service Protocol module service. Input parameter.
87
 *  @param address Actual protocol device address. Input parameter.
88
 *  @returns EOK on success.
89
 *  @returns ENOMEM if there is not enough memory left.
90
 */
91
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address );
92
 
93
/** Registers the device.
94
 *  Creates new device entry in the cache or updates the protocol address if the device with the device identifier and the driver service exists.
95
 *  @param device_id The device identifier. Input parameter.
96
 *  @param service The device driver service. Input parameter.
97
 *  @param protocol The protocol service. Input parameter.
98
 *  @param address The actual device protocol address.
99
 *  @returns EOK on success.
100
 *  @returns EEXIST if another device with the same device identifier and different driver service exists.
101
 *  @returns ENOMEM if there is not enough memory left.
102
 *  @returns Other error codes as defined for the measured_strings_return() function.
103
 */
104
int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address );
105
 
106
/** Returns the hardware address for the given protocol address.
107
 *  Sends the ARP request packet if the hardware address is not found in the cache.
108
 *  @param device_id The device identifier. Input parameter.
109
 *  @param protocol The protocol service. Input parameter.
110
 *  @param target The target protocol address. Input parameter.
111
 *  @returns The hardware address of the target.
112
 *  @returns NULL if the target parameter is NULL.
113
 *  @returns NULL if the device is not found.
114
 *  @returns NULL if the device packet is too small to send a&nbsp;request.
115
 *  @returns NULL if the hardware address is not found in the cache.
116
 */
117
measured_string_ref arp_translate_message( device_id_t device_id, services_t protocol, measured_string_ref target );
118
 
119
/** Processes the received ARP packet.
120
 *  Updates the source hardware address if the source entry exists or the packet is targeted to my protocol address.
121
 *  Responses to the ARP request if the packet is the ARP request and is targeted to my address.
122
 *  @param device_id The source device identifier. Input parameter.
123
 *  @param packet The received packet. Input/output parameter.
124
 *  @returns EOK on success.
125
 *  @returns EINVAL if the packet is too small to carry the ARP packet.
126
 *  @returns EINVAL if the received address lengths differs from the registered values.
127
 *  @returns ENOENT if the device is not found in the cache.
128
 *  @returns ENOENT if the protocol for the device is not found in the cache.
129
 *  @returns ENOMEM if there is not enough memory left.
130
 */
131
int arp_receive_message( device_id_t device_id, packet_t packet );
132
 
133
/** Clears the device specific data from the cache.
134
 *  @param device_id The device identifier. Input parameter.
135
 *  @returns EOK on success.
136
 *  @returns ENOENT  if the device is not found in the cache.
137
 */
138
int arp_clear_device_message( device_id_t device_id );
139
 
140
/** Clears the device specific data.
141
 *  @param device The device specific data.
142
 */
143
void    clear_device( arp_device_ref device );
144
 
145
/** Clears the whole cache.
146
 *  @returns EOK on success.
147
 */
148
int arp_clean_cache_message( void );
149
 
150
/** Processes IPC messages from the registered device driver modules in an infinite loop.
151
 *  @param iid The message identifier. Input parameter.
152
 *  @param icall The message parameters. Input/output parameter.
153
 */
154
void    arp_receiver( ipc_callid_t iid, ipc_call_t * icall );
155
 
3846 mejdrech 156
DEVICE_MAP_IMPLEMENT( arp_cache, arp_device_t )
157
 
158
INT_MAP_IMPLEMENT( arp_protos, arp_proto_t )
159
 
160
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t )
161
 
162
int arp_initialize( void ){
3991 mejdrech 163
    ERROR_DECLARE;
164
 
165
    rwlock_initialize( & arp_globals.lock );
166
    rwlock_write_lock( & arp_globals.lock );
167
    ERROR_PROPAGATE( arp_cache_initialize( & arp_globals.cache ));
168
    rwlock_write_unlock( & arp_globals.lock );
169
    return EOK;
3846 mejdrech 170
}
171
 
172
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address ){
173
    ERROR_DECLARE;
174
 
175
    * proto = ( arp_proto_ref ) malloc( sizeof( arp_proto_t ));
176
    if( !( * proto )) return ENOMEM;
177
    ( ** proto ).service = service;
178
    ( ** proto ).addr = address;
179
    ( ** proto ).addr_data = address->value;
3912 mejdrech 180
    if( ERROR_OCCURRED( arp_addr_initialize( &( ** proto).addresses ))){
3846 mejdrech 181
        free( * proto );
182
        return ERROR_CODE;
183
    }
184
    return EOK;
185
}
186
 
187
int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address ){
188
    ERROR_DECLARE;
189
 
190
    arp_device_ref  device;
191
    aid_t           message;
192
    ipc_call_t      answer;
193
    ipcarg_t        result;
194
    arp_proto_ref   proto;
195
 
3991 mejdrech 196
    rwlock_write_lock( & arp_globals.lock );
3846 mejdrech 197
    // an existing device?
198
    device = arp_cache_find( & arp_globals.cache, device_id );
199
    if( device ){
3991 mejdrech 200
        if( device->service != service ){
201
            rwlock_write_unlock( & arp_globals.lock );
202
            return EEXIST;
203
        }
3846 mejdrech 204
        proto = arp_protos_find( & device->protos, protocol );
205
        if( proto ){
206
            free( proto->addr );
207
            free( proto->addr_data );
208
            proto->addr = address;
209
            proto->addr_data = address->value;
210
        }else{
3991 mejdrech 211
            if( ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){
212
                rwlock_write_unlock( & arp_globals.lock );
213
                return ERROR_CODE;
214
            }
3912 mejdrech 215
            if( ERROR_OCCURRED( arp_protos_add( & device->protos, proto->service, proto ))){
3991 mejdrech 216
                rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 217
                free( proto );
218
                return ERROR_CODE;
219
            }
220
        }
221
        return EOK;
222
    }else{
223
        // create a new device
224
        device = ( arp_device_ref ) malloc( sizeof( arp_device_t ));
3991 mejdrech 225
        if( ! device ){
226
            rwlock_write_unlock( & arp_globals.lock );
227
            return ENOMEM;
228
        }
3846 mejdrech 229
        device->device_id = device_id;
3912 mejdrech 230
        if( ERROR_OCCURRED( arp_protos_initialize( & device->protos ))
231
        || ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){
3991 mejdrech 232
            rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 233
            free( device );
234
            return ERROR_CODE;
235
        }
3912 mejdrech 236
        if( ERROR_OCCURRED( arp_protos_add( & device->protos, proto->service, proto ))){
3991 mejdrech 237
            rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 238
            arp_protos_destroy( & device->protos );
239
            free( device );
240
            return ERROR_CODE;
241
        }
242
        device->service = service;
243
        // bind the new one
244
        device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver );
245
        // get packet dimensions
3912 mejdrech 246
        if( ERROR_OCCURRED( async_req_1_4( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){
3991 mejdrech 247
            rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 248
            arp_protos_destroy( & device->protos );
249
            free( device );
250
            return ERROR_CODE;
251
        }
252
        // get hardware address
253
        message = async_send_1( device->phone, NET_NIL_ADDR, device->device_id, & answer );
3912 mejdrech 254
        if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){
3991 mejdrech 255
            rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 256
            arp_protos_destroy( & device->protos );
257
            free( device );
258
            async_wait_for( message, NULL );
259
            return ERROR_CODE;
260
        }
261
        async_wait_for( message, & result );
3912 mejdrech 262
        if( ERROR_OCCURRED( result )){
3991 mejdrech 263
            rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 264
            free( device->addr );
265
            free( device->addr_data );
266
            arp_protos_destroy( & device->protos );
267
            free( device );
268
            return ERROR_CODE;
269
        }
270
        // get broadcast address
271
        message = async_send_1( device->phone, NET_NIL_BROADCAST_ADDR, device->device_id, & answer );
3912 mejdrech 272
        if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->broadcast_addr, & device->broadcast_data, 1 ))){
3991 mejdrech 273
            rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 274
            free( device->addr );
275
            free( device->addr_data );
276
            arp_protos_destroy( & device->protos );
277
            free( device );
278
            async_wait_for( message, NULL );
279
            return ERROR_CODE;
280
        }
281
        async_wait_for( message, & result );
282
        // add to the cache
3912 mejdrech 283
        if( ERROR_OCCURRED( result )
284
        || ERROR_OCCURRED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){
3991 mejdrech 285
            rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 286
            free( device->addr );
287
            free( device->addr_data );
288
            free( device->broadcast_addr );
289
            free( device->broadcast_data );
290
            arp_protos_destroy( & device->protos );
291
            free( device );
292
            return ERROR_CODE;
293
        }
294
    }
3991 mejdrech 295
    rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 296
    return EOK;
297
}
298
 
299
measured_string_ref arp_translate_message( device_id_t device_id, services_t protocol, measured_string_ref target ){
300
    arp_device_ref      device;
301
    arp_proto_ref       proto;
302
    measured_string_ref addr;
303
    size_t              length;
304
    packet_t            packet;
305
    arp_header_ref      header;
306
 
307
    if( ! target ) return NULL;
3991 mejdrech 308
    rwlock_read_lock( & arp_globals.lock );
3846 mejdrech 309
    device = arp_cache_find( & arp_globals.cache, device_id );
3991 mejdrech 310
    if( ! device ){
311
        rwlock_read_unlock( & arp_globals.lock );
312
        return NULL;
313
    }
3846 mejdrech 314
    proto = arp_protos_find( & device->protos, protocol );
3991 mejdrech 315
    if(( ! proto ) || ( proto->addr->length != target->length )){
316
        rwlock_read_unlock( & arp_globals.lock );
317
        return NULL;
318
    }
3846 mejdrech 319
    addr = arp_addr_find( & proto->addresses, target->value, target->length );
3991 mejdrech 320
    if( addr ){
321
        rwlock_read_unlock( & arp_globals.lock );
322
        return addr;
323
    }
3846 mejdrech 324
    // ARP packet content size = header + ( address + translation ) * 2
325
    length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2;
326
    if( length > device->content ){
3991 mejdrech 327
        rwlock_read_unlock( & arp_globals.lock );
3846 mejdrech 328
        return NULL;
329
    }
3991 mejdrech 330
    packet = packet_get_4( arp_globals.networking_phone, device->addr_len, device->prefix, length, device->suffix );
331
    if( ! packet ){
332
        rwlock_read_unlock( & arp_globals.lock );
333
        return NULL;
334
    }
3912 mejdrech 335
    header = ( arp_header_ref ) packet_suffix( packet, length );
3846 mejdrech 336
    header->hardware = device->hardware;
337
    header->hardware_length = device->addr->length;
338
    header->protocol = protocol_map( device->service, protocol );
339
    header->protocol_length = proto->addr->length;
340
    header->operation = ARPOP_REQUEST;
341
    length = sizeof( arp_header_t );
342
    memcpy((( uint8_t * ) header ) + length, device->addr->value, device->addr->length );
343
    length += device->addr->length;
344
    memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length );
345
    length += proto->addr->length;
346
    memset((( uint8_t * ) header ) + length, 0, device->addr->length );
347
    length += device->addr->length;
348
    memcpy((( uint8_t * ) header ) + length, target->value, target->length );
3912 mejdrech 349
    packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length ));
3901 mejdrech 350
    async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet ));
3991 mejdrech 351
    rwlock_read_unlock( & arp_globals.lock );
3846 mejdrech 352
    return NULL;
353
}
354
 
355
int arp_receive_message( device_id_t device_id, packet_t packet ){
356
    ERROR_DECLARE;
357
 
358
    size_t              length;
359
    arp_header_ref      header;
360
    arp_device_ref      device;
361
    arp_proto_ref       proto;
362
    measured_string_ref hw_source;
3991 mejdrech 363
    uint8_t *           src_hw;
3912 mejdrech 364
    uint8_t *           src_proto;
365
    uint8_t *           des_hw;
366
    uint8_t *           des_proto;
3846 mejdrech 367
 
368
    length = packet_get_data_length( packet );
369
    if( length <= sizeof( arp_header_t )) return EINVAL;
3991 mejdrech 370
    rwlock_read_lock( & arp_globals.lock );
3846 mejdrech 371
    device = arp_cache_find( & arp_globals.cache, device_id );
3991 mejdrech 372
    if( ! device ){
373
        rwlock_read_unlock( & arp_globals.lock );
374
        return ENOENT;
375
    }
3846 mejdrech 376
    header = ( arp_header_ref ) packet_get_data( packet );
3991 mejdrech 377
    if(( header->hardware != device->hardware )
378
    || ( length < sizeof( arp_header_t ) + ( header->hardware_length + header->protocol_length ) * 2 )){
379
        rwlock_read_unlock( & arp_globals.lock );
380
        return EINVAL;
381
    }
3846 mejdrech 382
    proto = arp_protos_find( & device->protos, protocol_unmap( device->service, header->protocol ));
3991 mejdrech 383
    if( ! proto ){
384
        rwlock_read_unlock( & arp_globals.lock );
385
        return ENOENT;
386
    }
3912 mejdrech 387
    src_hw = (( uint8_t * ) header ) + sizeof( arp_header_t );
3846 mejdrech 388
    src_proto = src_hw + header->hardware_length;
389
    des_hw = src_proto + header->protocol_length;
390
    des_proto = des_hw + header->hardware_length;
3912 mejdrech 391
    hw_source = arp_addr_find( & proto->addresses, ( char * ) src_proto, CONVERT_SIZE( uint8_t, char, header->protocol_length ));
3846 mejdrech 392
    // exists?
393
    if( hw_source ){
3991 mejdrech 394
        if( hw_source->length != CONVERT_SIZE( uint8_t, char, header->hardware_length )){
395
            rwlock_read_unlock( & arp_globals.lock );
396
            return EINVAL;
397
        }
3912 mejdrech 398
        memcpy( hw_source->value, src_hw, hw_source->length );
3846 mejdrech 399
    }
400
    // is my protocol address?
3991 mejdrech 401
    if( proto->addr->length != CONVERT_SIZE( uint8_t, char, header->hardware_length )){
402
        rwlock_read_unlock( & arp_globals.lock );
403
        return EINVAL;
3846 mejdrech 404
    }
3912 mejdrech 405
    if( ! strncmp( proto->addr->value, ( char * ) des_proto, proto->addr->length )){
3846 mejdrech 406
        // not already upadted?
407
        if( ! hw_source ){
3912 mejdrech 408
            hw_source = measured_string_create_bulk(( char * ) src_hw, CONVERT_SIZE( uint8_t, char, header->hardware_length ));
3991 mejdrech 409
            if( ! hw_source ){
410
                rwlock_read_unlock( & arp_globals.lock );
411
                return ENOMEM;
412
            }
413
            if( ERROR_OCCURRED( arp_addr_add( & proto->addresses, ( char * ) src_proto, CONVERT_SIZE( uint8_t, char, header->protocol_length ), hw_source ))){
414
                rwlock_read_unlock( & arp_globals.lock );
415
                return ERROR_CODE;
416
            }
3846 mejdrech 417
        }
418
        if( header->operation == ARPOP_REQUEST ){
419
            header->operation = ARPOP_REPLY;
3991 mejdrech 420
            memcpy( des_proto, src_proto, header->protocol_length );
3846 mejdrech 421
            memcpy( src_proto, proto->addr->value, header->protocol_length );
422
            memcpy( src_hw, des_hw, header->hardware_length );
3912 mejdrech 423
            memcpy( des_hw, hw_source->value, header->hardware_length );
424
            packet_set_addr( packet, src_hw, des_hw, header->hardware_length );
3901 mejdrech 425
            async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet ));
3991 mejdrech 426
            rwlock_read_unlock( & arp_globals.lock );
3901 mejdrech 427
        }else{
3991 mejdrech 428
            rwlock_read_unlock( & arp_globals.lock );
3901 mejdrech 429
            packet_release( arp_globals.networking_phone, packet_get_id( packet ));
3846 mejdrech 430
        }
431
    }
432
    return EOK;
433
}
434
 
435
int arp_clear_device_message( device_id_t device_id ){
436
    arp_device_ref  device;
437
 
3991 mejdrech 438
    rwlock_write_lock( & arp_globals.lock );
3846 mejdrech 439
    device = arp_cache_find( & arp_globals.cache, device_id );
3991 mejdrech 440
    if( ! device ){
441
        rwlock_write_unlock( & arp_globals.lock );
442
        return ENOENT;
443
    }
3846 mejdrech 444
    clear_device( device );
3991 mejdrech 445
    rwlock_write_unlock( & arp_globals.lock );
3846 mejdrech 446
    return EOK;
447
}
448
 
449
void clear_device( arp_device_ref device ){
450
    int             count;
451
    arp_proto_ref   proto;
452
 
453
    count = arp_protos_count( & device->protos );
454
    while( count > 0 ){
455
        proto = arp_protos_get_index( & device->protos, count );
456
        if( proto->addr ) free( proto->addr );
457
        if( proto->addr_data ) free( proto->addr_data );
458
        arp_addr_destroy( & proto->addresses );
459
        -- count;
460
    }
461
    arp_protos_clear( & device->protos );
462
}
463
 
464
int arp_clean_cache_message( void ){
465
    int             count;
466
    arp_device_ref  device;
467
 
3991 mejdrech 468
    rwlock_write_lock( & arp_globals.lock );
3846 mejdrech 469
    count = arp_cache_count( & arp_globals.cache );
470
    while( count > 0 ){
471
        device = arp_cache_get_index( & arp_globals.cache, count );
472
        if( device ){
473
            clear_device( device );
3912 mejdrech 474
            if( device->addr_data ) free( device->addr_data );
3846 mejdrech 475
            if( device->broadcast_data ) free( device->broadcast_data );
476
        }
477
    }
478
    arp_cache_clear( & arp_globals.cache );
3991 mejdrech 479
    rwlock_write_lock( & arp_globals.lock );
3846 mejdrech 480
    return EOK;
481
}
482
 
483
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
484
    ERROR_DECLARE;
485
 
486
    measured_string_ref address;
487
    measured_string_ref translation;
488
    char *              data;
489
 
490
    * answer_count = 0;
491
    switch( IPC_GET_METHOD( * call )){
492
        case IPC_M_PHONE_HUNGUP:
493
            return EOK;
494
        case NET_ARP_DEVICE:
495
            ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 ));
3912 mejdrech 496
            if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_PROTO( call ), address ))){
3846 mejdrech 497
                free( address );
498
                free( data );
499
            }
500
            return ERROR_CODE;
501
        case NET_ARP_TRANSLATE:
502
            ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 ));
503
            translation = arp_translate_message( IPC_GET_DEVICE( call ), IPC_GET_PROTO( call ), address );
504
            free( address );
505
            free( data );
506
            if( ! translation ) return ENOENT;
507
            return measured_strings_reply( translation, 1 );
508
        case NET_ARP_CLEAR_DEVICE:
509
            return arp_clear_device_message( IPC_GET_DEVICE( call ));
510
        case NET_ARP_CLEAN_CACHE:
511
            return arp_clean_cache_message();
512
    }
513
    return ENOTSUP;
514
}
515
 
516
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ){
517
    ERROR_DECLARE;
518
 
519
    packet_t        packet;
520
 
521
    while( true ){
3912 mejdrech 522
        switch( IPC_GET_METHOD( * icall )){
3846 mejdrech 523
            case NET_IL_DEVICE_STATE:
3991 mejdrech 524
                // do nothing - keep the cache
525
                ipc_answer_0( iid, EOK );
3846 mejdrech 526
                break;
527
            case NET_IL_RECEIVED:
3912 mejdrech 528
                if( ! ERROR_OCCURRED( packet_translate( arp_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){
529
                    ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( icall ), packet );
3846 mejdrech 530
                }
3912 mejdrech 531
                ipc_answer_0( iid, ERROR_CODE );
3846 mejdrech 532
                break;
533
            default:
3912 mejdrech 534
                ipc_answer_0( iid, ENOTSUP );
3846 mejdrech 535
        }
3912 mejdrech 536
        iid = async_get_call( icall );
3846 mejdrech 537
    }
538
}
539
 
540
/** @}
541
 */