Subversion Repositories HelenOS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 3845 → Rev 3846

/branches/network/uspace/srv/net/ip/ip_module.h
0,0 → 1,48
/*
* Copyright (c) 2008 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 net
* @{
*/
 
/**
* @file
*/
 
#ifndef __NET_IP_MODULE_H__
#define __NET_IP_MODULE_H__
 
#include <ipc/ipc.h>
 
int ip_initialize( void );
int ip_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/ip/ip_messages.h
0,0 → 1,91
/*
* Copyright (c) 2008 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 net
* @{
*/
 
/**
* @file
*/
 
#ifndef __NET_IP_MESSAGES_H__
#define __NET_IP_MESSAGES_H__
 
#include <ipc/ipc.h>
 
#include "../err.h"
#include "../messages.h"
#include "../packet.h"
 
#if IP_BUNDLE
 
int ip_device_message( device_id_t device_id, services_t service );
int ip_echo_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t * res1, ipcarg_t * res2, ipcarg_t * res3, ipcarg_t * res4, ipcarg_t * res5 );
int ip_send_message( device_id_t device_id, packet_t packet );
 
#define ip_device( ip_phone, device_id, service ) \
ip_device_message(( device_id ), ( service ))
 
#define ip_echo( ip_phone, arg1, arg2, arg3, arg4, arg5, answer1, answer2, answer3, answer4, answer5 ) \
ip_echo_message(( arg1 ), ( arg2 ), ( arg3 ), ( arg4 ), ( arg5 ), ( answer1 ), ( answer2 ), ( answer3 ), ( answer4 ), ( answer5 ))
 
#define ip_send( ip_phone, device_id, packet ) \
ip_send_message(( device_id ), ( packet ));
#else
 
#define ip_device( ip_phone, device_id, service ) \
ipc_sync_send_2_0( ip_phone, NET_IP_DEVICE, ( device_id ), ( service ))
 
#define ip_echo( ip_phone, arg1, arg2, arg3, arg4, arg5, answer1, answer2, answer3, answer4, answer5 ) \
async_req_5_5( ip_phone, NET_IP_ECHO, ( arg1 ), ( arg2 ), ( arg3 ), ( arg4 ), ( arg5 ), ( answer1 ), ( answer2 ), ( answer3 ), ( answer4 ), ( answer5 ))
 
#define ip_send( ip_phone, device_id, packet ) \
{ \
ERROR_DECLARE; \
\
aid_t message; \
ipc_call_t answer; \
ipcarg_t result; \
\
message = async_send_1(( ip_phone ), NET_IP_SEND, ( device_id ), & answer ); \
if( ERROR_OCCURED( packet_send(( packet ), ( ip_phone )))){ \
async_wait_for( message, NULL ); \
result = ERROR_CODE; \
}else{ \
async_wait_for( message, & result ); \
} \
result; \
}
 
#endif
 
#endif
 
/** @}
*/
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/branches/network/uspace/srv/net/ip/ip_header.h
0,0 → 1,260
/*
* Copyright (c) 2008 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 net
* @{
*/
 
/**
* @file
* Interent protocol header and options definitions.
* Names according to the linux src/include/linux/ip.h header file.
*/
 
#ifndef __NET_IP_HEADER_H__
#define __NET_IP_HEADER_H__
 
#include <byteorder.h>
#include <types.h>
 
typedef struct ip_header ip_header_t;
typedef ip_header_t * ip_header_ref;
 
