Subversion Repositories HelenOS

Rev

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

Rev 3901 Rev 3912
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2008 Lukas Mejdrech
2
 * Copyright (c) 2009 Lukas Mejdrech
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
Line 29... Line 29...
29
/** @addtogroup arp
29
/** @addtogroup arp
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
-
 
34
 *  ARP module implementation.
-
 
35
 *  @see arp.h
34
 */
36
 */
35
 
37
 
36
#include <as.h>
38
#include <as.h>
37
#include <async.h>
39
#include <async.h>
38
#include <malloc.h>
40
#include <malloc.h>
Line 57... Line 59...
57
#include "arp_header.h"
59
#include "arp_header.h"
58
#include "arp_oc.h"
60
#include "arp_oc.h"
59
//#include "arp_messages.h"
61
//#include "arp_messages.h"
60
#include "arp_module.h"
62
#include "arp_module.h"
61
 
63
 
-
 
64
/** Returns the device identifier message parameter.
-
 
65
 */
62
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
66
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
-
 
67
 
-
 
68
/** Returns the packet identifier message parameter.
-
 
69
 */
63
#define IPC_GET_PACKET( call )      ( packet_id_t ) IPC_GET_ARG2( * call )
70
#define IPC_GET_PACKET( call )      ( packet_id_t ) IPC_GET_ARG2( * call )
-
 
71
 
-
 
72
/** Returns the protocol service message parameter.
-
 
73
 */
64
#define IPC_GET_PROTO( call )       ( services_t ) IPC_GET_ARG2( * call )
74
#define IPC_GET_PROTO( call )       ( services_t ) IPC_GET_ARG2( * call )
-
 
75
 
-
 
76
/** Returns the device driver service message parameter.
-
 
77
 */
65
#define IPC_GET_SERVICE( call )     ( services_t ) IPC_GET_ARG3( * call )
78
#define IPC_GET_SERVICE( call )     ( services_t ) IPC_GET_ARG3( * call )
66
 
79
 
-
 
80
/** ARP global data.
-
 
81
 */
67
arp_globals_t   arp_globals;
82
arp_globals_t   arp_globals;
68
 
83
 
-
 
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
 
69
DEVICE_MAP_IMPLEMENT( arp_cache, arp_device_t )
156
DEVICE_MAP_IMPLEMENT( arp_cache, arp_device_t )
70
 
157
 
71
INT_MAP_IMPLEMENT( arp_protos, arp_proto_t )
158
INT_MAP_IMPLEMENT( arp_protos, arp_proto_t )
72
 
159
 
73
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t )
160
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t )
74
 
161
 
75
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address );
-
 
76
int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address );
-
 
77
measured_string_ref arp_translate_message( device_id_t device, services_t protocol, measured_string_ref target );
-
 
78
int arp_receive_message( device_id_t device_id, packet_t packet );
-
 
79
int arp_clear_device_message( device_id_t device_id );
-
 
80
void clear_device( arp_device_ref device );
-
 
81
int arp_clean_cache_message( void );
-
 
82
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall );
-
 
83
 
-
 
84
/** Initializes the ARP module.
-
 
85
 */
-
 
86
int arp_initialize( void ){
162
int arp_initialize( void ){
87
    arp_cache_initialize( & arp_globals.cache );
163
    return arp_cache_initialize( & arp_globals.cache );
88
    return EOK;
-
 
89
}
164
}
90
 
165
 
91
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address ){
166
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address ){
92
    ERROR_DECLARE;
167
    ERROR_DECLARE;
93
 
168
 
94
    * proto = ( arp_proto_ref ) malloc( sizeof( arp_proto_t ));
169
    * proto = ( arp_proto_ref ) malloc( sizeof( arp_proto_t ));
95
    if( !( * proto )) return ENOMEM;
170
    if( !( * proto )) return ENOMEM;
96
    ( ** proto ).service = service;
171
    ( ** proto ).service = service;
97
    ( ** proto ).addr = address;
172
    ( ** proto ).addr = address;
98
    ( ** proto ).addr_data = address->value;
173
    ( ** proto ).addr_data = address->value;
99
    if( ERROR_OCCURED( arp_addr_initialize( &( ** proto).addresses ))){
174
    if( ERROR_OCCURRED( arp_addr_initialize( &( ** proto).addresses ))){
100
        free( * proto );
175
        free( * proto );
101
        return ERROR_CODE;
176
        return ERROR_CODE;
102
    }
177
    }
103
    return EOK;
178
    return EOK;
104
}
179
}
Line 122... Line 197...
122
            free( proto->addr_data );
