/branches/network/uspace/srv/net/nil/ethernet |
---|
Property changes: |
Deleted: svn:mergeinfo |
/branches/network/uspace/srv/net/nil/eth/eth.c |
---|
0,0 → 1,430 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup eth |
* @{ |
*/ |
/** @file |
* Ethernet module implementation. |
* @see eth.h |
*/ |
#include <async.h> |
#include <malloc.h> |
#include <stdio.h> |
#include <string.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../include/byteorder.h" |
#include "../../include/ethernet_protocols.h" |
#include "../../include/protocol_map.h" |
#include "../../netif/device.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet.h" |
#include "../../structures/packet/packet_client.h" |
#include "eth.h" |
#include "eth_header.h" |
//#include "eth_messages.h" |
#include "eth_module.h" |
#define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
#define ETH_SUFFIX 4 |
#define ETH_MAX_CONTENT ( ETH_MIN_PROTO - 1 ) |
#define ETH_MIN_CONTENT 46 |
#define ETH_PADDING ETH_SUFFIX |
/** Returns the device identifier message parameter. |
*/ |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
/** Returns the packet identifier message parameter. |
*/ |
#define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
/** Returns the protocol service message parameter. |
*/ |
#define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG1( * call ) |
/** Returns the device driver service message parameter. |
*/ |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG3( * call ) |
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
#define IPC_SET_ADDR( answer ) (( size_t * ) & IPC_GET_ARG1( * answer )) |
#define IPC_SET_PREFIX( answer ) (( size_t * ) & IPC_GET_ARG2( * answer )) |
#define IPC_SET_CONTENT( answer ) (( size_t * ) & IPC_GET_ARG3( * answer )) |
#define IPC_SET_SUFFIX( answer ) (( size_t * ) & IPC_GET_ARG4( * answer )) |
typedef enum eth_addr_type eth_addr_type_t; |
typedef eth_addr_type_t * eth_addr_type_ref; |
enum eth_addr_type{ |
ETH_LOCAL_ADDR, |
ETH_BROADCAST_ADDR |
}; |
/** Ethernet global data. |
*/ |
eth_globals_t eth_globals; |
/** Processes IPC messages from the registered device driver modules in an infinite loop. |
* @param iid The message identifier. Input parameter. |
* @param icall The message parameters. Input/output parameter. |
*/ |
void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
DEVICE_MAP_IMPLEMENT( eth_devices, eth_device_t ) |
INT_MAP_IMPLEMENT( eth_protos, eth_proto_t ) |
int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
int eth_receive_message( device_id_t device_id, packet_t packet ); |
int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ); |
int eth_register_message( services_t service, int phone ); |
int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
int eth_initialize( void ){ |
ERROR_DECLARE; |
rwlock_initialize( & eth_globals.devices_lock ); |
rwlock_initialize( & eth_globals.protos_lock ); |
rwlock_write_lock( & eth_globals.devices_lock ); |
rwlock_write_lock( & eth_globals.protos_lock ); |
eth_globals.broadcast_addr = measured_string_create_bulk( "\xFF\xFF\xFF\xFF\xFF\xFF", CONVERT_SIZE( uint8_t, char, ETH_ADDR )); |
if( ! eth_globals.broadcast_addr ) return ENOMEM; |
ERROR_PROPAGATE( eth_devices_initialize( & eth_globals.devices )); |
if( ERROR_OCCURRED( eth_protos_initialize( & eth_globals.protos ))){ |
eth_devices_destroy( & eth_globals.devices ); |
return ERROR_CODE; |
} |
rwlock_write_unlock( & eth_globals.protos_lock ); |
rwlock_write_unlock( & eth_globals.devices_lock ); |
return EOK; |
} |
int eth_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
ERROR_DECLARE; |
aid_t message; |
ipc_call_t answer; |
eth_device_ref device; |
int result; |
rwlock_write_lock( & eth_globals.devices_lock ); |
// an existing device? |
device = eth_devices_find( & eth_globals.devices, device_id ); |
if( device ){ |
if( device->service == service ){ |
// update mtu |
device->mtu = mtu; |
rwlock_write_unlock( & eth_globals.devices_lock ); |
return EOK; |
}else{ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
return EEXIST; |
} |
}else{ |
// create a new device |
device = ( eth_device_ref ) malloc( sizeof( eth_device_t )); |
if( ! device ) return ENOMEM; |
device->device_id = device_id; |
device->service = service; |
device->mtu = mtu; |
// bind the device driver |
device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver ); |
// get hardware address |
message = async_send_1( device->phone, NET_NETIF_GET_ADDR, device->device_id, & answer ); |
if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
free( device ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, ( ipcarg_t * ) & result ); |
if( ERROR_OCCURRED( result )){ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
free( device->addr ); |
free( device->addr_data ); |
free( device ); |
return ERROR_CODE; |
} |
// add to the cache |
if( ERROR_OCCURRED( eth_devices_add( & eth_globals.devices, device->device_id, device ))){ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
free( device->addr ); |
free( device->addr_data ); |
free( device ); |
return ERROR_CODE; |
} |
} |
rwlock_write_unlock( & eth_globals.devices_lock ); |
return EOK; |
} |
int eth_receive_message( device_id_t device_id, packet_t packet ){ |
ERROR_DECLARE; |
eth_header_ex_ref header; |
size_t length; |
int type; |
eth_proto_ref proto; |
size_t size; |
length = packet_get_data_length( packet ); |
if( length <= sizeof( eth_header_t ) + ETH_MIN_CONTENT + ETH_PADDING ) return EINVAL; |
// TODO check CRC padding? |
header = ( eth_header_ex_ref ) packet_get_data( packet ); |
type = ntohs( header->header.ethertype ); |
if( type >= ETH_MIN_PROTO ){ |
// DIX Ethernet |
size = sizeof( eth_header_t ); |
}else{ |
// TODO check length? |
// translate "LSAP" values |
if(( header->lsap.dsap == ETH_RAW ) && ( header->lsap.ssap == ETH_RAW )){ |
// raw packet |
// discard |
return EINVAL; |
}else if(( header->lsap.dsap == ETH_LSAP_SNAP ) && ( header->lsap.ssap == ETH_LSAP_SNAP )){ |
// IEEE 802.3 SNAP |
// organization code not supported |
type = ntohs( header->snap.ethertype ); |
size = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t) + sizeof( eth_header_snap_t); |
}else{ |
// IEEE 802.3 + 802.2 LSAP |
// TODO lsap numbers |
type = header->lsap.dsap; |
size = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t); |
} |
} |
rwlock_write_lock( & eth_globals.protos_lock ); |
proto = eth_protos_find( & eth_globals.protos, type ); |
if( ! proto ){ |
rwlock_write_unlock( & eth_globals.protos_lock ); |
return ENOENT; |
} |
if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
|| ERROR_OCCURRED( packet_trim( packet, size, ETH_PADDING ))){ |
rwlock_write_unlock( & eth_globals.protos_lock ); |
return ERROR_CODE; |
} |
async_msg_2( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet )); |
rwlock_write_unlock( & eth_globals.protos_lock ); |
return EOK; |
} |
int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
eth_device_ref device; |
if( !( addr_len && prefix && content && suffix )) return EINVAL; |
rwlock_write_lock( & eth_globals.devices_lock ); |
device = eth_devices_find( & eth_globals.devices, device_id ); |
if( ! device ){ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
return ENOENT; |
} |
* content = ( ETH_MAX_CONTENT > device->mtu ) ? device->mtu : ETH_MAX_CONTENT; |
rwlock_write_unlock( & eth_globals.devices_lock ); |
* addr_len = ETH_ADDR; |
* prefix = ETH_PREFIX; |
* suffix = ETH_SUFFIX; |
return EOK; |
} |
int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ){ |
eth_device_ref device; |
if( ! address ) return EINVAL; |
if( type == ETH_BROADCAST_ADDR ){ |
* address = eth_globals.broadcast_addr; |
}else{ |
rwlock_write_lock( & eth_globals.devices_lock ); |
device = eth_devices_find( & eth_globals.devices, device_id ); |
if( ! device ){ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
return ENOENT; |
} |
* address = device->addr; |
rwlock_write_unlock( & eth_globals.devices_lock ); |
} |
return ( * address ) ? EOK : ENOENT; |
} |
int eth_register_message( services_t service, int phone ){ |
ERROR_DECLARE; |
eth_proto_ref proto; |
int protocol; |
protocol = protocol_map( SERVICE_ETHERNET, service ); |
if( ! protocol ) return ENOENT; |
rwlock_write_lock( & eth_globals.protos_lock ); |
proto = eth_protos_find( & eth_globals.protos, protocol ); |
if( proto ){ |
proto->phone = phone; |
rwlock_write_unlock( & eth_globals.protos_lock ); |
return EOK; |
}else{ |
proto = ( eth_proto_ref ) malloc( sizeof( eth_proto_t )); |
if( ! proto ){ |
rwlock_write_unlock( & eth_globals.protos_lock ); |
return ENOMEM; |
} |
proto->service = service; |
proto->protocol = protocol; |
proto->phone = phone; |
if( ERROR_OCCURRED( eth_protos_add( & eth_globals.protos, protocol, proto ))){ |
rwlock_write_unlock( & eth_globals.protos_lock ); |
free( proto ); |
return ERROR_CODE; |
} |
} |
rwlock_write_unlock( & eth_globals.protos_lock ); |
return EOK; |
} |
int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
ERROR_DECLARE; |
eth_device_ref device; |
eth_header_ex_ref header; |
uint8_t * src; |
uint8_t * dest; |
int length; |
int i; |
header = PACKET_PREFIX( packet, eth_header_ex_t ); |
if( ! header ) return ENOMEM; |
for( i = 0; i < 7; ++ i ) header->header.preamble[ i ] = ETH_PREAMBLE; |
header->header.sfd = ETH_SFD; |
length = packet_get_addr( packet, & src, & dest ); |
if( length < 0 ) return length; |
if( length < ETH_ADDR ) return EINVAL; |
// TODO src set? |
// TODO set addresses |
length = packet_get_data_length( packet ); |
if( length > ETH_MAX_CONTENT ) return EINVAL; |
if( length < ETH_MIN_CONTENT ){ |
// TODO pad zeros |
} |
header->header.ethertype = htons( length ); |
header->lsap.dsap = 0xAA; |
header->lsap.ssap = header->lsap.dsap; |
header->lsap.ctrl = 0; |
for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
header->snap.ethertype = htons( protocol_map( SERVICE_ETHERNET, sender )); |
if( ! header ) return ENOENT; |
// TODO eth padding |
if( ! packet_suffix( packet, ETH_PADDING )){ |
return ENOMEM; |
} |
rwlock_write_lock( & eth_globals.devices_lock ); |
rwlock_write_unlock( & eth_globals.devices_lock ); |
return EOK; |
} |
int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
ERROR_DECLARE; |
measured_string_ref address; |
packet_t packet; |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NIL_DEVICE: |
return eth_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_MTU( call )); |
case NET_NIL_SEND: |
ERROR_PROPAGATE( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
return eth_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
case NET_NIL_PACKET_SPACE: |
ERROR_PROPAGATE( eth_packet_space_message( IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); |
* answer_count = 3; |
return EOK; |
case NET_NIL_ADDR: |
rwlock_read_lock( & eth_globals.devices_lock ); |
if( ! ERROR_OCCURRED( eth_addr_message( IPC_GET_DEVICE( call ), ETH_LOCAL_ADDR, & address ))){ |
ERROR_CODE = measured_strings_reply( address, 1 ); |
} |
rwlock_read_unlock( & eth_globals.devices_lock ); |
return ERROR_CODE; |
case NET_NIL_BROADCAST_ADDR: |
rwlock_read_lock( & eth_globals.devices_lock ); |
if( ! ERROR_OCCURRED( eth_addr_message( IPC_GET_DEVICE( call ), ETH_BROADCAST_ADDR, & address ))){ |
ERROR_CODE = measured_strings_reply( address, 1 ); |
} |
rwlock_read_unlock( & eth_globals.devices_lock ); |
return ERROR_CODE; |
case IPC_M_CONNECT_TO_ME: |
return eth_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
} |
return ENOTSUP; |
} |
void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
ERROR_DECLARE; |
packet_t packet; |
while( true ){ |
switch( IPC_GET_METHOD( * icall )){ |
case NET_NIL_DEVICE_STATE: |
//TODO clear device if off? |
break; |
case NET_NIL_RECEIVED: |
if( ! ERROR_OCCURRED( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){ |
ERROR_CODE = eth_receive_message( IPC_GET_DEVICE( icall ), packet ); |
} |
ipc_answer_0( iid, ERROR_CODE ); |
break; |
default: |
ipc_answer_0( iid, ENOTSUP ); |
} |
iid = async_get_call( icall ); |
} |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/eth/eth.h |
---|
0,0 → 1,149 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup eth |
* @{ |
*/ |
/** |
* @file |
*/ |
#ifndef __NET_ETH_H__ |
#define __NET_ETH_H__ |
#include <rwlock.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../include/sockaddr.h" |
#include "../../netif/device.h" |
#include "../../structures/measured_strings.h" |
/** Type definition of the Ethernet global data. |
* @see eth_globals |
*/ |
typedef struct eth_globals eth_globals_t; |
/** Type definition of the Ethernet device specific data. |
* @see eth_device |
*/ |
typedef struct eth_device eth_device_t; |
/** Type definition of the Ethernet device specific data pointer. |
* @see eth_device |
*/ |
typedef eth_device_t * eth_device_ref; |
/** Type definition of the Ethernet protocol specific data. |
* @see eth_proto |
*/ |
typedef struct eth_proto eth_proto_t; |
/** Type definition of the Ethernet protocol specific data pointer. |
* @see eth_proto |
*/ |
typedef eth_proto_t * eth_proto_ref; |
/** Ethernet address cache. |
* Maps devices to the Ethernet device specific data. |
* @see device.h |
*/ |
DEVICE_MAP_DECLARE( eth_devices, eth_device_t ) |
/** Ethernet protocol map. |
* Maps protocol identifiers to the Ethernet protocol specific data. |
* @see int_map.h |
*/ |
INT_MAP_DECLARE( eth_protos, eth_proto_t ) |
/** Ethernet device specific data. |
*/ |
struct eth_device{ |
/** Device identifier. |
*/ |
device_id_t device_id; |
/** Device driver service. |
*/ |
services_t service; |
/** Driver phone. |
*/ |
int phone; |
/** Maximal transmission unit. |
*/ |
size_t mtu; |
/** Actual device hardware address. |
*/ |
measured_string_ref addr; |
/** Actual device hardware address data. |
*/ |
char * addr_data; |
}; |
/** Ethernet protocol specific data. |
*/ |
struct eth_proto{ |
/** Protocol service. |
*/ |
services_t service; |
/** Protocol identifier. |
*/ |
int protocol; |
/** Protocol module phone. |
*/ |
int phone; |
}; |
/** Ethernet global data. |
*/ |
struct eth_globals{ |
/** Networking module phone. |
*/ |
int networking_phone; |
/** Safety lock for devices. |
*/ |
rwlock_t devices_lock; |
/** All known Ethernet devices. |
*/ |
eth_devices_t devices; |
/** Safety lock for protocols. |
*/ |
rwlock_t protos_lock; |
/** Protocol map. |
* Service phone map for each protocol. |
*/ |
eth_protos_t protos; |
/** Broadcast device hardware address. |
*/ |
measured_string_ref broadcast_addr; |
}; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/eth/eth_module.c |
---|
0,0 → 1,82 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup eth |
* @{ |
*/ |
/** @file |
*/ |
#include <async.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include "../../err.h" |
#include "../../modules.h" |
#include "../../structures/packet/packet.h" |
#include "eth.h" |
#include "eth_module.h" |
#define NAME "Ethernet protocol" |
void eth_print_name( void ); |
int eth_start_module( async_client_conn_t client_connection ); |
extern eth_globals_t eth_globals; |
void eth_print_name( void ){ |
printf( NAME ); |
} |
int eth_start_module( async_client_conn_t client_connection ){ |
ERROR_DECLARE; |
ipcarg_t phonehash; |
async_set_client_connection( client_connection ); |
eth_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
ERROR_PROPAGATE( pm_init()); |
if( ERROR_OCCURRED( eth_initialize()) |
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_ETHERNET, & phonehash ))){ |
pm_destroy(); |
return ERROR_CODE; |
} |
async_manager(); |
pm_destroy(); |
return EOK; |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/eth/eth_module.h |
---|
0,0 → 1,47 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup eth |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __NET_ETH_MODULE_H__ |
#define __NET_ETH_MODULE_H__ |
#include <ipc/ipc.h> |
int eth_initialize( void ); |
int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/eth/Makefile |
---|
0,0 → 1,46 |
# |
# Copyright (c) 2009 Lukas Mejdrech |
# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
# modification, are permitted provided that the following conditions |
# are met: |
# |
# - Redistributions of source code must retain the above copyright |
# notice, this list of conditions and the following disclaimer. |
# - Redistributions in binary form must reproduce the above copyright |
# notice, this list of conditions and the following disclaimer in the |
# documentation and/or other materials provided with the distribution. |
# - The name of the author may not be used to endorse or promote products |
# derived from this software without specific prior written permission. |
# |
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
# |
NAME = eth |
NET_BASE = ../../ |
STRUCTURES = $(NET_BASE)structures/ |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME)_module.c \ |
$(NAME).c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(STRUCTURES)measured_strings.c \ |
$(STRUCTURES)packet/packet.c \ |
$(STRUCTURES)packet/packet_client.c |
NET_DEFS += -D ETH_BUNDLE=1 |
include $(NET_BASE)Makefile.module |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/eth/eth_header.h |
---|
0,0 → 1,164 |
/* |
* Copyright (c) 2009 Lukas Mejdrech |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup eth |
* @{ |
*/ |
/** @file |
* Ethernet protocol header definitions. |
* Names according to the linux src/include/linux/ip.h header file. |
*/ |
#ifndef __NET_ETH_HEADER_H__ |
#define __NET_ETH_HEADER_H__ |
#include <sys/types.h> |
#define ETH_ADDR 6 |
#define ETH_PREAMBLE 0x55 |
#define ETH_SFD 0xF5 |
#define ETH_LSAP_SNAP 0xAA |
#define ETH_RAW 0xFF |
/** Type definition of the Ethernet header with all the extensions. |
* @see eth_header_ex |
*/ |
typedef struct eth_header_ex eth_header_ex_t; |
/** Type definition of the Ethernet header with all the extensions pointer. |
* @see eth_header |
*/ |
typedef eth_header_ex_t * eth_header_ex_ref; |
/** Type definition of the Ethernet header LSAP extension. |
* @see eth_header_lsap |
*/ |
typedef struct eth_header_lsap eth_header_lsap_t; |
/** Type definition of the Ethernet header LSAP extension pointer. |
* @see eth_header_lsap |
*/ |
typedef eth_header_lsap_t * eth_header_lsap_ref; |
/** Type definition of the Ethernet header SNAP extension. |
* @see eth_header_snap |
*/ |
typedef struct eth_header_snap eth_header_snap_t; |
/** Type definition of the Ethernet header SNAP extension pointer. |
* @see eth_header_snap |
*/ |
typedef eth_header_snap_t * eth_header_snap_ref; |
/** Type definition of the Ethernet header. |
* @see eth_header |
*/ |
typedef struct eth_header eth_header_t; |
/** Type definition of the Ethernet header pointer. |
* @see eth_header |
*/ |
typedef eth_header_t * eth_header_ref; |
/** Ethernet header Link Service Access Point extension. |
*/ |
struct eth_header_lsap{ |
/** Destination Service Access Point identifier. |
* The possible values are assigned by an IEEE committee. |
*/ |
uint8_t dsap; |
/** Source Service Access Point identifier. |
* The possible values are assigned by an IEEE committee. |
*/ |
uint8_t ssap; |
/** Control parameter. |
* The possible values are assigned by an IEEE committee. |
*/ |
uint8_t ctrl; |
}; |
/** Ethernet header SNAP extension. |
*/ |
struct eth_header_snap{ |
/** Protocol identifier or organization code. |
*/ |
uint8_t proto[ 3 ]; |
/** Ethernet protocol identifier in the network byte order (big endian). |
* @see ethernet_protocols.h |
*/ |
uint16_t ethertype; |
}; |
/** Ethernet header. |
*/ |
struct eth_header{ |
/** Controlling preamble used for the frame transmission synchronization. |
* All should be set to ETH_PREAMBLE. |
*/ |
uint8_t preamble[ 7 ]; |
/** Start of Frame Delimiter used for the frame transmission synchronization. |
* Should be set to ETH_SFD. |
*/ |
uint8_t sfd; |
/** Destination host Ethernet address (MAC address). |
*/ |
uint8_t dest[ ETH_ADDR ]; |
/** Source host Ethernet address (MAC address). |
*/ |
uint8_t src[ ETH_ADDR ]; |
/** Ethernet protocol identifier in the network byte order (big endian). |
* @see ethernet_protocols.h |
*/ |
uint16_t ethertype; |
}; |
/** Ethernet header with all the extensions. |
*/ |
struct eth_header_ex{ |
/** Ethernet header. |
*/ |
eth_header_t header; |
/** LSAP extension. |
* If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being used. |
* If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet without any extensions is being used and the frame content starts rigth after the two fields. |
*/ |
eth_header_lsap_t lsap; |
/** SNAP extension. |
*/ |
eth_header_snap_t snap; |
}; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/nil/eth |
---|
Property changes: |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/include/ethernet_protocols.h |
---|
38,6 → 38,10 |
#ifndef __NET_ETHERNET_PROTOCOLS_H__ |
#define __NET_ETHERNET_PROTOCOLS_H__ |
/** Ethernet minimal protocol number. |
*/ |
#define ETH_MIN_PROTO 1501 |
/** Ethernet loopback packet protocol type. |
*/ |
#define ETH_P_LOOP 0x0060 |
/branches/network/uspace/srv/net/Makefile |
---|
1,5 → 1,5 |
# |
# Copyright (c) 2005 Martin Decky |
# Copyright (c) 2009 Lukas Mejdrech |
# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
36,7 → 36,7 |
DIRS_MODULAR = il/ip \ |
tl/tcp \ |
il/arp \ |
# nil/ethernet \ |
nil/eth \ |
# il/rarp \ |
# il/icmp \ |
# tl/udp \ |
/branches/network/boot/arch/ia32/Makefile.inc |
---|
58,12 → 58,12 |
ifeq ($(NETWORKING), modular) |
RD_TASKS += $(USPACEDIR)/srv/net/il/ip/ip \ |
$(USPACEDIR)/srv/net/tl/tcp/tcp \ |
$(USPACEDIR)/srv/net/il/arp/arp |
$(USPACEDIR)/srv/net/il/arp/arp \ |
$(USPACEDIR)/srv/net/nil/eth/eth |
# $(USPACEDIR)/srv/net/il/rarp/rarp \ |
# $(USPACEDIR)/srv/net/il/icmp/icmp \ |
# $(USPACEDIR)/srv/net/tl/udp/udp \ |
# $(USPACEDIR)/srv/net/socket \ |
# $(USPACEDIR)/srv/net/nil/ethernet/ethernet |
# $(USPACEDIR)/srv/net/socket |
endif |
build: $(BASE)/image.iso |