/** Internet header.
* The variable options should be included after the header itself and indicated by the increased header length value.
*/
struct ip_header{
#ifdef ARCH_IS_BIG_ENDIAN
/** The Version field indicates the format of the internet header.
*/
uint8_t:4 version;
/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
* Note that the minimum value for a~correct header is~5.
*/
uint8_t:4 ihl;
#else
/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
* Note that the minimum value for a~correct header is~5.
*/
uint8_t:4 ihl;
/** The Version field indicates the format of the internet header.
*/
uint8_t:4 version;
#endif
/** The Type of Service provides an indication of the abstract parameters of the quality of service desired.
* These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network.
* Several networks offer service precedence, which somehow treats high precedence traffic as more important than other traffic (generally by accepting only traffic above a~certain precedence at time of high load).
* The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput.
*/
uint8_t tos;
/** Total Length is the length of the datagram, measured in octets, including internet header and data.
* This field allows the length of a~datagram to be up to 65,535~octets.
*/
uint16_t total_length;
/** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram.
*/
unit16_t identification;
#ifdef ARCH_IS_BIG_ENDIAN
/** Various control flags.
*/
uint_16:3 flags;
/** This field indicates where in the datagram this fragment belongs.
*/
uint_16:13 fragment_offset;
#else
/** This field indicates where in the datagram this fragment belongs.
*/
uint_16:13 fragment_offset;
/** Various control flags.
*/
uint_16:3 flags;
#endif
/** This field indicates the maximum time the datagram is allowed to remain in the internet system.
* If this field contains the value zero, then the datagram must be destroyed.
* This field is modified in internet header processing.
* The time is measured in units of seconds, but since every module that processes a~datagram must decrease the TTL by at least one even if it process the datagram in less than a~second, the TTL must be thought of only as an upper bound on the time a~datagram may exist.
* The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.
*/
uint8_t ttl;
/** This field indicates the next level protocol used in the data portion of the internet datagram.
*/
uint8_t protocol;
/** A checksum on the header only.
* Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed.
* The checksum algorithm is: The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header.
* For purposes of computing the checksum, the value of the checksum field is zero.
*/
uint16_t header_checksum;
/** The source address.
*/
uint32_t source_address;
/** The destination address.
*/
uint32_t destination_address;
};
 
typedef struct ip_option ip_option_t;
typedef ip_option * ip_option_ref;
 
/** Internet option header.
* Only type field is always valid.
* Other fields' validity depends on the option type.
*/
struct ip_option{
/** A single octet of option-type.
*/
uint8_t type;
/** An option length octet.
*/
uint8_t length;
/** A~pointer.
*/
uint8_t pointer;
#ifdef ARCH_IS_BIG_ENDIAN
/** The number of IP modules that cannot register timestamps due to lack of space.
*/
uint8_t:4 overflow;
/** Various internet timestamp control flags.
*/
uint8_t:4 flags;
#else
/** Various internet timestamp control flags.
*/
uint8_t:4 flags;
/** The number of IP modules that cannot register timestamps due to lack of space.
*/
uint8_t:4 overflow;
#endif
};
 
#define IPTOS_TOS_MASK 0x1E
#define IPTOS_PRECEDENCE_SHIFT 5
#define IPTOS_DELAY_SHIFT 4
#define IPTOS_TROUGHPUT_SHIFT 3
#define IPTOS_RELIABILITY_SHIFT 2
#define IPTOS_COST_SHIFT 1
 
#define IPTOS_NORMALDELAY ( 0x0 << IPTOS_DELAY_SHIFT )
#define IPTOS_LOWDELAY ( 0x1 << IPTOS_DELAY_SHIFT )
 
#define IPTOS_NORMALTHROUGHPUT ( 0x0 << IPTOS_THROUGHPUT_SHIFT )
#define IPTOS_THROUGHPUT ( 0x1 << IPTOS_THROUGHPUT_SHIFT )
 
#define IPTOS_NORMALRELIABILITY ( 0x0 << IPTOS_RELIABILITY_SHIFT )
#define IPTOS_RELIABILITY ( 0x1 << IPTOS_RELIABILITY_SHIFT )
 
#define IPTOS_NORMALCOST ( 0x0 << IPTOS_COST_SHIFT )
#define IPTOS_MICNCOST ( 0x1 << IPTOS_COST_SHIFT )
 
