/branches/network/uspace/srv/net/structures/module_map.c |
---|
26,7 → 26,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup netif |
/** @addtogroup net |
* @{ |
*/ |
48,7 → 48,7 |
GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t ) |
int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id ){ |
int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id, connect_module_t connect_module ){ |
ERROR_DECLARE; |
module_ref tmp_module; |
61,6 → 61,7 |
tmp_module->name = name; |
tmp_module->filename = filename; |
tmp_module->service = service; |
tmp_module->connect_module = connect_module; |
if( ERROR_OCCURRED( modules_add( modules, tmp_module->name, 0, tmp_module ))){ |
free( tmp_module ); |
return ERROR_CODE; |
80,7 → 81,7 |
if( ! module->task_id ) return NULL; |
} |
if( ! module->phone ){ |
module->phone = connect_to_service( module->service ); |
module->phone = module->connect_module( module->service ); |
} |
return module; |
} |
/branches/network/uspace/srv/net/structures/measured_strings.h |
---|
38,6 → 38,8 |
#ifndef __MEASURED_STRINGS_H__ |
#define __MEASURED_STRINGS_H__ |
#include <sys/types.h> |
/** Type definition of the character string with measured length. |
* @see measured_string |
*/ |
/branches/network/uspace/srv/net/structures/packet/packet_remote.c |
---|
0,0 → 1,125 |
/* |
* 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 packet |
* @{ |
*/ |
/** |
* @file |
*/ |
#include <async.h> |
#include <ipc/ipc.h> |
#include <sys/mman.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "packet.h" |
#include "packet_client.h" |
#include "packet_messages.h" |
/** Obtains the packet from the packet server as the shared memory block. |
* Creates the local packet mapping as well. |
* @param phone The packet server module phone. Input parameter. |
* @param packet The packet reference pointer to store the received packet reference. Output parameter. |
* @param packet_id The packet identifier. Input parameter. |
* @param size The packet total size in bytes. Input parameter. |
* @returns EOK on success. |
* \todo ipc_share_in_start() error? |
* @returns Other error codes as defined for the pm_add() function. |
*/ |
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ); |
int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
ERROR_DECLARE; |
unsigned int size; |
if( ! packet ) return EINVAL; |
* packet = pm_find( packet_id ); |
if( * packet ) return EOK; |
ERROR_PROPAGATE( async_req_1_1( phone, NET_PACKET_GET_SIZE, packet_id, & size )); |
return packet_return( phone, packet, packet_id, size ); |
} |
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ){ |
ERROR_DECLARE; |
aid_t message; |
ipc_call_t answer; |
ipcarg_t result; |
message = async_send_1( phone, NET_PACKET_GET, packet_id, & answer ); |
* packet = ( packet_t ) as_get_mappable_page( size ); |
if( ERROR_OCCURRED( ipc_share_in_start_0_0( phone, * packet, size )) |
|| ERROR_OCCURRED( pm_add( * packet ))){ |
munmap( * packet, size ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
return result; |
} |
packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
ERROR_DECLARE; |
packet_id_t packet_id; |
unsigned int size; |
packet_t packet; |
if( ERROR_OCCURRED( async_req_4_2( phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, ( ipcarg_t * ) & packet_id, & size )) |
|| ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
return NULL; |
} |
return packet; |
} |
packet_t packet_get_1( int phone, size_t content ){ |
ERROR_DECLARE; |
packet_id_t packet_id; |
unsigned int size; |
packet_t packet; |
if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, ( ipcarg_t * ) & packet_id, & size )) |
|| ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
return NULL; |
} |
return packet; |
} |
void pq_release( int phone, packet_id_t packet_id ){ |
async_msg_1( phone, NET_PACKET_RELEASE, packet_id ); |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/structures/packet/packet_messages.h |
---|
0,0 → 1,78 |
/* |
* 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 packet |
* @{ |
*/ |
/** @file |
*/ |
#ifndef __NET_PACKET_MESSAGES__ |
#define __NET_PACKET_MESSAGES__ |
#include <ipc/ipc.h> |
#include "../../messages.h" |
typedef enum { |
NET_PACKET_CREATE_1 = NET_PACKET_FIRST, |
NET_PACKET_CREATE_4, |
NET_PACKET_GET, |
NET_PACKET_GET_SIZE, |
NET_PACKET_RELEASE |
} packet_messages; |
/** Returns the protocol service message parameter. |
*/ |
#define ARP_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
/** Returns the packet identifier message parameter. |
*/ |
#define IPC_GET_ID( call ) ( packet_id_t ) IPC_GET_ARG1( * call ) |
/** Returns the maximal content length message parameter. |
*/ |
#define IPC_GET_CONTENT( call ) ( size_t ) IPC_GET_ARG1( * call ) |
/** Returns the maximal address length message parameter. |
*/ |
#define IPC_GET_ADDR_LEN( call ) ( size_t ) IPC_GET_ARG2( * call ) |
/** Returns the maximal prefix length message parameter. |
*/ |
#define IPC_GET_PREFIX( call ) ( size_t ) IPC_GET_ARG3( * call ) |
/** Returns the maximal suffix length message parameter. |
*/ |
#define IPC_GET_SUFFIX( call ) ( size_t ) IPC_GET_ARG4( * call ) |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/structures/packet/packet_header.h |
---|
37,6 → 37,8 |
#ifndef __NET_PACKET_HEADER_H__ |
#define __NET_PACKET_HEADER_H__ |
#include "../../messages.h" |
#include "packet.h" |
/** Packet integrity check magic value. |
/branches/network/uspace/srv/net/structures/packet/packet_client.c |
---|
50,18 → 50,6 |
#include "packet_header.h" |
#include "packet_client.h" |
/** Obtains the packet from the packet server as the shared memory block. |
* Creates the local packet mapping as well. |
* @param phone The packet server module phone. Input parameter. |
* @param packet The packet reference pointer to store the received packet reference. Output parameter. |
* @param packet_id The packet identifier. Input parameter. |
* @param size The packet total size in bytes. Input parameter. |
* @returns EOK on success. |
* \todo ipc_share_in_start() error? |
* @returns Other error codes as defined for the pm_add() function. |
*/ |
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ); |
int packet_copy_data( packet_t packet, const void * data, size_t length ){ |
if( ! packet_is_valid( packet )) return EINVAL; |
if( packet->data_start + length >= packet->length ) return ENOMEM; |
135,68 → 123,5 |
return EOK; |
} |
int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
ERROR_DECLARE; |
unsigned int size; |
if( ! packet ) return EINVAL; |
* packet = pm_find( packet_id ); |
if( * packet ) return EOK; |
ERROR_PROPAGATE( async_req_1_1( phone, NET_PACKET_GET_SIZE, packet_id, & size )); |
return packet_return( phone, packet, packet_id, size ); |
} |
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ){ |
ERROR_DECLARE; |
aid_t message; |
ipc_call_t answer; |
ipcarg_t result; |
message = async_send_1( phone, NET_PACKET_GET, packet_id, & answer ); |
* packet = ( packet_t ) as_get_mappable_page( size ); |
if( ERROR_OCCURRED( ipc_share_in_start_0_0( phone, * packet, size )) |
|| ERROR_OCCURRED( pm_add( * packet ))){ |
munmap( * packet, size ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & result ); |
return result; |
} |
packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
ERROR_DECLARE; |
packet_id_t packet_id; |
unsigned int size; |
packet_t packet; |
if( ERROR_OCCURRED( async_req_4_2( phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, ( ipcarg_t * ) & packet_id, & size )) |
|| ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
return NULL; |
} |
return packet; |
} |
packet_t packet_get_1( int phone, size_t content ){ |
ERROR_DECLARE; |
packet_id_t packet_id; |
unsigned int size; |
packet_t packet; |
if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, ( ipcarg_t * ) & packet_id, & size )) |
|| ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
return NULL; |
} |
return packet; |
} |
void pq_release( int phone, packet_id_t packet_id ){ |
async_msg_1( phone, NET_PACKET_RELEASE, packet_id ); |
} |
/** @} |
*/ |
/branches/network/uspace/srv/net/structures/packet/packet_server.c |
---|
48,9 → 48,13 |
#include "../../messages.h" |
#include "packet.h" |
#include "packet_client.h" |
#include "packet_header.h" |
#include "packet_messages.h" |
#include "packet_server.h" |
#define FREE_QUEUES_COUNT 7 |
/** The default address length reserved for new packets. |
*/ |
#define DEFAULT_ADDR_LEN 32 |
63,28 → 67,6 |
*/ |
#define DEFAULT_SUFFIX 0 |
/** Returns the packet identifier message parameter. |
*/ |
#define IPC_GET_ID( call ) ( packet_id_t ) IPC_GET_ARG1( * call ) |
/** Returns the maximal content length message parameter. |
*/ |
#define IPC_GET_CONTENT( call ) ( size_t ) IPC_GET_ARG1( * call ) |
/** Returns the maximal address length message parameter. |
*/ |
#define IPC_GET_ADDR_LEN( call ) ( size_t ) IPC_GET_ARG2( * call ) |
/** Returns the maximal prefix length message parameter. |
*/ |
#define IPC_GET_PREFIX( call ) ( size_t ) IPC_GET_ARG3( * call ) |
/** Returns the maximal suffix length message parameter. |
*/ |
#define IPC_GET_SUFFIX( call ) ( size_t ) IPC_GET_ARG4( * call ) |
#define FREE_QUEUES_COUNT 7 |
/** Packet server global data. |
*/ |
static struct{ |
109,12 → 91,6 |
0 |
}; |
/** Releases the packet and returns it to the appropriate free packet queue. |
* Should be used only when the global data are locked. |
* @param packet The packet to be released. Input parameter. |
*/ |
void packet_release( packet_t packet ); |
/** Returns the packet of dimensions at least as given. |
* Tries to reuse free packets first. |
* Creates a new packet aligned to the memory page size if none available. |
128,6 → 104,16 |
*/ |
packet_t packet_get( size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
/** \todo |
*/ |
int packet_release_wrapper( packet_id_t packet_id ); |
/** Releases the packet and returns it to the appropriate free packet queue. |
* Should be used only when the global data are locked. |
* @param packet The packet to be released. Input parameter. |
*/ |
void packet_release( packet_t packet ); |
/** Creates a new packet of dimensions at least as given. |
* Should be used only when the global data are locked. |
* @param length The total length of the packet, including the header, the addresses and the data of the packet. Input parameter. |
159,6 → 145,24 |
*/ |
int packet_reply( const packet_t packet ); |
int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
if( ! packet ) return EINVAL; |
* packet = pm_find( packet_id ); |
return ( * packet ) ? EOK : ENOENT; |
} |
packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
return packet_get( addr_len, max_prefix, max_content, max_suffix ); |
} |
packet_t packet_get_1( int phone, size_t content ){ |
return packet_get( DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, DEFAULT_SUFFIX ); |
} |
void pq_release( int phone, packet_id_t packet_id ){ |
( void ) packet_release_wrapper( packet_id ); |
} |
int packet_server_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
packet_t packet; |
191,7 → 195,15 |
IPC_SET_ARG1( * answer, packet->length ); |
return EOK; |
case NET_PACKET_RELEASE: |
packet = pm_find( IPC_GET_ID( call )); |
return packet_release_wrapper( IPC_GET_ID( call )); |
} |
return ENOTSUP; |
} |
int packet_release_wrapper( packet_id_t packet_id ){ |
packet_t packet; |
packet = pm_find( packet_id ); |
if( ! packet_is_valid( packet )) return ENOENT; |
futex_down( & ps_globals.lock ); |
pq_destroy( packet, packet_release ); |
198,8 → 210,6 |
futex_up( & ps_globals.lock ); |
return EOK; |
} |
return ENOTSUP; |
} |
void packet_release( packet_t packet ){ |
int index; |
/branches/network/uspace/srv/net/structures/module_map.h |
---|
26,7 → 26,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup netif |
/** @addtogroup net |
* @{ |
*/ |
41,6 → 41,8 |
#include <ipc/services.h> |
#include "../modules.h" |
#include "generic_char_map.h" |
typedef struct module_struct module_t; |
55,9 → 57,10 |
int usage; |
char * name; |
char * filename; |
connect_module_t * connect_module; |
}; |
int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id ); |
int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id, connect_module_t * connect_module ); |
module_ref get_running_module( modules_ref modules, char * name ); |
task_id_t spawn( char * fname ); |