197
            free( proto->addr_data );
123
            proto->addr = address;
198
            proto->addr = address;
124
            proto->addr_data = address->value;
199
            proto->addr_data = address->value;
125
        }else{
200
        }else{
126
            ERROR_PROPAGATE( arp_proto_create( & proto, protocol, address ));
201
            ERROR_PROPAGATE( arp_proto_create( & proto, protocol, address ));
127
            if( ERROR_OCCURED( arp_protos_add( & device->protos, proto->service, proto ))){
202
            if( ERROR_OCCURRED( arp_protos_add( & device->protos, proto->service, proto ))){
128
                free( proto );
203
                free( proto );
129
                return ERROR_CODE;
204
                return ERROR_CODE;
130
            }
205
            }
131
        }
206
        }
132
        return EOK;
207
        return EOK;
133
    }else{
208
    }else{
134
        // create a new device
209
        // create a new device
135
        device = ( arp_device_ref ) malloc( sizeof( arp_device_t ));
210
        device = ( arp_device_ref ) malloc( sizeof( arp_device_t ));
136
        if( ! device ) return ENOMEM;
211
        if( ! device ) return ENOMEM;
137
        device->device_id = device_id;
212
        device->device_id = device_id;
138
        if( ERROR_OCCURED( arp_protos_initialize( & device->protos ))
213
        if( ERROR_OCCURRED( arp_protos_initialize( & device->protos ))
139
        || ERROR_OCCURED( arp_proto_create( & proto, protocol, address ))){
214
        || ERROR_OCCURRED( arp_proto_create( & proto, protocol, address ))){
140
            free( device );
215
            free( device );
141
            return ERROR_CODE;
216
            return ERROR_CODE;
142
        }
217
        }
143
        if( ERROR_OCCURED( arp_protos_add( & device->protos, proto->service, proto ))){
218
        if( ERROR_OCCURRED( arp_protos_add( & device->protos, proto->service, proto ))){
144
            arp_protos_destroy( & device->protos );
219
            arp_protos_destroy( & device->protos );
145
            free( device );
220
            free( device );
146
            return ERROR_CODE;
221
            return ERROR_CODE;
147
        }
222
        }
148
        device->service = service;
223
        device->service = service;
149
        // bind the new one
224
        // bind the new one
150
        device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver );
225
        device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver );
151
        // get packet dimensions
226
        // get packet dimensions
152
        if( ERROR_OCCURED( async_req_1_4( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->addr_len, & device->prefix, & device->content, & device->sufix ))){
227
        if( ERROR_OCCURRED( async_req_1_4( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){
153
            arp_protos_destroy( & device->protos );
228
            arp_protos_destroy( & device->protos );
154
            free( device );
229
            free( device );
155
            return ERROR_CODE;
230
            return ERROR_CODE;
156
        }
231
        }
157
        // get hardware address
232
        // get hardware address
158
        message = async_send_1( device->phone, NET_NIL_ADDR, device->device_id, & answer );
233
        message = async_send_1( device->phone, NET_NIL_ADDR, device->device_id, & answer );
159
        if( ERROR_OCCURED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){
234
        if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){
160
            arp_protos_destroy( & device->protos );
235
            arp_protos_destroy( & device->protos );
161
            free( device );
236
            free( device );
162
            async_wait_for( message, NULL );
237
            async_wait_for( message, NULL );
163
            return ERROR_CODE;
238
            return ERROR_CODE;
164
        }
239
        }
165
        async_wait_for( message, & result );
240
        async_wait_for( message, & result );
166
        if( ERROR_OCCURED( result )){
241
        if( ERROR_OCCURRED( result )){
167
            free( device->addr );
242
            free( device->addr );
168
            free( device->addr_data );
243
            free( device->addr_data );
169
            arp_protos_destroy( & device->protos );
244
            arp_protos_destroy( & device->protos );
170
            free( device );
245
            free( device );
171
            return ERROR_CODE;
246
            return ERROR_CODE;
172
        }
247
        }
173
        // get broadcast address
248
        // get broadcast address
174
        message = async_send_1( device->phone, NET_NIL_BROADCAST_ADDR, device->device_id, & answer );
249
        message = async_send_1( device->phone, NET_NIL_BROADCAST_ADDR, device->device_id, & answer );
175
        if( ERROR_OCCURED( measured_strings_return( device->phone, & device->broadcast_addr, & device->broadcast_data, 1 ))){
250
        if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->broadcast_addr, & device->broadcast_data, 1 ))){
176
            free( device->addr );
251
            free( device->addr );
177
            free( device->addr_data );
252
            free( device->addr_data );
178
            arp_protos_destroy( & device->protos );
253
            arp_protos_destroy( & device->protos );
179
            free( device );
254
            free( device );
180
            async_wait_for( message, NULL );
255
            async_wait_for( message, NULL );
181
            return ERROR_CODE;
256
            return ERROR_CODE;
182
        }
