Subversion Repositories HelenOS

Rev

Rev 4715 | Rev 4743 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/*
 * 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 net
 *  @{
 */

/** @file
 *  \todo
 */

#ifndef __NET_MESSAGES_H__
#define __NET_MESSAGES_H__

#include <async.h>

#include <ipc/ipc.h>
#include <ipc/services.h>

#include "include/device.h"

#include "structures/measured_strings.h"
#include "structures/packet/packet.h"

#define NET_NETIF_COUNT     6
#define NET_NET_COUNT       9
#define NET_NIL_COUNT       7
#define NET_ETH_COUNT       0
#define NET_IL_COUNT        6
#define NET_IP_COUNT        4
#define NET_ARP_COUNT       5
#define NET_RARP_COUNT      0
#define NET_ICMP_COUNT      7
#define NET_TL_COUNT        1
#define NET_UDP_COUNT       0
#define NET_TCP_COUNT       0
#define NET_PACKET_COUNT    5
#define NET_SOCKET_COUNT    14

#define NET_FIRST           2000

#define NET_NETIF_FIRST     NET_FIRST
#define NET_NETIF_LAST      ( NET_NETIF_FIRST + NET_NETIF_COUNT )

#define NET_NET_FIRST       ( NET_NETIF_LAST + 0 )
#define NET_NET_LAST        ( NET_NET_FIRST + NET_NET_COUNT )

#define NET_NIL_FIRST       ( NET_NET_LAST + 0 )
#define NET_NIL_LAST        ( NET_NIL_FIRST + NET_NIL_COUNT )
#define NET_ETH_FIRST       ( NET_NIL_LAST + 0 )
#define NET_ETH_LAST        ( NET_ETH_FIRST + NET_ETH_COUNT )

#define NET_IL_FIRST        ( NET_ETH_LAST + 0 )
#define NET_IL_LAST         ( NET_IL_FIRST + NET_IL_COUNT )
#define NET_IP_FIRST        ( NET_IL_LAST + 0 )
#define NET_IP_LAST         ( NET_IP_FIRST + NET_IP_COUNT )

#define NET_ARP_FIRST       ( NET_IP_LAST + 0 )
#define NET_ARP_LAST        ( NET_ARP_FIRST + NET_ARP_COUNT )
#define NET_RARP_FIRST      ( NET_ARP_LAST + 0 )
#define NET_RARP_LAST       ( NET_RARP_FIRST + NET_RARP_COUNT )
#define NET_ICMP_FIRST      ( NET_RARP_LAST + 0 )
#define NET_ICMP_LAST       ( NET_ICMP_FIRST + NET_ICMP_COUNT )

#define NET_TL_FIRST        ( NET_ICMP_LAST + 0 )
#define NET_TL_LAST         ( NET_TL_FIRST + NET_TL_COUNT )
#define NET_UDP_FIRST       ( NET_TL_LAST + 0 )
#define NET_UDP_LAST        ( NET_UDP_FIRST + NET_UDP_COUNT )
#define NET_TCP_FIRST       ( NET_UDP_LAST + 0 )
#define NET_TCP_LAST        ( NET_TCP_FIRST + NET_TCP_COUNT )

#define NET_SOCKET_FIRST    ( NET_TCP_LAST + 0 )
#define NET_SOCKET_LAST     ( NET_SOCKET_FIRST + NET_SOCKET_COUNT )

#define NET_PACKET_FIRST    ( NET_SOCKET_LAST + 0 )
#define NET_PACKET_LAST     ( NET_PACKET_FIRST + NET_PACKET_COUNT )

#define NET_LAST            NET_PACKET_LAST

#define NET_COUNT           ( NET_LAST - NET_FIRST )

#define IS_IN_INTERVAL( item, first_inclusive, last_exclusive ) ((( item ) >= ( first_inclusive )) && (( item ) < ( last_exclusive )))

#define IS_NET_MESSAGE( call )          IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_FIRST, NET_LAST )
#define IS_NET_NET_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_NET_FIRST, NET_NET_LAST )
#define IS_NET_NIL_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_NIL_FIRST, NET_NIL_LAST )
#define IS_NET_ETH_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_ETH_FIRST, NET_ETH_LAST )
#define IS_NET_IL_MESSAGE( call )       IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_IL_FIRST, NET_IL_LAST )
#define IS_NET_IP_MESSAGE( call )       IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_IP_FIRST, NET_IP_LAST )
#define IS_NET_ARP_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_ARP_FIRST, NET_ARP_LAST )
#define IS_NET_RARP_MESSAGE( call )     IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_RARP_FIRST, NET_RARP_LAST )
#define IS_NET_ICMP_MESSAGE( call )     IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_ICMP_FIRST, NET_ICMP_LAST )
#define IS_NET_TL_MESSAGE( call )       IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_TL_FIRST, NET_TL_LAST )
#define IS_NET_UDP_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_UDP_FIRST, NET_UDP_LAST )
#define IS_NET_TCP_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_TCP_FIRST, NET_TCP_LAST )
#define IS_NET_SOCKET_MESSAGE( call )   IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_SOCKET_FIRST, NET_SOCKET_LAST )
#define IS_NET_PACKET_MESSAGE( call )   IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_PACKET_FIRST, NET_PACKET_LAST )

