Rev 4243 | Rev 4271 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4261 | ||
---|---|---|---|
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/nil_messages.h" |
|
53 | #include "../../include/protocol_map.h" |
54 | #include "../../include/protocol_map.h" |
54 | 55 | ||
55 | #include "../../structures/measured_strings.h" |
56 | #include "../../structures/measured_strings.h" |
56 | #include "../../structures/packet/packet.h" |
57 | #include "../../structures/packet/packet.h" |
57 | #include "../../structures/packet/packet_client.h" |
58 | #include "../../structures/packet/packet_client.h" |
Line 60... | Line 61... | ||
60 | #include "arp_header.h" |
61 | #include "arp_header.h" |
61 | #include "arp_oc.h" |
62 | #include "arp_oc.h" |
62 | //#include "arp_messages.h" |
63 | //#include "arp_messages.h" |
63 | #include "arp_module.h" |
64 | #include "arp_module.h" |
64 | 65 | ||
65 | /** Returns the device identifier message parameter. |
- | |
66 | */ |
- | |
67 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
- | |
68 | - | ||
69 | /** Returns the packet identifier message parameter. |
- | |
70 | */ |
- | |
71 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
- | |
72 | - | ||
73 | /** Returns the protocol service message parameter. |
66 | /** Returns the protocol service message parameter. |
74 | */ |
67 | */ |
75 | #define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
68 | #define ARP_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
76 | - | ||
77 | /** Returns the device driver service message parameter. |
- | |
78 | */ |
- | |
79 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
- | |
80 | 69 | ||
81 | /** ARP global data. |
70 | /** ARP global data. |
82 | */ |
71 | */ |
83 | arp_globals_t arp_globals; |
72 | arp_globals_t arp_globals; |
84 | 73 | ||
Line 187... | Line 176... | ||
187 | 176 | ||
188 | int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address ){ |
177 | int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address ){ |
189 | ERROR_DECLARE; |
178 | ERROR_DECLARE; |
190 | 179 | ||
191 | arp_device_ref device; |
180 | arp_device_ref device; |
192 | aid_t message; |
- | |
193 | ipc_call_t answer; |
- | |
194 | ipcarg_t result; |
- | |
195 | arp_proto_ref proto; |
181 | arp_proto_ref proto; |
196 | int index; |
182 | int index; |
197 | 183 | ||
198 | rwlock_write_lock( & arp_globals.lock ); |
184 | rwlock_write_lock( & arp_globals.lock ); |
199 | // an existing device? |
185 | // an existing device? |
Line 217... | Line 203... | ||
217 | } |
203 | } |
218 | index = arp_protos_add( & device->protos, proto->service, proto ); |
204 | index = arp_protos_add( & device->protos, proto->service, proto ); |
219 | if( index < 0 ){ |
205 | if( index < 0 ){ |
220 | rwlock_write_unlock( & arp_globals.lock ); |
206 | rwlock_write_unlock( & arp_globals.lock ); |
221 | free( proto ); |
207 | free( proto ); |
222 | return result; |
208 | return index; |
223 | } |
209 | } |
224 | } |
210 | } |
225 | printf( "\nCache of the existing device %d cleaned", device->device_id ); |
211 | printf( "\nCache of the existing device %d cleaned", device->device_id ); |
226 | }else{ |
212 | }else{ |
227 | index = hardware_map( service ); |
213 | index = hardware_map( service ); |
Line 255... | Line 241... | ||
255 | arp_protos_destroy( & device->protos ); |
241 | arp_protos_destroy( & device->protos ); |
256 | free( device ); |
242 | free( device ); |
257 | return EREFUSED; |
243 | return EREFUSED; |
258 | } |
244 | } |
259 | // get packet dimensions |
245 | // get packet dimensions |
260 | if( ERROR_OCCURRED( async_req_1_4( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){ |
246 | if( ERROR_OCCURRED( nil_packet_size_req( device->phone, device_id, & device->addr_len, & device->prefix, & device->content, & device->suffix ))){ |
261 | rwlock_write_unlock( & arp_globals.lock ); |
247 | rwlock_write_unlock( & arp_globals.lock ); |
262 | arp_protos_destroy( & device->protos ); |
248 | arp_protos_destroy( & device->protos ); |
263 | free( device ); |
249 | free( device ); |
264 | return ERROR_CODE; |
250 | return ERROR_CODE; |
265 | } |
251 | } |
266 | // get hardware address |
252 | // get hardware address |
267 | message = async_send_1( device->phone, NET_NIL_ADDR, device->device_id, & answer ); |
- | |
268 | if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){ |
253 | if( ERROR_OCCURRED( nil_get_addr( device->phone, device_id, & device->addr, & device->addr_data ))){ |
269 | rwlock_write_unlock( & arp_globals.lock ); |
254 | rwlock_write_unlock( & arp_globals.lock ); |
270 | arp_protos_destroy( & device->protos ); |
255 | arp_protos_destroy( & device->protos ); |
271 | free( device ); |
256 | free( device ); |
272 | async_wait_for( message, NULL ); |
- | |
273 | return ERROR_CODE; |
- | |
274 | } |
- | |
275 | async_wait_for( message, & result ); |
- | |
276 | if( ERROR_OCCURRED( result )){ |
- | |
277 | rwlock_write_unlock( & arp_globals.lock ); |
- | |
278 | free( device->addr ); |
- | |
279 | free( device->addr_data ); |
- | |
280 | arp_protos_destroy( & device->protos ); |
- | |
281 | free( device ); |
- | |
282 | return ERROR_CODE; |
257 | return ERROR_CODE; |
283 | } |
258 | } |
284 | // get broadcast address |
259 | // get broadcast address |
285 | message = async_send_1( device->phone, NET_NIL_BROADCAST_ADDR, device->device_id, & answer ); |
- | |
286 | if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->broadcast_addr, & device->broadcast_data, 1 ))){ |
260 | if( ERROR_OCCURRED( nil_get_broadcast_addr( device->phone, device_id, & device->broadcast_addr, & device->broadcast_data ))){ |
287 | rwlock_write_unlock( & arp_globals.lock ); |
261 | rwlock_write_unlock( & arp_globals.lock ); |
288 | free( device->addr ); |
262 | free( device->addr ); |
289 | free( device->addr_data ); |
263 | free( device->addr_data ); |
290 | arp_protos_destroy( & device->protos ); |
264 | arp_protos_destroy( & device->protos ); |
291 | free( device ); |
265 | free( device ); |
292 | async_wait_for( message, NULL ); |
- | |
293 | return ERROR_CODE; |
266 | return ERROR_CODE; |
294 | } |
267 | } |
295 | async_wait_for( message, & result ); |
- | |
296 | // add to the cache |
- | |
297 | if( ERROR_OCCURRED( result ) |
- | |
298 | || ERROR_OCCURRED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){ |
268 | if( ERROR_OCCURRED( arp_cache_add( & arp_globals.cache, device->device_id, device ))){ |
299 | rwlock_write_unlock( & arp_globals.lock ); |
269 | rwlock_write_unlock( & arp_globals.lock ); |
300 | free( device->addr ); |
270 | free( device->addr ); |
301 | free( device->addr_data ); |
271 | free( device->addr_data ); |
302 | free( device->broadcast_addr ); |
272 | free( device->broadcast_addr ); |
303 | free( device->broadcast_data ); |
273 | free( device->broadcast_data ); |
Line 344... | Line 314... | ||
344 | length += proto->addr->length; |
314 | length += proto->addr->length; |
345 | bzero((( uint8_t * ) header ) + length, device->addr->length ); |
315 | bzero((( uint8_t * ) header ) + length, device->addr->length ); |
346 | length += device->addr->length; |
316 | length += device->addr->length; |
347 | memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
317 | memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
348 | packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length )); |
318 | packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length )); |
349 | async_msg_3( device->phone, NET_NIL_SEND, device_id, packet_get_id( packet ), SERVICE_ARP ); |
319 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
350 | return NULL; |
320 | return NULL; |
351 | } |
321 | } |
352 | 322 | ||
353 | int arp_receive_message( device_id_t device_id, packet_t packet ){ |
323 | int arp_receive_message( device_id_t device_id, packet_t packet ){ |
354 | ERROR_DECLARE; |
324 | ERROR_DECLARE; |
Line 402... | Line 372... | ||
402 | memcpy( des_proto, src_proto, header->protocol_length ); |
372 | memcpy( des_proto, src_proto, header->protocol_length ); |
403 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
373 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
404 | memcpy( src_hw, des_hw, header->hardware_length ); |
374 | memcpy( src_hw, des_hw, header->hardware_length ); |
405 | memcpy( des_hw, hw_source->value, header->hardware_length ); |
375 | memcpy( des_hw, hw_source->value, header->hardware_length ); |
406 | packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
376 | packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
407 | async_msg_3( device->phone, NET_NIL_SEND, device_id, packet_get_id( packet ), SERVICE_ARP ); |
377 | nil_send_msg( device->phone, device_id, packet, SERVICE_ARP ); |
408 | }else{ |
378 | }else{ |
409 | pq_release( arp_globals.networking_phone, packet_get_id( packet )); |
379 | pq_release( arp_globals.networking_phone, packet_get_id( packet )); |
410 | } |
380 | } |
411 | } |
381 | } |
412 | return EOK; |
382 | return EOK; |
Line 473... | Line 443... | ||
473 | switch( IPC_GET_METHOD( * call )){ |
443 | switch( IPC_GET_METHOD( * call )){ |
474 | case IPC_M_PHONE_HUNGUP: |
444 | case IPC_M_PHONE_HUNGUP: |
475 | return EOK; |
445 | return EOK; |
476 | case NET_ARP_DEVICE: |
446 | case NET_ARP_DEVICE: |
477 | ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
447 | ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
478 | if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_PROTO( call ), address ))){ |
448 | if( ERROR_OCCURRED( arp_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), ARP_GET_PROTO( call ), address ))){ |
479 | free( address ); |
449 | free( address ); |
480 | free( data ); |
450 | free( data ); |
481 | } |
451 | } |
482 | return ERROR_CODE; |
452 | return ERROR_CODE; |
483 | case NET_ARP_TRANSLATE: |
453 | case NET_ARP_TRANSLATE: |
484 | ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
454 | ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
485 | rwlock_read_lock( & arp_globals.lock ); |
455 | rwlock_read_lock( & arp_globals.lock ); |
486 | translation = arp_translate_message( IPC_GET_DEVICE( call ), IPC_GET_PROTO( call ), address ); |
456 | translation = arp_translate_message( IPC_GET_DEVICE( call ), ARP_GET_PROTO( call ), address ); |
487 | free( address ); |
457 | free( address ); |
488 | free( data ); |
458 | free( data ); |
489 | if( ! translation ){ |
459 | if( ! translation ){ |
490 | rwlock_read_unlock( & arp_globals.lock ); |
460 | rwlock_read_unlock( & arp_globals.lock ); |
491 | return ENOENT; |
461 | return ENOENT; |