#define IPTOS_PREC_MASK 0xE0
#define IPTOS_PREC_ROUTINE ( 0x0 << IPTOS_PRECEDENCE_SHIFT )
#define IPTOS_PREC_PRIORITY ( 0x1 << IPTOS_PRECEDENCE_SHIFT )
#define IPTOS_PREC_IMMEDIATE ( 0x2 << IPTOS_PRECEDENCE_SHIFT )
#define IPTOS_PREC_FLASH ( 0x3 << IPTOS_PRECEDENCE_SHIFT )
#define IPTOS_PREC_FLASHOVERRIDE ( 0x4 << IPTOS_PRECEDENCE_SHIFT )
#define IPTOS_PREC_CRITIC_ECP ( 0x5 << IPTOS_PRECEDENCE_SHIFT )
#define IPTOS_PREC_INTERNETCONTROL ( 0x6 << IPTOS_PRECEDENCE_SHIFT )
#define IPTOS_PREC_NETCONTROL ( 0x7 << IPTOS_PRECEDENCE_SHIFT )
 
#define IPFLAG_FRAGMENT_SHIFT 1
#define IPFLAG_FRAGMENTED_SHIFT 0
 
#define IPFLAG_MAY_FRAGMENT ( 0x0 << IPFLAG_FRAGMENT_SHIFT )
#define IPFLAG_DONT_FRAGMENT ( 0x1 << IPFLAG_FRAGMENT_SHIFT )
 
#define IPFLAG_LAST_FRAGMENT ( 0x0 << IPFLAG_FRAGMENTED_SHIFT )
#define IPFLAG_MORE_FRAGMENTS ( 0x1 << IPFLAG_FRAGMENTED_SHIFT )
 
#define IPOPT_COPY_SHIFT 7
#define IPOPT_CLASS_SHIFT 5
#define IPOPT_NUMBER_SHIFT 0
#define IPOPT_CLASS_MASK 0x60
#define IPOPT_NUMBER_MASK 0x1F
 
#define IPOPT_COPY ( 1 << IPOPT_COPY_SHIFT )
 
#define IPOPT_TYPE( copy, class, number ) ((( copy ) & IPOPT_COPY ) | (( class ) & IPOPT_CLASS_MASK ) | (( number << IPOPT_NUMBER_SHIFT ) & IPOPT_NUMBER_MASK ))
 
#define IPOPT_COPIED( o ) (( o ) & IPOPT_COPY )
#define IPOPT_CLASS( o ) (( o ) & IPOPT_CLASS_MASK )
#define IPOPT_NUMBER( o ) (( o ) & IPOPT_NUMBER_MASK )
 
#define IPOPT_CONTROL ( 1 << IPOPT_CLASS_SHIFT )
#define IPOPT_RESERVED1 ( 2 << IPOPT_CLASS_SHIFT )
#define IPOPT_MEASUREMENT ( 3 << IPOPT_CLASS_SHIFT )
#define IPOPT_RESERVED2 ( 4 << IPOPT_CLASS_SHIFT )
 
//#define IPOPT_END_OF_LIST 0x0
#define IPOPT_END IPOPT_TYPE( 0, IPOPT_CONTROL, 0 )
//#define IPOPT_NO_OPERATION 0x1
#define IPOPT_NOOP IPOPT_TYPE( 0, IPOPT_CONTROL, 1 )
//#define IPOPT_SECURITY 0x82
#define IPOPT_SEC IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 2 )
#define IPOPT_SEC_LENGTH 11
#define IPOPT_SEC_UNCLASIFIED 0x0
#define IPOPT_SEC_CONFIDENTIAL 0xF035
#define IPOPT_SEC_EFTO 0x789A
#define IPOPT_SEC_MMMM 0xBC4D
#define IPOPT_SEC_PROG 0x5E26
#define IPOPT_SEC_RESTRICTED 0xAF13
#define IPOPT_SEC_SECRET 0xD788
#define IPOPT_SEC_TOP_SECRET 0x6BC5
//#define IPOPT_LOOSE_SOURCE 0x83
#define IPOPT_LSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 3 )
//#define IPOPT_STRICT_SOURCE 0x89
#define IPOPT_SSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 9 )
//#define IPOPT_RECORD_ROUTE 0x07
#define IPOPT_RR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 7 )
//#define IPOPT_STREAM_IDENTIFIER 0x88
#define IPOPT_SID IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 8 )
#define IPOPT_SID_LENGTH 4
//#define IPOPT_INTERNET_TIMESTAMP 0x44
#define IPOPT_TIMESTAMP IPOPT_TYPE( IPOPT_COPY, IPOPT_MEASUREMENT, 4 )
#define IPOPT_CIPSO IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 5 )
 
