Rev 4731 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4731 | Rev 4743 | ||
---|---|---|---|
Line 47... | Line 47... | ||
47 | #include "../../err.h" |
47 | #include "../../err.h" |
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/crc.h" |
52 | #include "../../include/checksum.h" |
53 | #include "../../include/ethernet_lsap.h" |
53 | #include "../../include/ethernet_lsap.h" |
54 | #include "../../include/ethernet_protocols.h" |
54 | #include "../../include/ethernet_protocols.h" |
55 | #include "../../include/protocol_map.h" |
55 | #include "../../include/protocol_map.h" |
56 | #include "../../include/device.h" |
56 | #include "../../include/device.h" |
57 | #include "../../include/netif_interface.h" |
57 | #include "../../include/netif_interface.h" |
Line 189... | Line 189... | ||
189 | * @returns EOK on success. |
189 | * @returns EOK on success. |
190 | * @returns EEXIST if the device with the different service exists. |
190 | * @returns EEXIST if the device with the different service exists. |
191 | * @returns ENOMEM if there is not enough memory left. |
191 | * @returns ENOMEM if there is not enough memory left. |
192 | * @returns Other error codes as defined for the net_get_device_conf_req() function. |
192 | * @returns Other error codes as defined for the net_get_device_conf_req() function. |
193 | * @returns Other error codes as defined for the netif_bind_service() function. |
193 | * @returns Other error codes as defined for the netif_bind_service() function. |
194 | * @returns Other error codes as defined for the netif_get_addr() function. |
194 | * @returns Other error codes as defined for the netif_get_addr_req() function. |
195 | */ |
195 | */ |
196 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
196 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
197 | 197 | ||
198 | /** Registers receiving module service. |
198 | /** Registers receiving module service. |
199 | * Passes received packets for this service. |
199 | * Passes received packets for this service. |
Line 361... | Line 361... | ||
361 | } |
361 | } |
362 | if( configuration ){ |
362 | if( configuration ){ |
363 | if( ! str_lcmp( configuration[ 0 ].value, "DIX", configuration[ 0 ].length )){ |
363 | if( ! str_lcmp( configuration[ 0 ].value, "DIX", configuration[ 0 ].length )){ |
364 | device->flags |= ETH_DIX; |
364 | device->flags |= ETH_DIX; |
365 | }else if( ! str_lcmp( configuration[ 0 ].value, "8023_2_LSAP", configuration[ 0 ].length )){ |
365 | }else if( ! str_lcmp( configuration[ 0 ].value, "8023_2_LSAP", configuration[ 0 ].length )){ |
366 | // TODO 8023_2_LSAP |
- | |
367 | printf( "8023_2_LSAP is not supported (yet?), DIX used instead\n" ); |
- | |
368 | device->flags |= ETH_DIX; |
366 | device->flags |= ETH_8023_2_LSAP; |
369 | }else device->flags |= ETH_8023_2_SNAP; |
367 | }else device->flags |= ETH_8023_2_SNAP; |
370 | if(( configuration[ 1 ].value ) && ( configuration[ 1 ].value[ 0 ] == 'y' )){ |
368 | if(( configuration[ 1 ].value ) && ( configuration[ 1 ].value[ 0 ] == 'y' )){ |
371 | device->flags |= ETH_DUMMY; |
369 | device->flags |= ETH_DUMMY; |
372 | } |
370 | } |
373 | net_free_settings( configuration, data ); |
371 | net_free_settings( configuration, data ); |
Line 380... | Line 378... | ||
380 | fibril_rwlock_write_unlock( & eth_globals.devices_lock ); |
378 | fibril_rwlock_write_unlock( & eth_globals.devices_lock ); |
381 | free( device ); |
379 | free( device ); |
382 | return device->phone; |
380 | return device->phone; |
383 | } |
381 | } |
384 | // get hardware address |
382 | // get hardware address |
385 | if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
383 | if( ERROR_OCCURRED( netif_get_addr_req( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
386 | fibril_rwlock_write_unlock( & eth_globals.devices_lock ); |
384 | fibril_rwlock_write_unlock( & eth_globals.devices_lock ); |
387 | free( device ); |
385 | free( device ); |
388 | return ERROR_CODE; |
386 | return ERROR_CODE; |
389 | } |
387 | } |
390 | // add to the cache |
388 | // add to the cache |
Line 403... | Line 401... | ||
403 | } |
401 | } |
404 | 402 | ||
405 | eth_proto_ref eth_process_packet( int flags, packet_t packet ){ |
403 | eth_proto_ref eth_process_packet( int flags, packet_t packet ){ |
406 | ERROR_DECLARE; |
404 | ERROR_DECLARE; |
407 | 405 | ||
408 | eth_header_ex_ref header; |
406 | eth_header_snap_ref header; |
409 | size_t length; |
407 | size_t length; |
410 | eth_type_t type; |
408 | eth_type_t type; |
411 | size_t prefix; |
409 | size_t prefix; |
412 | size_t suffix; |
410 | size_t suffix; |
413 | eth_fcs_ref fcs; |
411 | eth_fcs_ref fcs; |
Line 417... | Line 415... | ||
417 | if( IS_DUMMY( flags )){ |
415 | if( IS_DUMMY( flags )){ |
418 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
416 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
419 | } |
417 | } |
420 | if( length < sizeof( eth_header_t ) + ETH_MIN_CONTENT + ( IS_DUMMY( flags ) ? ETH_SUFFIX : 0 )) return NULL; |
418 | if( length < sizeof( eth_header_t ) + ETH_MIN_CONTENT + ( IS_DUMMY( flags ) ? ETH_SUFFIX : 0 )) return NULL; |
421 | data = packet_get_data( packet ); |
419 | data = packet_get_data( packet ); |
422 | header = ( eth_header_ex_ref ) data; |
420 | header = ( eth_header_snap_ref ) data; |
423 | type = ntohs( header->header.ethertype ); |
421 | type = ntohs( header->header.ethertype ); |
424 | if( type >= ETH_MIN_PROTO ){ |
422 | if( type >= ETH_MIN_PROTO ){ |
425 | // DIX Ethernet |
423 | // DIX Ethernet |
426 | prefix = sizeof( eth_header_t ); |
424 | prefix = sizeof( eth_header_t ); |
427 | suffix = 0; |
425 | suffix = 0; |
Line 564... | Line 562... | ||
564 | fibril_rwlock_write_unlock( & eth_globals.protos_lock ); |
562 | fibril_rwlock_write_unlock( & eth_globals.protos_lock ); |
565 | return EOK; |
563 | return EOK; |
566 | } |
564 | } |
567 | 565 | ||
568 | int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype, size_t mtu ){ |
566 | int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype, size_t mtu ){ |
569 | eth_header_ex_ref header; |
567 | eth_header_snap_ref header; |
- | 568 | eth_header_lsap_ref header_lsap; |
|
570 | eth_header_ref header_dix; |
569 | eth_header_ref header_dix; |
571 | eth_fcs_ref fcs; |
570 | eth_fcs_ref fcs; |
572 | uint8_t * src; |
571 | uint8_t * src; |
573 | uint8_t * dest; |
572 | uint8_t * dest; |
574 | size_t length; |
573 | size_t length; |
Line 590... | Line 589... | ||
590 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
589 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
591 | if( ! preamble ) return ENOMEM; |
590 | if( ! preamble ) return ENOMEM; |
592 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
591 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
593 | preamble->sfd = ETH_SFD; |
592 | preamble->sfd = ETH_SFD; |
594 | } |
593 | } |
595 | // TODO LSAP only device |
- | |
596 | if( IS_DIX( flags ) || IS_8023_2_LSAP( flags )){ |
594 | if( IS_DIX( flags )){ |
597 | header_dix = PACKET_PREFIX( packet, eth_header_t ); |
595 | header_dix = PACKET_PREFIX( packet, eth_header_t ); |
598 | if( ! header_dix ) return ENOMEM; |
596 | if( ! header_dix ) return ENOMEM; |
599 | header_dix->ethertype = ( uint16_t ) ethertype; |
597 | header_dix->ethertype = ( uint16_t ) ethertype; |
600 | memcpy( header_dix->source_address, src_addr, ETH_ADDR ); |
598 | memcpy( header_dix->source_address, src_addr, ETH_ADDR ); |
601 | memcpy( header_dix->destination_address, dest, ETH_ADDR ); |
599 | memcpy( header_dix->destination_address, dest, ETH_ADDR ); |
602 | src = & header_dix->destination_address[ 0 ]; |
600 | src = & header_dix->destination_address[ 0 ]; |
- | 601 | }else if( IS_8023_2_LSAP( flags )){ |
|
- | 602 | header_lsap = PACKET_PREFIX( packet, eth_header_lsap_t ); |
|
- | 603 | if( ! header_lsap ) return ENOMEM; |
|
- | 604 | header_lsap->header.ethertype = htons( length + sizeof( eth_header_lsap_t )); |
|
- | 605 | header_lsap->lsap.dsap = lsap_unmap( ntohs( ethertype )); |
|
- | 606 | header_lsap->lsap.ssap = header_lsap->lsap.dsap; |
|
- | 607 | header_lsap->lsap.ctrl = IEEE_8023_2_UI; |
|
- | 608 | memcpy( header_lsap->header.source_address, src_addr, ETH_ADDR ); |
|
- | 609 | memcpy( header_lsap->header.destination_address, dest, ETH_ADDR ); |
|
- | 610 | src = & header_lsap->header.destination_address[ 0 ]; |
|
603 | }else if( IS_8023_2_SNAP( flags )){ |
611 | }else if( IS_8023_2_SNAP( flags )){ |
604 | header = PACKET_PREFIX( packet, eth_header_ex_t ); |
612 | header = PACKET_PREFIX( packet, eth_header_snap_t ); |
605 | if( ! header ) return ENOMEM; |
613 | if( ! header ) return ENOMEM; |
606 | header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
614 | header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
607 | header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
615 | header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
608 | header->lsap.ssap = header->lsap.dsap; |
616 | header->lsap.ssap = header->lsap.dsap; |
609 | header->lsap.ctrl = 0; |
617 | header->lsap.ctrl = IEEE_8023_2_UI; |
610 | for( i = 0; i < 3; ++ i ) header->snap.protocol[ i ] = 0; |
618 | for( i = 0; i < 3; ++ i ) header->snap.protocol[ i ] = 0; |
611 | header->snap.ethertype = ( uint16_t ) ethertype; |
619 | header->snap.ethertype = ( uint16_t ) ethertype; |
612 | memcpy( header->header.source_address, src_addr, ETH_ADDR ); |
620 | memcpy( header->header.source_address, src_addr, ETH_ADDR ); |
613 | memcpy( header->header.destination_address, dest, ETH_ADDR ); |
621 | memcpy( header->header.destination_address, dest, ETH_ADDR ); |
614 | src = & header->header.destination_address[ 0 ]; |
622 | src = & header->header.destination_address[ 0 ]; |