Subversion Repositories HelenOS

Rev

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

Rev 4261 Rev 4271
Line 48... Line 48...
48
#include "../../messages.h"
48
#include "../../messages.h"
49
#include "../../modules.h"
49
#include "../../modules.h"
50
 
50
 
51
#include "../../include/byteorder.h"
51
#include "../../include/byteorder.h"
52
#include "../../include/device.h"
52
#include "../../include/device.h"
-
 
53
#include "../../include/arp_messages.h"
53
#include "../../include/nil_messages.h"
54
#include "../../include/nil_messages.h"
54
#include "../../include/protocol_map.h"
55
#include "../../include/protocol_map.h"
55
 
56
 
56
#include "../../structures/measured_strings.h"
57
#include "../../structures/measured_strings.h"
57
#include "../../structures/packet/packet.h"
58
#include "../../structures/packet/packet.h"
58
#include "../../structures/packet/packet_client.h"
59
#include "../../structures/packet/packet_client.h"
59
 
60
 
60
#include "arp.h"
61
#include "arp.h"
61
#include "arp_header.h"
62
#include "arp_header.h"
62
#include "arp_oc.h"
63
#include "arp_oc.h"
63
//#include "arp_messages.h"
-
 
64
#include "arp_module.h"
64
#include "arp_module.h"
65
 
-
 
66
/** Returns the protocol service message parameter.
65
#include "arp_wrappers.h"
67
 */
-
 
68
#define ARP_GET_PROTO( call )       ( services_t ) IPC_GET_ARG2( * call )
-
 
69
 
66
 
70
/** ARP global data.
67
/** ARP global data.
71
 */
68
 */
72
arp_globals_t   arp_globals;
69
arp_globals_t   arp_globals;
73
 
70
 
Line 118... Line 115...
118
 *  @returns ENOENT if the protocol for the device is not found in the cache.
115
 *  @returns ENOENT if the protocol for the device is not found in the cache.
119
 *  @returns ENOMEM if there is not enough memory left.
116
 *  @returns ENOMEM if there is not enough memory left.
120
 */
117
 */
121
int arp_receive_message( device_id_t device_id, packet_t packet );
118
int arp_receive_message( device_id_t device_id, packet_t packet );
122
 
119
 
123
/** Clears the device specific data from the cache.
-
 
124
 *  @param device_id The device identifier. Input parameter.
-
 
125
 *  @returns EOK on success.
-
 
126
 *  @returns ENOENT  if the device is not found in the cache.
-
 
127
 */
-
 
128
int arp_clear_device_message( device_id_t device_id );
-
 
129
 
-
 
130
/** Clears the device specific data.
120
/** Clears the device specific data.
131
 *  @param device The device specific data.
121
 *  @param device The device specific data.
132
 */
122
 */
133
void    clear_device( arp_device_ref device );
123
void    clear_device( arp_device_ref device );
134
 
124
 
135
/** Clears the whole cache.
-
 
136
 *  @returns EOK on success.
-
 
137
 */
-
 
138
int arp_clean_cache_message( void );
-
 
139
 
-
 
140
/** Processes IPC messages from the registered device driver modules in an infinite loop.
125
/** Processes IPC messages from the registered device driver modules in an infinite loop.
141
 *  @param iid The message identifier. Input parameter.
126
 *  @param iid The message identifier. Input parameter.
142
 *  @param icall The message parameters. Input/output parameter.
127
 *  @param icall The message parameters. Input/output parameter.
143
 */
128
 */
144
void    arp_receiver( ipc_callid_t iid, ipc_call_t * icall );
129
void    arp_receiver( ipc_callid_t iid, ipc_call_t * icall );
Line 147... Line 132...
147
 
132
 
148
INT_MAP_IMPLEMENT( arp_protos, arp_proto_t )
133
INT_MAP_IMPLEMENT( arp_protos, arp_proto_t )
149
 
134
 
150
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t )
135
GENERIC_CHAR_MAP_IMPLEMENT( arp_addr, measured_string_t )
151
 
136
 
-
 
137
int arp_clear_device_wrapper( device_id_t device_id ){
-
 
138
    arp_device_ref  device;
-
 
139
 
-
 
140
    rwlock_write_lock( & arp_globals.lock );
-
 
141
    device = arp_cache_find( & arp_globals.cache, device_id );
-
 
142
    if( ! device ){
-
 
143
        rwlock_write_unlock( & arp_globals.lock );
-
 
144
        return ENOENT;
-
 
145
    }
-
 
146
    clear_device( device );
-
 
147
    printf( "\nDevice %d cleared", device_id );
-
 
148
    rwlock_write_unlock( & arp_globals.lock );
-
 
149
    return EOK;
-
 
150
}
-
 
151
 
-
 
152
int arp_clean_cache_wrapper( void ){
-
 
153
    int             count;
-
 
154
    arp_device_ref  device;
-
 
155
 
-
 
156
    rwlock_write_lock( & arp_globals.lock );
-
 
157
    for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){
-
 
158
        device = arp_cache_get_index( & arp_globals.cache, count );
-
 
159
        if( device ){
-
 
160
            clear_device( device );
-
 
161
            if( device->addr_data ) free( device->addr_data );
-
 
162
            if( device->broadcast_data ) free( device->broadcast_data );
-
 
163
        }
-
 
164
    }
-
 
165
    arp_cache_clear( & arp_globals.cache );
-
 
166
    rwlock_write_unlock( & arp_globals.lock );
-
 
167
    printf( "\nCache cleaned" );
-
 
168
    return EOK;
-
 