#define IPVERSION 4
#define MAXTTL 255
#define IPDEFTTL 64
 
#define IPOPT_OPTVAL 0
#define IPOPT_OLEN 1
#define IPOPT_OFFSET 2
#define IPOPT_MINOFF 4
#define MAX_IPOPTLEN 40
#define IPOPT_NOP IPOPT_NOOP
#define IPOPT_EOL IPOPT_END
#define IPOPT_TS IPOPT_TIMESTAMP
 
#define IPOPT_TS_TSONLY 0 /* timestamps only */
#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
#define IPOPT_TS_PRESPEC 3 /* specified modules only */
 
#endif
 
/** @}
*/
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/branches/network/uspace/srv/net/ip/ip.c
33,58 → 33,64
/** @file
*/
 
#include <as.h>
#include <async.h>
#include <errno.h>
#include <stdio.h>
 
#include <ipc/ipc.h>
#include <ipc/services.h>
//#include <sys/mman.h>
 
#include "../err.h"
#include "../measured_strings.h"
#include "../messages.h"
#include "../modules.h"
#include "../netif/netif_device_id_type.h"
#include "../packet.h"
 
#include "../include/sockaddr.h"
#include "../include/socket.h"
#include "../netif/device.h"
 
#include "ip.h"
#include "ip_messages.h"
#include "ip_module.h"
 
#define DEFAULT_IPV 4
#define DEFAULT_IPV 4
 
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call )
#define IPC_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * call )
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call )
#define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call )
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call )
 
ip_globals_t ip_globals;
 
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t )
 
int parse_address( char * value, address_ref address );
INT_MAP_IMPLEMENT( ip_protos, ip_proto_t )
 
int ip_register_message( int protocol, int phone );
int ip_state_message( device_id_t device_id, device_state_t state );
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall );
 
/** Initializes the module.
*/
int ip_initialize( void ){
ip_netifs_initialize( & ip_globals.netifs );
ip_protos_initialize( & ip_globals.protos );
return EOK;
}
 
int ip_call( ipc_callid_t callid ){
int ip_echo_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t * answer1, ipcarg_t * answer2, ipcarg_t * answer3, ipcarg_t * answer4, ipcarg_t * answer5 ){
if( answer1 ) * answer1 = arg1;
if( answer2 ) * answer2 = arg2;
if( answer3 ) * answer3 = arg3;
if( answer4 ) * answer4 = arg4;
if( answer5 ) * answer5 = arg5;
return EOK;
}
 
int parse_address( char * value, address_ref address ){
char * next;
int index;
 
if( ! value ){
( * address )[ 0 ] = ( * address )[ 1 ] = ( * address )[ 2 ] = ( * address )[ 3 ] = 0;
return ENOENT;
}
next = value;
for( index = 0; index < 4; ++ index ){
if(( ! next ) || ( ! * next )) return EINVAL;
if( index ) ++ next;
( * address )[ index ] = strtoul( next, & next, 0 );
}
return EOK;
}
 
