Subversion Repositories HelenOS

Rev

Rev 4695 | Rev 4708 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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