Rev 3886 | Rev 3991 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3886 | Rev 3901 | ||
---|---|---|---|
Line 49... | Line 49... | ||
49 | #include "../../include/protocol_map.h" |
49 | #include "../../include/protocol_map.h" |
50 | #include "../../netif/device.h" |
50 | #include "../../netif/device.h" |
51 | 51 | ||
52 | #include "../../structures/measured_strings.h" |
52 | #include "../../structures/measured_strings.h" |
53 | #include "../../structures/packet/packet.h" |
53 | #include "../../structures/packet/packet.h" |
- | 54 | #include "../../structures/packet/packet_client.h" |
|
54 | 55 | ||
55 | #include "arp.h" |
56 | #include "arp.h" |
56 | #include "arp_header.h" |
57 | #include "arp_header.h" |
57 | #include "arp_oc.h" |
58 | #include "arp_oc.h" |
58 | //#include "arp_messages.h" |
59 | //#include "arp_messages.h" |
59 | #include "arp_module.h" |
60 | #include "arp_module.h" |
60 | 61 | ||
61 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
62 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
- | 63 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
|
62 | #define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
64 | #define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
63 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
65 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
64 | 66 | ||
65 | arp_globals_t arp_globals; |
67 | arp_globals_t arp_globals; |
66 | 68 | ||
Line 145... | Line 147... | ||
145 | } |
147 | } |
146 | device->service = service; |
148 | device->service = service; |
147 | // bind the new one |
149 | // bind the new one |
148 | device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver ); |
150 | device->phone = bind_service( device->service, device->device_id, SERVICE_ARP, 0, arp_receiver ); |
149 | // get packet dimensions |
151 | // get packet dimensions |
150 | if( ERROR_OCCURED( async_req_1_3( device->phone, NET_NIL_PACKET_SPACE, device_id, & device->prefix, & device->content, & device->sufix ))){ |
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 ))){ |
151 | arp_protos_destroy( & device->protos ); |
153 | arp_protos_destroy( & device->protos ); |
152 | free( device ); |
154 | free( device ); |
153 | return ERROR_CODE; |
155 | return ERROR_CODE; |
154 | } |
156 | } |
155 | // get hardware address |
157 | // get hardware address |
Line 214... | Line 216... | ||
214 | // ARP packet content size = header + ( address + translation ) * 2 |
216 | // ARP packet content size = header + ( address + translation ) * 2 |
215 | length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2; |
217 | length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2; |
216 | if( length > device->content ){ |
218 | if( length > device->content ){ |
217 | return NULL; |
219 | return NULL; |
218 | } |
220 | } |
219 | packet = packet_create( device->prefix, length, device->sufix ); |
221 | packet = packet_get_5( arp_globals.networking_phone, SERVICE_ARP, device->addr_len, device->prefix, length, device->sufix ); |
220 | if( ! packet ) return NULL; |
222 | if( ! packet ) return NULL; |
221 | header = ( arp_header_ref ) packet_append( packet, length ); |
223 | header = ( arp_header_ref ) packet_append( packet, length ); |
222 | header->hardware = device->hardware; |
224 | header->hardware = device->hardware; |
223 | header->hardware_length = device->addr->length; |
225 | header->hardware_length = device->addr->length; |
224 | header->protocol = protocol_map( device->service, protocol ); |
226 | header->protocol = protocol_map( device->service, protocol ); |
Line 231... | Line 233... | ||
231 | length += proto->addr->length; |
233 | length += proto->addr->length; |
232 | memset((( uint8_t * ) header ) + length, 0, device->addr->length ); |
234 | memset((( uint8_t * ) header ) + length, 0, device->addr->length ); |
233 | length += device->addr->length; |
235 | length += device->addr->length; |
234 | memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
236 | memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
235 | // TODO send to the device->broadcast_addr as arp protocol |
237 | // TODO send to the device->broadcast_addr as arp protocol |
236 | packet_send( packet, device->phone ); |
238 | async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet )); |
237 | return NULL; |
239 | return NULL; |
238 | } |
240 | } |
239 | 241 | ||
240 | int arp_receive_message( device_id_t device_id, packet_t packet ){ |
242 | int arp_receive_message( device_id_t device_id, packet_t packet ){ |
241 | ERROR_DECLARE; |
243 | ERROR_DECLARE; |
Line 309... | Line 311... | ||
309 | */ memcpy( des_proto, src_proto, header->protocol_length ); |
311 | */ memcpy( des_proto, src_proto, header->protocol_length ); |
310 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
312 | memcpy( src_proto, proto->addr->value, header->protocol_length ); |
311 | memcpy( src_hw, des_hw, header->hardware_length ); |
313 | memcpy( src_hw, des_hw, header->hardware_length ); |
312 | memcpy( des_hw, hw_source->value, hw_source->length ); |
314 | memcpy( des_hw, hw_source->value, hw_source->length ); |
313 | // TODO send to the hw_source as arp protocol |
315 | // TODO send to the hw_source as arp protocol |
- | 316 | async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet )); |
|
- | 317 | }else{ |
|
314 | packet_send( packet, device->phone ); |
318 | packet_release( arp_globals.networking_phone, packet_get_id( packet )); |
315 | } |
319 | } |
316 | } |
320 | } |
317 | return EOK; |
321 | return EOK; |
318 | } |
322 | } |
319 | 323 | ||
Line 412... | Line 416... | ||
412 | switch( IPC_GET_METHOD( call )){ |
416 | switch( IPC_GET_METHOD( call )){ |
413 | case NET_IL_DEVICE_STATE: |
417 | case NET_IL_DEVICE_STATE: |
414 | //TODO clear device if off? |
418 | //TODO clear device if off? |
415 | break; |
419 | break; |
416 | case NET_IL_RECEIVED: |
420 | case NET_IL_RECEIVED: |
417 | if( ! ERROR_OCCURED( packet_receive( & packet ))){ |
421 | if( ! ERROR_OCCURED( packet_translate( arp_globals.networking_phone, & packet, IPC_GET_PACKET( & call )))){ |
418 | ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( & call ), packet ); |
422 | ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( & call ), packet ); |
419 | } |
423 | } |
420 | ipc_answer_0( callid, ERROR_CODE ); |
424 | ipc_answer_0( callid, ERROR_CODE ); |
421 | break; |
425 | break; |
422 | default: |
426 | default: |