int ip_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
int ip_device_message( device_id_t device_id, services_t service ){
ERROR_DECLARE;
 
ip_netif_ref ip_netif;
95,85 → 101,176
measured_string_ref settings;
char * data;
 
switch( method ){
ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t ));
if( ! ip_netif ) return ENOMEM;
ip_netif->device_id = device_id;
// get configuration
// TODO mapping
message = async_send_2( ip_globals.networking_phone, NET_NET_GET_DEVICE_CONF, ip_netif->device_id, count, & answer );
// send names and get settings
if( ERROR_OCCURED( measured_strings_send( ip_globals.networking_phone, configuration, count ))
|| ERROR_OCCURED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){
async_wait_for( message, NULL );
return ERROR_CODE;
}
if( settings ){
if( settings[ 0 ].value ){
ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 );
}else{
ip_netif->ipv = DEFAULT_IPV;
}
ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" );
if( ip_netif->dhcp ){
// TODO dhcp
free( ip_netif );
return ENOTSUP;
}else if( ip_netif->ipv == 4 ){
if( ERROR_OCCURED( inet_pton( AF_INET, settings[ 2 ].value, ( uint8_t * ) & ip_netif->address ))
|| ERROR_OCCURED( inet_pton( AF_INET, settings[ 3 ].value, ( uint8_t * ) & ip_netif->netmask ))
|| ( inet_pton( AF_INET, settings[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL )
|| ( inet_pton( AF_INET, settings[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL )
|| ( inet_pton( AF_INET, settings[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL )
|| ( inet_pton( AF_INET, settings[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){
free( ip_netif );
return EINVAL;
}
}else{
// TODO ipv6
free( ip_netif );
return ENOTSUP;
}
// TODO ARP module
}
// TODO arp module
free( settings );
free( data );
// end request
// TODO mapping
async_wait_for( message, NULL );
// print the settings
printf( "\n -IPV =\t%d", ip_netif->ipv );
printf( "\n -configuration =\t%s", ip_netif->dhcp ? "dhcp" : "static" );
// TODO ipv6
data = malloc( INET_ADDRSTRLEN );
if( data ){
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN );
printf( "\n -address =\t%s", data );
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN );
printf( "\n -netmask =\t%s", data );
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN );
printf( "\n -gateway =\t%s", data );
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN );
printf( "\n -broadcast =\t%s", data );
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN );
printf( "\n -dns1 =\t%s", data );
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN );
printf( "\n -dns2 =\t%s", data );
free( data );
}
// TODO mapping
ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver );
if( ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){
free( ip_netif );
return ERROR_CODE;
}
return EOK;
}
 
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){
ERROR_DECLARE;
 
ipc_callid_t callid;
ipc_call_t call;
// ipc_call_t answer;
// int count;
int result;
packet_t packet;
 
/*
* Accept the connection
* - Answer the first IPC_M_CONNECT_ME_TO call.
*/
ipc_answer_0( iid, EOK );
 
while( true ){
/* // refresh data
count = 0;
IPC_SET_RETVAL( answer, 0 );
// just to be precize
IPC_SET_RETVAL( answer, 0 );
IPC_SET_ARG1( answer, 0 );
IPC_SET_ARG2( answer, 0 );
IPC_SET_ARG3( answer, 0 );
IPC_SET_ARG4( answer, 0 );
IPC_SET_ARG5( answer, 0 );
*/
callid = async_get_call( & call );
switch( IPC_GET_METHOD( call )){
case NET_IL_DEVICE_STATE:
case NET_NIL_DEVICE_STATE:
result = ip_state_message( IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call ));
ipc_answer_0( callid, result );
// TODO packer received
case NET_IL_RECEIVED:
case NET_NIL_RECEIVED:
if( ERROR_OCCURED( result = packet_receive( & packet ))){
ipc_answer_0( callid, ERROR_CODE );
continue;
}
//result = ip_receive_message( IPC_GET_DEVICE( call ), packet );
packet_destroy( packet );
ipc_answer_0( callid, result );
}
}
}
 
int ip_state_message( device_id_t device_id, device_state_t state ){
// TODO state
printf( "\nip - device %d changed state to %d\n", device_id, state );
return EOK;
}
 
int ip_register_message( int protocol, int phone ){
ERROR_DECLARE;
 
ip_proto_ref proto;
 
proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t ));
if( ! proto ) return ENOMEM;
proto->protocol = protocol;
proto->phone = phone;
if( ERROR_OCCURED( ip_protos_add( & ip_globals.protos, proto->protocol, proto ))){
free( proto );
return ERROR_CODE;
}
return EOK;
}
 
int ip_send_message( device_id_t device_id, packet_t packet ){
// TODO send packet
printf( "Packet to send via %d: %s", device_id, packet_get_data( packet ));
return EOK;
}
 
int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
ERROR_DECLARE;
 
packet_t packet;
 