257
        }
183
        async_wait_for( message, & result );
258
        async_wait_for( message, & result );
184
        // add to the cache
259
        // add to the cache
185
        if( ERROR_OCCURED( result )
260
        if( ERROR_OCCURRED( result )
186
        || ERROR_OCCURED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){
261
        || ERROR_OCCURRED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){
187
            free( device->addr );
262
            free( device->addr );
188
            free( device->addr_data );
263
            free( device->addr_data );
189
            free( device->broadcast_addr );
264
            free( device->broadcast_addr );
190
            free( device->broadcast_data );
265
            free( device->broadcast_data );
191
            arp_protos_destroy( & device->protos );
266
            arp_protos_destroy( & device->protos );
Line 195... Line 270...
195
    }
270
    }
196
    return EOK;
271
    return EOK;
197
}
272
}
198
 
273
 
199
measured_string_ref arp_translate_message( device_id_t device_id, services_t protocol, measured_string_ref target ){
274
measured_string_ref arp_translate_message( device_id_t device_id, services_t protocol, measured_string_ref target ){
200
//  ERROR_DECLARE;
-
 
201
 
-
 
202
    arp_device_ref      device;
275
    arp_device_ref      device;
203
    arp_proto_ref       proto;
276
    arp_proto_ref       proto;
204
    measured_string_ref addr;
277
    measured_string_ref addr;
205
    size_t              length;
278
    size_t              length;
206
    packet_t            packet;
279
    packet_t            packet;
Line 216... Line 289...
216
    // ARP packet content size = header + ( address + translation ) * 2
289
    // ARP packet content size = header + ( address + translation ) * 2
217
    length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2;
290
    length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2;
218
    if( length > device->content ){
291
    if( length > device->content ){
219
        return NULL;
292
        return NULL;
220
    }
293
    }
221
    packet = packet_get_5( arp_globals.networking_phone, SERVICE_ARP, device->addr_len, device->prefix, length, device->sufix );
294
    packet = packet_get_5( arp_globals.networking_phone, SERVICE_ARP, device->addr_len, device->prefix, length, device->suffix );
222
    if( ! packet ) return NULL;
295
    if( ! packet ) return NULL;
223
    header = ( arp_header_ref ) packet_append( packet, length );
296
    header = ( arp_header_ref ) packet_suffix( packet, length );
224
    header->hardware = device->hardware;
297
    header->hardware = device->hardware;
225
    header->hardware_length = device->addr->length;
298
    header->hardware_length = device->addr->length;
226
    header->protocol = protocol_map( device->service, protocol );
299
    header->protocol = protocol_map( device->service, protocol );
227
    header->protocol_length = proto->addr->length;
300
    header->protocol_length = proto->addr->length;
228
    header->operation = ARPOP_REQUEST;
301
    header->operation = ARPOP_REQUEST;
Line 232... Line 305...
232
    memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length );
305
    memcpy((( uint8_t * ) header ) + length, proto->addr->value, proto->addr->length );
233
    length += proto->addr->length;
306
    length += proto->addr->length;
234
    memset((( uint8_t * ) header ) + length, 0, device->addr->length );
307
    memset((( uint8_t * ) header ) + length, 0, device->addr->length );
235
    length += device->addr->length;
308
    length += device->addr->length;
236
    memcpy((( uint8_t * ) header ) + length, target->value, target->length );
309
    memcpy((( uint8_t * ) header ) + length, target->value, target->length );
237
    // TODO send to the device->broadcast_addr as arp protocol
310
    packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length ));