169
}
-
 
170
 
-
 
171
int arp_device_wrapper( device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address ){
-
 
172
    ERROR_DECLARE;
-
 
173
 
-
 
174
    measured_string_ref tmp;
-
 
175
 
-
 
176
    tmp = measured_string_copy( address );
-
 
177
    if( ERROR_OCCURRED( arp_device_message( device_id, netif, protocol, tmp ))){
-
 
178
        free( tmp->value );
-
 
179
        free( tmp );
-
 
180
    }
-
 
181
    return ERROR_CODE;
-
 
182
}
-
 
183
 
-
 
184
int arp_translate_wrapper( device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data ){
-
 
185
    measured_string_ref tmp;
-
 
186
 
-
 
187
    rwlock_read_lock( & arp_globals.lock );
-
 
188
    tmp = arp_translate_message( device_id, protocol, address );
-
 
189
    if( tmp ){
-
 
190
        * translation = measured_string_copy( tmp );
-
 
191
        rwlock_read_unlock( & arp_globals.lock );
-
 
192
        if( * translation ){
-
 
193
            * data = ( ** translation ).value;
-
 
194
            return EOK;
-
 
195
        }else{
-
 
196
            return ENOMEM;
-
 
197
        }
-
 
198
    }else{
-
 
199
        rwlock_read_unlock( & arp_globals.lock );
-
 
200
        return ENOENT;
-
 
201
    }
-
 
202
}
-
 
203
 
152
int arp_initialize( void ){
204
int arp_initialize( void ){
153
    ERROR_DECLARE;
205
    ERROR_DECLARE;
154
 
206
 
155
    rwlock_initialize( & arp_globals.lock );
207
    rwlock_initialize( & arp_globals.lock );
156
    rwlock_write_lock( & arp_globals.lock );
208
    rwlock_write_lock( & arp_globals.lock );
Line 380... Line 432...
380
        }
432
        }
381
    }
433
    }
382
    return EOK;
434
    return EOK;
383
}
435
}
384
 
436
 
385
int arp_clear_device_message( device_id_t device_id ){
-
 
386
    arp_device_ref  device;
-
 
387
 
-
 
388
    rwlock_write_lock( & arp_globals.lock );
-
 
389
    device = arp_cache_find( & arp_globals.cache, device_id );
-
 
390
    if( ! device ){
-
 
391
        rwlock_write_unlock( & arp_globals.lock );
-
 
392
        return ENOENT;
-
 
393
    }
-
 
394
    clear_device( device );
-
 
395
    printf( "\nDevice %d cleared", device_id );
-
 
396
    rwlock_write_unlock( & arp_globals.lock );
-
 
397
    return EOK;
-
 
398
}
-
 
399
 
-
 
400
void clear_device( arp_device_ref device ){
437
void clear_device( arp_device_ref device ){
401
    int             count;
438
    int             count;
402
    arp_proto_ref   proto;
439
    arp_proto_ref   proto;
403
 
440
 
404
    for( count = arp_protos_count( & device->protos ) - 1; count >= 0; -- count ){
441
    for( count = arp_protos_count( & device->protos ) - 1; count >= 0; -- count ){
Line 410... Line 447...
410
        }
447
        }
411
    }
448
    }
412
    arp_protos_clear( & device->protos );
449
    arp_protos_clear( & device->protos );
413
}
450
}
414
 
451
 
415
int arp_clean_cache_message( void ){
-
 
416
    int             count;
-
 
417
    arp_device_ref  device;
-
 
418
 
-
 
419
    rwlock_write_lock( & arp_globals.lock );
-
 
420
    for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){
-
 
421
        device = arp_cache_get_index( & arp_globals.cache, count );
-
 
422
        if( device ){
-
 
423
            clear_device( device );
-
 
424
            if( device->addr_data ) free( device->addr_data );
-
 
425
            if( device->broadcast_data ) free( device->broadcast_data );
-
 
426
        }
-
 
427
    }
-
 
428
    arp_cache_clear( & arp_globals.cache );
-
 
429
    rwlock_write_unlock( & arp_globals.lock );
-
 
430
    printf( "\nCache cleaned" );
-
 
431
    return EOK;
-
 
432
}
-
 
433
 
-
 
434
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
452
int arp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
435
    ERROR_DECLARE;
453
    ERROR_DECLARE;
436
 
454
 
437
    measured_string_ref address;
455
    measured_string_ref address;
438
    measured_string_ref translation;
456
    measured_string_ref translation;
Line 462... Line 480...
462
            }
480
            }
463
            ERROR_CODE = measured_strings_reply( translation, 1 );
481
            ERROR_CODE = measured_strings_reply( translation, 1 );
464
            rwlock_read_unlock( & arp_globals.lock );
482
            rwlock_read_unlock( & arp_globals.lock );
465
            return ERROR_CODE;
483
            return ERROR_CODE;
466
        case NET_ARP_CLEAR_DEVICE:
484
        case NET_ARP_CLEAR_DEVICE:
467
            return arp_clear_device_message( IPC_GET_DEVICE( call ));
485
            return arp_clear_device_wrapper( IPC_GET_DEVICE( call ));
468
        case NET_ARP_CLEAN_CACHE:
486
        case NET_ARP_CLEAN_CACHE:
469
            return arp_clean_cache_message();
487
            return arp_clean_cache_wrapper();
470
    }
488
    }
471
    return ENOTSUP;
489
    return ENOTSUP;
472
}
490
}
473
 
491
 
474
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ){
492
void arp_receiver( ipc_callid_t iid, ipc_call_t * icall ){