* answer_count = 0;
switch( IPC_GET_METHOD( * call )){
case IPC_M_PHONE_HUNGUP:
return EOK;
case NET_IP_ECHO:
if( result1 ) * result1 = arg1;
if( result2 ) * result2 = arg2;
if( result3 ) * result3 = arg3;
return EOK;
* answer_count = 5;
return ip_echo_message( IPC_GET_ARG1( * call ), IPC_GET_ARG2( * call ), IPC_GET_ARG3( * call ), IPC_GET_ARG4( * call ), IPC_GET_ARG5( * call ), & IPC_GET_ARG1( * answer ), & IPC_GET_ARG2( * answer ), & IPC_GET_ARG3( * answer ), & IPC_GET_ARG4( * answer ), & IPC_GET_ARG5( * answer ) );
case NET_IL_DEVICE:
ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t ));
if( ! ip_netif ) return ENOMEM;
ip_netif->device_id = arg1;
// get configuration
message = async_send_2( ip_globals.networking_phone, NET_NETWORKING_GET_DEVICE_CONFIGURATION, ip_netif->device_id, count, & answer );
// send names and get settings
if( ERROR_OCCURED( measured_strings_send( ip_globals.networking_phone, configuration, count ))
|| ERROR_OCCURED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){
async_wait_for( message, NULL );
return ERROR_CODE;
}
if( settings ){
if( settings[ 0 ].value ){
ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 );
}else{
ip_netif->ipv = DEFAULT_IPV;
}
ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" );
if( ip_netif->dhcp ){
// TODO dhcp
free( ip_netif );
return ENOTSUP;
}else if( ip_netif->ipv == 4 ){
if( ERROR_OCCURED( parse_address( settings[ 2 ].value, & ip_netif->address ))
|| ERROR_OCCURED( parse_address( settings[ 3 ].value, & ip_netif->netmask ))
|| ( parse_address( settings[ 4 ].value, & ip_netif->gateway ) == EINVAL )
|| ( parse_address( settings[ 5 ].value, & ip_netif->broadcast ) == EINVAL )
|| ( parse_address( settings[ 6 ].value, & ip_netif->dns1 ) == EINVAL )
|| ( parse_address( settings[ 7 ].value, & ip_netif->dns2 ) == EINVAL )){
free( ip_netif );
return EINVAL;
}
}else{
// TODO ipv6
free( ip_netif );
return ENOTSUP;
}
// TODO ARP module
}
// print the settings
printf( "\n -IPV=%d", ip_netif->ipv );
printf( "\n -configuration=%s", ip_netif->dhcp ? "dhcp" : "static" );
// TODO ipv6
printf( "\n -address=%d.%d.%d.%d", ip_netif->address[ 0 ], ip_netif->address[ 1 ], ip_netif->address[ 2 ], ip_netif->address[ 3 ] );
printf( "\n -netmask=%d.%d.%d.%d", ip_netif->netmask[ 0 ], ip_netif->netmask[ 1 ], ip_netif->netmask[ 2 ], ip_netif->netmask[ 3 ] );
printf( "\n -gateway=%d.%d.%d.%d", ip_netif->gateway[ 0 ], ip_netif->gateway[ 1 ], ip_netif->gateway[ 2 ], ip_netif->gateway[ 3 ] );
printf( "\n -broadcast=%d.%d.%d.%d", ip_netif->broadcast[ 0 ], ip_netif->broadcast[ 1 ], ip_netif->broadcast[ 2 ], ip_netif->broadcast[ 3 ] );
printf( "\n -dns1=%d.%d.%d.%d", ip_netif->dns1[ 0 ], ip_netif->dns1[ 1 ], ip_netif->dns1[ 2 ], ip_netif->dns1[ 3 ] );
printf( "\n -dns2=%d.%d.%d.%d", ip_netif->dns2[ 0 ], ip_netif->dns2[ 1 ], ip_netif->dns2[ 2 ], ip_netif->dns2[ 3 ] );
// TODO arp module
free( settings );
free( data );
// end request
async_wait_for( message, NULL );
ip_netif->phone = connect_to_service( arg2 );
if( ERROR_OCCURED( async_req_2_0( ip_netif->phone, NET_LL_REGISTER, arg1, SERVICE_IP ))
|| ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){
free( ip_netif );
return ERROR_CODE;
}
return EOK;
case NET_IL_DEVICE_STATE_CHANGED:
case NET_LL_DEVICE_STATE_CHANGED:
// arg1 device id
// arg2 state
// TODO state
printf( "\nip - device %d changed state to %d\n", arg1, arg2 );
case NET_IP_TCP_REGISTER:
ip_globals.tcp_phone = connect_to_service( arg1 );
return EOK;
return ip_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ));
case IPC_M_CONNECT_TO_ME:
return ip_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call ));
case NET_IP_SEND:
ERROR_PROPAGATE( packet_receive( & packet ));
return ip_send_message( IPC_GET_DEVICE( call ), packet );
}
return ENOTSUP;
}
/branches/network/uspace/srv/net/ip/Makefile
46,9 → 46,11
$(NAME).c \
../measured_strings.c \
../module.c \
../modules.c
../modules.c \
../packet.c \
../sockaddr.c
 