238
    async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet ));
311
    async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet ));
239
    return NULL;
312
    return NULL;
240
}
313
}
241
 
314
 
242
int arp_receive_message( device_id_t device_id, packet_t packet ){
315
int arp_receive_message( device_id_t device_id, packet_t packet ){
Line 251... Line 324...
251
/*  measured_string_t   proto_target;
324
/*  measured_string_t   proto_target;
252
    aid_t               message;
325
    aid_t               message;
253
    ipcarg_t            result;
326
    ipcarg_t            result;
254
    int                 index;
327
    int                 index;
255
    ipc_call_t          answer;
328
    ipc_call_t          answer;
256
*/  int8_t *            src_hw;
329
*/  uint8_t *           src_hw;
257
    int8_t *            src_proto;
330
    uint8_t *           src_proto;
258
    int8_t *            des_hw;
331
    uint8_t *           des_hw;
259
    int8_t *            des_proto;
332
    uint8_t *           des_proto;
260
 
333
 
261
    length = packet_get_data_length( packet );
334
    length = packet_get_data_length( packet );
262
    if( length <= sizeof( arp_header_t )) return EINVAL;
335
    if( length <= sizeof( arp_header_t )) return EINVAL;
263
    device = arp_cache_find( & arp_globals.cache, device_id );
336
    device = arp_cache_find( & arp_globals.cache, device_id );
264
    if( ! device ) return ENOENT;
337
    if( ! device ) return ENOENT;
265
    header = ( arp_header_ref ) packet_get_data( packet );
338
    header = ( arp_header_ref ) packet_get_data( packet );
266
    if( header->hardware != device->hardware ) return EINVAL;
339
    if( header->hardware != device->hardware ) return EINVAL;
267
    if( length < sizeof( arp_header_t ) + ( header->hardware_length + header->protocol_length ) * 2 ) return EINVAL;
340
    if( length < sizeof( arp_header_t ) + ( header->hardware_length + header->protocol_length ) * 2 ) return EINVAL;
268
    proto = arp_protos_find( & device->protos, protocol_unmap( device->service, header->protocol ));
341
    proto = arp_protos_find( & device->protos, protocol_unmap( device->service, header->protocol ));
269
    if( ! proto ) return ENOENT;
342
    if( ! proto ) return ENOENT;
270
    src_hw = (( int8_t * ) header ) + sizeof( arp_header_t );
343
    src_hw = (( uint8_t * ) header ) + sizeof( arp_header_t );
271
    src_proto = src_hw + header->hardware_length;
344
    src_proto = src_hw + header->hardware_length;
272
    des_hw = src_proto + header->protocol_length;
345
    des_hw = src_proto + header->protocol_length;
273
    des_proto = des_hw + header->hardware_length;
346
    des_proto = des_hw + header->hardware_length;
274
    hw_source = arp_addr_find( & proto->addresses, src_proto, header->protocol_length );
347
    hw_source = arp_addr_find( & proto->addresses, ( char * ) src_proto, CONVERT_SIZE( uint8_t, char, header->protocol_length ));
275
    // exists?
348
    // exists?
276
    if( hw_source ){
349
    if( hw_source ){
277
        if( hw_source->length != header->hardware_length ) return EINVAL;
350
        if( hw_source->length != CONVERT_SIZE( uint8_t, char, header->hardware_length )) return EINVAL;
278
        memcpy( hw_source->value, src_hw, header->hardware_length );
351
        memcpy( hw_source->value, src_hw, hw_source->length );
279
    }
352
    }
280
    // is my protocol address?
353
    // is my protocol address?
-
 
354
    // TODO query protocol module?
281
/*  proto_target.value = des_proto;
355
/*  proto_target.value = des_proto;
282
    proto_target.length = header->protocol_length;
356
    proto_target.length = header->protocol_length;
283
    // TODO send necessary?
357
    // TODO send necessary?
284
    message = async_send_0( proto->phone, NET_IL_MY_ADDR, & answer );
358
    message = async_send_0( proto->phone, NET_IL_MY_ADDR, & answer );
285
    if( ERROR_OCCURED( measured_strings_send( device->phone, & proto_target, 1 ))){
359
    if( ERROR_OCCURRED( measured_strings_send( device->phone, & proto_target, 1 ))){
286
        async_wait_for( message, NULL );
360
        async_wait_for( message, NULL );
287
        return ERROR_CODE;
361
        return ERROR_CODE;
288
    }
362
    }
289
    async_wait_for( message, & result );
363
    async_wait_for( message, & result );
290
    if( result == EOK ){
364
    if( result == EOK ){
291
*/  if( proto->addr->length != header->hardware_length ) return EINVAL;
365
*/  if( proto->addr->length != CONVERT_SIZE( uint8_t, char, header->hardware_length )) return EINVAL;
292
    if( ! strncmp( proto->addr->value, des_proto, proto->addr->length )){
366
    if( ! strncmp( proto->addr->value, ( char * ) des_proto, proto->addr->length )){
293
        // not already upadted?
367
        // not already upadted?
294
        if( ! hw_source ){
368
        if( ! hw_source ){
295
            hw_source = measured_string_create_bulk( src_hw, header->hardware_length );
369
            hw_source = measured_string_create_bulk(( char * ) src_hw, CONVERT_SIZE( uint8_t, char, header->hardware_length ));
296
            if( ! hw_source ) return ENOMEM;
370
            if( ! hw_source ) return ENOMEM;
297
            ERROR_PROPAGATE( arp_addr_add( & proto->addresses, src_proto, header->protocol_length, hw_source ));
371
            ERROR_PROPAGATE( arp_addr_add( & proto->addresses, ( char * ) src_proto, CONVERT_SIZE( uint8_t, char, header->protocol_length ), hw_source ));
298
        }
372
        }
299
        if( header->operation == ARPOP_REQUEST ){
373
        if( header->operation == ARPOP_REQUEST ){
300
            header->operation = ARPOP_REPLY;
374
            header->operation = ARPOP_REPLY;
301
/*          for( index = 0; index + header->hardware_length < header->protocol_length; index += header->hardware_length ){
375
/*          for( index = 0; index + header->hardware_length < header->protocol_length; index += header->hardware_length ){
302
                memcpy( src_hw, src_proto + index, header->hardware_length );
376
                memcpy( src_hw, src_proto + index, header->hardware_length );
Line 309... Line 383...
309
            memcpy( src_hw, des_hw, header->hardware_length );
383
            memcpy( src_hw, des_hw, header->hardware_length );
310
            memcpy( des_hw, hw_source->value, hw_source->length );
384
            memcpy( des_hw, hw_source->value, hw_source->length );
311
*/          memcpy( des_proto, src_proto, header->protocol_length );
385
*/          memcpy( des_proto, src_proto, header->protocol_length );
312
            memcpy( src_proto, proto->addr->value, header->protocol_length );
386
            memcpy( src_proto, proto->addr->value, header->protocol_length );
313
            memcpy( src_hw, des_hw, header->hardware_length );
387
            memcpy( src_hw, des_hw, header->hardware_length );
314
            memcpy( des_hw, hw_source->value, hw_source->length );
388
            memcpy( des_hw, hw_source->value, header->hardware_length );
315
            // TODO send to the hw_source as arp protocol
389
            packet_set_addr( packet, src_hw, des_hw, header->hardware_length );
316
            async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet ));
390
            async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet ));
317
        }else{
391
        }else{
318
            packet_release( arp_globals.networking_phone, packet_get_id( packet ));
392
            packet_release( arp_globals.networking_phone, packet_get_id( packet ));
319
        }
393
        }