/** 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 )
#define IPC_GET_COUNT( call )       ( size_t ) IPC_GET_ARG2( * call )
#define IPC_GET_STATE( call )       ( device_state_t ) IPC_GET_ARG2( * call )

/** Returns the maximum transmission unit message parameter.
 */
#define IPC_GET_MTU( call )         ( size_t ) IPC_GET_ARG2( * call )

/** Returns the device driver service message parameter.
 */
#define IPC_GET_SERVICE( call )     ( services_t ) IPC_GET_ARG3( * call )
#define IPC_GET_TARGET( call )      ( services_t ) IPC_GET_ARG3( * call )
#define IPC_GET_SENDER( call )      ( services_t ) IPC_GET_ARG3( * call )

#define IPC_GET_ERROR( call )       ( services_t ) IPC_GET_ARG4( * call )

#define IPC_GET_PHONE( call )       ( int ) IPC_GET_ARG5( * call )

#define IPC_SET_DEVICE( answer )    (( device_id_t * ) & IPC_GET_ARG1( * answer ))

#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 {
    /* () not supported, registers new device */
    NET_NET_DEVICE = NET_NET_FIRST,
    /* ( NULL, count ), measured_strings_send( names ), measured_strings_return( values ) */
    NET_NET_GET_CONF,
    /* ( device_id, count ), measured_strings_send( names ), measured_strings_return( values ) */
    NET_NET_GET_DEVICE_CONF,
    /* () not supported, measured_strings_send( names ), measured_strings_send( values ) */
    NET_NET_SET_CONF,
    /* ( device_id, count ) not supported, measured_strings_send( names ), measured_strings_send( values ) */
    NET_NET_SET_DEVICE_CONF,
    /* () */
    NET_NET_STARTUP,
    /* ( device_id ) */
    NET_NET_START,
    /* ( device_id ) */
    NET_NET_STOP,
    /* ( device_id ) ipc_data_read( stats ) */
    NET_NET_STATS,
} net_messages;

static inline int generic_get_addr( int phone, int message, device_id_t device_id, measured_string_ref * address, char ** data ){
    aid_t           message_id;
    ipcarg_t        result;
    int             string;

    if( !( address && data )) return EBADMEM;
    message_id = async_send_1( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, NULL );
    string = measured_strings_return( phone, address, data, 1 );
    async_wait_for( message_id, & result );
    if(( string == EOK ) && ( result != EOK )){
        free( * address );
        free( * data );
    }
    return ( int ) result;
}

static inline int   generic_translate_req( int phone, int message, device_id_t device_id, services_t service, measured_string_ref configuration, size_t count, measured_string_ref * translation, char ** data ){
    aid_t           message_id;
    ipcarg_t        result;
    int             string;

    if( !( configuration && ( count > 0 ))) return EINVAL;
    if( !( translation && data )) return EBADMEM;
    message_id = async_send_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) count, ( ipcarg_t ) service, NULL );
    measured_strings_send( phone, configuration, count );
    string = measured_strings_return( phone, translation, data, count );
    async_wait_for( message_id, & result );
    if(( string == EOK ) && ( result != EOK )){
        free( * translation );
        free( * data );
    }
    return ( int ) result;
}

static inline int   generic_send_msg( int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error ){
    if( error ){
        async_msg_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) sender, ( ipcarg_t ) error );
    }else{
        async_msg_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) sender );
    }
    return EOK;
}

static inline int   generic_packet_size_req( int phone, int message, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){
    return ( int ) async_req_1_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t * ) addr_len, ( ipcarg_t * ) prefix, ( ipcarg_t * ) content, ( ipcarg_t * ) suffix );
}

static inline int   generic_device_state_msg( int phone, int message, device_id_t device_id, int state, services_t target ){
    async_msg_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) state, target );
    return EOK;
}

static inline int   generic_received_msg( int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t target, services_t error ){
    if( error ){
        async_msg_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) target, ( ipcarg_t ) error );
    }else{
        async_msg_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) target );
    }
    return EOK;
}

static inline int   generic_device_req( int phone, int message, device_id_t device_id, int arg2, services_t service ){
    return ( int ) async_req_3_0( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) arg2, ( ipcarg_t ) service );
}

#endif

/** @}
 */