DEFS += -D NETWORKING_$(NETWORKING) -D $(NAME)_call=module_call -D $(NAME)_message=module_message -D $(NAME)_start_module=module_start -D $(NAME)_print_name=module_print_name
DEFS += -D IP_BUNDLE=1 -D $(NAME)_message=module_message -D $(NAME)_start_module=module_start -D $(NAME)_print_name=module_print_name
 
OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
 
/branches/network/uspace/srv/net/ip/ip.h
34,49 → 34,51
* @file
*/
 
#ifndef __NET_IP_INTERNALS_H__
#define __NET_IP_INTERNALS_H__
#ifndef __NET_IP_H__
#define __NET_IP_H__
 
#include <ipc/ipc.h>
 
#include "../netif/netif_device_id_type.h"
#include "../include/sockaddr.h"
#include "../netif/device.h"
 
#define IP_MAX_ADDRESS_LENGTH 4
 
typedef int address_t[ IP_MAX_ADDRESS_LENGTH ];
typedef address_t * address_ref;
 
typedef struct ip_netif ip_netif_t;
typedef ip_netif_t * ip_netif_ref;
 
typedef struct ip_proto ip_proto_t;
typedef ip_proto_t * ip_proto_ref;
 
typedef struct ip_globals ip_globals_t;
 
DEVICE_MAP_DECLARE( ip_netifs, ip_netif_t )
 
INT_MAP_DECLARE( ip_protos, ip_proto_t )
 
struct ip_netif{
netif_device_id_t device_id;
device_id_t device_id;
int phone;
int ipv;
int dhcp;
address_t address;
address_t netmask;
address_t gateway;
address_t broadcast;
address_t dns1;
address_t dns2;
in_addr_t address;
in_addr_t netmask;
in_addr_t gateway;
in_addr_t broadcast;
in_addr_t dns1;
in_addr_t dns2;
// TODO modules
};
 
struct ip_proto{
int protocol;
int phone;
};
 
struct ip_globals{
int networking_phone;
int tcp_phone;
ip_netifs_t netifs;
ip_protos_t protos;
};
 
int ip_initialize( void );
int ip_call( ipc_callid_t callid );
int ip_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
 
#endif
 
/** @}
/branches/network/uspace/srv/net/ip/ip_module.c
35,17 → 35,20
 
#include <async.h>
#include <stdio.h>
 
#include <ipc/ipc.h>
#include <ipc/services.h>
 
#include "../err.h"
#include "../modules.h"
 
#include "ip.h"
#include "ip_module.h"
 
#define NAME "IP protocol"
 
void ip_print_name( void );
int ip_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall ));
int ip_start_module( async_client_conn_t client_connection );
 
extern ip_globals_t ip_globals;
 
53,15 → 56,19
printf( NAME );
}
 
int ip_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){
services_t need[ 2 ];
int * need_phone[ 2 ];
int ip_start_module( async_client_conn_t client_connection ){
ERROR_DECLARE;
 
need[ 0 ] = SERVICE_NETWORKING;
need[ 1 ] = NULL;
need_phone[ 0 ] = & ip_globals.networking_phone;
need_phone[ 1 ] = NULL;
return start_service( SERVICE_IP, need, need_phone, client_connection, ip_initialize );
ipcarg_t phonehash;
 
async_set_client_connection( client_connection );
ip_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
ERROR_PROPAGATE( ip_initialize());
ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
 
async_manager();
 
return EOK;
}
 
/** @}