320
    }
394
    }
Line 352... Line 426...
352
    count = arp_cache_count( & arp_globals.cache );
426
    count = arp_cache_count( & arp_globals.cache );
353
    while( count > 0 ){
427
    while( count > 0 ){
354
        device = arp_cache_get_index( & arp_globals.cache, count );
428
        device = arp_cache_get_index( & arp_globals.cache, count );
355
        if( device ){
429
        if( device ){
356
            clear_device( device );
430
            clear_device( device );
357
            if( device->broadcast_addr ) free( device->broadcast_addr );
431
            if( device->addr_data ) free( device->addr_data );
358
            if( device->broadcast_data ) free( device->broadcast_data );
432
            if( device->broadcast_data ) free( device->broadcast_data );
359
        }
433
        }
360
    }
434
    }
361
    arp_cache_clear( & arp_globals.cache );
435
    arp_cache_clear( & arp_globals.cache );
362
    return EOK;
436
    return EOK;
363
}
437
}
364
 
438
 
365
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
439
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
366
    ERROR_DECLARE;
440
    ERROR_DECLARE;
367
 
441
 
368
//  packet_t            packet;
-
 
369
    measured_string_ref address;
442
    measured_string_ref address;
370
    measured_string_ref translation;
443
    measured_string_ref translation;
371
    char *              data;
444
    char *              data;
372
 
445
 
373
    * answer_count = 0;
446
    * answer_count = 0;
374
    switch( IPC_GET_METHOD( * call )){
447
    switch( IPC_GET_METHOD( * call )){
375
        case IPC_M_PHONE_HUNGUP:
448
        case IPC_M_PHONE_HUNGUP:
376
            return EOK;
449
            return EOK;
377
        case NET_ARP_DEVICE:
450
        case NET_ARP_DEVICE:
378
            ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 ));
451
            ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 ));
379
            if( ERROR_OCCURED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_PROTO( call ), address ))){
452
            if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_PROTO( call ), address ))){
380
                free( address );
453
                free( address );
381
                free( data );
454
                free( data );
382
            }
455
            }
383
            return ERROR_CODE;
456
            return ERROR_CODE;
384
        case NET_ARP_TRANSLATE:
457
        case NET_ARP_TRANSLATE:
Line 397... Line 470...
397
}
470
}
398
 
471
 
399
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ){
472
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ){
400
    ERROR_DECLARE;
473
    ERROR_DECLARE;
401
 
474
 
402
    ipc_callid_t    callid;
-
 
403
    ipc_call_t      call;
-
 
404
//  int             result;
-
 
405
    packet_t        packet;
475
    packet_t        packet;
406
 
476
 
407
    /*
-
 
408
     * Accept the connection
-
 
409
     *  - Answer the first IPC_M_CONNECT_ME_TO call.
-
 
410
     */
-
 
411
    //TODO auto accept?
-
 
412
    //ipc_answer_0( iid, EOK );
-
 
413
 
-
 
414
    while( true ){
477
    while( true ){
415
        callid = async_get_call( & call );
-
 
416
        switch( IPC_GET_METHOD( call )){
478
        switch( IPC_GET_METHOD( * icall )){
417
            case NET_IL_DEVICE_STATE:
479
            case NET_IL_DEVICE_STATE:
418
                //TODO clear device if off?
480
                //TODO clear device if off?
419
                break;
481
                break;
420
            case NET_IL_RECEIVED:
482
            case NET_IL_RECEIVED:
421
                if( ! ERROR_OCCURED( packet_translate( arp_globals.networking_phone, & packet, IPC_GET_PACKET( & call )))){
483
                if( ! ERROR_OCCURRED( packet_translate( arp_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){
422
                    ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( & call ), packet );
484
                    ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( icall ), packet );
423
                }
485
                }
424
                ipc_answer_0( callid, ERROR_CODE );
486
                ipc_answer_0( iid, ERROR_CODE );
425
                break;
487
                break;
426
            default:
488
            default:
427
                ipc_answer_0( callid, ENOTSUP );
489
                ipc_answer_0( iid, ENOTSUP );
428
        }
490
        }
-
 
491
        iid = async_get_call( icall );
429
    }
492
    }
430
}
493
}
431
 
494
 
432
/** @}
495
/** @}
433
 */
496
 */