/branches/network/uspace/srv/net/nil/eth/eth.c |
---|
52,7 → 52,8 |
#include "../../include/ethernet_lsap.h" |
#include "../../include/ethernet_protocols.h" |
#include "../../include/protocol_map.h" |
#include "../../netif/device.h" |
#include "../../include/device.h" |
#include "../../include/netif_messages.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet.h" |
67,6 → 68,8 |
#define ETH_SUFFIX sizeof( eth_fcs_t ) |
#define ETH_MAX_CONTENT 1500 |
#define ETH_MIN_CONTENT 46 |
#define ETH_MAX_TAGGED_CONTENT ( ETH_MAX_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
#define ETH_MIN_TAGGED_CONTENT ( ETH_MIN_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
/** Returns the device identifier message parameter. |
*/ |
84,9 → 87,9 |
/** Returns the device driver service message parameter. |
*/ |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
#define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG3( * call ) |
#define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
123,7 → 126,6 |
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 ); |
eth_proto_ref eth_process_packet( int dummy, packet_t packet ); |
int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ); |
150,10 → 152,7 |
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; |
ipcarg_t result; |
int index; |
rwlock_write_lock( & eth_globals.devices_lock ); |
175,7 → 174,7 |
if( ! device ) return ENOMEM; |
device->device_id = device_id; |
device->service = service; |
device->mtu = ( mtu > 0 ) ? mtu : ETH_MAX_CONTENT; |
device->mtu = (( mtu > 0 ) && ( mtu <= ETH_MAX_TAGGED_CONTENT )) ? mtu : ETH_MAX_TAGGED_CONTENT; |
// TODO get dummy setting |
device->dummy = 0; |
// bind the device driver |
186,21 → 185,11 |
return device->phone; |
} |
// 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 ))){ |
if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
rwlock_write_unlock( & eth_globals.devices_lock ); |
free( device ); |
async_wait_for( message, NULL ); |
return ERROR_CODE; |
} |
async_wait_for( message, & 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 |
index = eth_devices_add( & eth_globals.devices, device->device_id, device ); |
if( index < 0 ){ |
248,7 → 237,7 |
// IEEE 802.3 + 802.2 + LSAP + SNAP |
// organization code not supported |
type = ntohs( header->snap.ethertype ); |
prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t) + sizeof( eth_header_snap_t); |
prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t ); |
}else{ |
// IEEE 802.3 + 802.2 LSAP |
type = lsap_map( header->lsap.dsap ); |
313,7 → 302,7 |
rwlock_read_unlock( & eth_globals.devices_lock ); |
return ENOENT; |
} |
* content = ( ETH_MAX_CONTENT > device->mtu ) ? device->mtu : ETH_MAX_CONTENT; |
* content = device->mtu; |
rwlock_read_unlock( & eth_globals.devices_lock ); |
* addr_len = ETH_ADDR; |
* prefix = ETH_PREFIX; |
384,6 → 373,13 |
void * padding; |
eth_preamble_ref preamble; |
length = packet_get_data_length( packet ); |
if( length > ETH_MAX_TAGGED_CONTENT ) return EINVAL; |
if( length < ETH_MIN_TAGGED_CONTENT ){ |
padding = packet_suffix( packet, ETH_MIN_TAGGED_CONTENT - length ); |
if( ! padding ) return ENOMEM; |
bzero( padding, ETH_MIN_TAGGED_CONTENT - length ); |
} |
if( dummy ){ |
preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
if( ! preamble ) return ENOMEM; |
392,24 → 388,17 |
} |
header = PACKET_PREFIX( packet, eth_header_ex_t ); |
if( ! header ) return ENOMEM; |
length = packet_get_addr( packet, & src, & dest ); |
if( length < 0 ) return length; |
if( length < ETH_ADDR ) return EINVAL; |
memcpy( header->header.src, src_addr, ETH_ADDR ); |
memcpy( & header->header.dest, dest, ETH_ADDR ); |
length = packet_get_data_length( packet ); |
if( length > ETH_MAX_CONTENT ) return EINVAL; |
if( length < ETH_MIN_CONTENT ){ |
padding = packet_suffix( packet, ETH_MIN_CONTENT - length ); |
if( ! padding ) return ENOMEM; |
bzero( padding, ETH_MIN_CONTENT - length ); |
} |
header->header.ethertype = htons( length ); |
header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
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 = ethertype; |
length = packet_get_addr( packet, & src, & dest ); |
if( length < 0 ) return length; |
if( length < ETH_ADDR ) return EINVAL; |
memcpy( header->header.src, src_addr, ETH_ADDR ); |
memcpy( header->header.dest, dest, ETH_ADDR ); |
if( dummy ){ |
fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
if( ! fcs ) return ENOMEM; |
450,7 → 439,7 |
} |
}while( next ); |
// send packet queue |
async_msg_2( device->phone, NET_NETIF_SEND, device_id, packet_get_id( packet )); |
netif_send_msg( device->phone, device_id, packet ); |
rwlock_read_unlock( & eth_globals.devices_lock ); |
return EOK; |
} |
461,6 → 450,7 |
measured_string_ref address; |
packet_t packet; |
// printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_NIL_FIRST ); |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
480,7 → 470,6 |
case NET_NIL_BROADCAST_ADDR: |
ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_BROADCAST_ADDR, & address )); |
return measured_strings_reply( address, 1 ); |
return ERROR_CODE; |
case IPC_M_CONNECT_TO_ME: |
return eth_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
} |
/branches/network/uspace/srv/net/nil/eth/eth.h |
---|
42,7 → 42,7 |
#include <ipc/services.h> |
#include "../../include/sockaddr.h" |
#include "../../netif/device.h" |
#include "../../include/device.h" |
#include "../../structures/measured_strings.h" |
/** Type definition of the Ethernet global data. |
/branches/network/uspace/srv/net/nil/eth/eth_header.h |
---|
111,7 → 111,7 |
* The possible values are assigned by an IEEE committee. |
*/ |
uint8_t ctrl; |
}; |
} __attribute__ ((packed)); |
/** Ethernet header SNAP extension. |
*/ |
123,7 → 123,7 |
* @see ethernet_protocols.h |
*/ |
uint16_t ethertype; |
}; |
} __attribute__ ((packed)); |
/** Ethernet header preamble. |
* Used for dummy devices. |
137,7 → 137,7 |
* Should be set to ETH_SFD. |
*/ |
uint8_t sfd; |
}; |
} __attribute__ ((packed)); |
/** Ethernet header. |
*/ |
152,7 → 152,7 |
* @see ethernet_protocols.h |
*/ |
uint16_t ethertype; |
}; |
} __attribute__ ((packed)); |
/** Ethernet header with all the extensions. |
*/ |
168,7 → 168,7 |
/** SNAP extension. |
*/ |
eth_header_snap_t snap; |
}; |
} __attribute__ ((packed)); |
/** Ethernet Frame Check Sequence. |
*/ |
/branches/network/uspace/srv/net/include/netif_messages.h |
---|
0,0 → 1,134 |
/* |
* 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 netif |
* @{ |
*/ |
/** |
* @file |
*/ |
#ifndef __NET_NETIF_MESSAGES_H__ |
#define __NET_NETIF_MESSAGES_H__ |
#include <async.h> |
#include <errno.h> |
#include <malloc.h> |
#include <ipc/ipc.h> |
#include "../messages.h" |
#include "../structures/measured_strings.h" |
#include "../structures/packet/packet.h" |
#include "device.h" |
typedef enum { |
/* ( device_id, irq, io ) */ |
NET_NETIF_PROBE = NET_NETIF_FIRST, |
/* () not supported, should ask networking for a name and register device */ |
NET_NETIF_PROBE_AUTO, |
/* ( device_id, packet_id ) */ |
NET_NETIF_SEND, |
/* ( device_id ) */ |
NET_NETIF_START, |
/* ( device_id ), ipc_data_read( stats ) */ |
NET_NETIF_STATS, |
/* ( device_id ) */ |
NET_NETIF_STOP, |
/* */ |
NET_NETIF_SET_ADDR, |
/* */ |
NET_NETIF_GET_ADDR, |
} netif_messages; |
#ifdef NETIF_BUNDLE |
#include "../netif/netif_wrappers.h" |
#define NETIF_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define NETIF_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
#define NETIF_GET_IRQ( call ) ( int ) IPC_GET_ARG2( * call ) |
#define NETIF_GET_IO( call ) ( int ) IPC_GET_ARG3( * call ) |
#define netif_get_addr( netif_phone, device_id, address, data ) \ |
netif_get_addr_wrapper( netif_phone, device_id, address, data ) |
#define netif_probe_req( netif_phone, device_id, irq, io ) \ |
netif_probe_wrapper( device_id, irq, io ) |
#define netif_send_msg( netif_phone, device_id, packet ) \ |
netif_send_wrapper( device_id, packet ) |
#define netif_start_req( netif_phone, device_id ) \ |
netif_start_wrapper( device_id ) |
#define netif_stop_req( netif_phone, device_id ) \ |
netif_stop_wrapper( device_id ) |
#else |
static inline int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){ |
aid_t message; |
// ipc_call_t answer; |
ipcarg_t result; |
int string; |
if( !( address && data )) return EBADMEM; |
message = async_send_1( netif_phone, NET_NETIF_GET_ADDR, device_id, NULL /* & answer */ ); |
string = measured_strings_return( netif_phone, address, data, 1 ); |
async_wait_for( message, & result ); |
if(( string == EOK ) && ( result != EOK )){ |
free( * address ); |
free( * data ); |
} |
return result; |
} |
#define netif_probe_req( netif_phone, device_id, irq, io ) \ |
async_req_3_0( netif_phone, NET_NETIF_PROBE, device_id, irq, io ) |
#define netif_send_msg( netif_phone, device_id, packet ) \ |
async_msg_2( netif_phone, NET_NETIF_SEND, device_id, packet_get_id( packet )) |
#define netif_start_req( netif_phone, device_id ) \ |
async_req_1_0( netif_phone, NET_NETIF_START, device_id ) |
#define netif_stop_req( netif_phone, device_id ) \ |
async_req_1_0( netif_phone, NET_NETIF_STOP, device_id ) |
#endif |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/include/protocol_map.h |
---|
41,6 → 41,7 |
#include "ethernet_lsap.h" |
#include "ethernet_protocols.h" |
#include "hardware.h" |
/** Maps the internetwork layer service to the network interface layer type. |
* @param nil Network interface layer service. Input parameter. |
102,6 → 103,17 |
} |
} |
/** \todo |
*/ |
static inline int hardware_map( services_t nil ){ |
switch( nil ){ |
case SERVICE_ETHERNET: |
return HW_ETHER; |
default: |
return 0; |
} |
} |
#endif |
/** @} |
/branches/network/uspace/srv/net/include/device.h |
---|
0,0 → 1,174 |
/* |
* 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 netif |
* @{ |
*/ |
/** @file |
* Device identifier, state and usage statistics. |
*/ |
#ifndef __NET_DEVICE_ID_TYPE_H__ |
#define __NET_DEVICE_ID_TYPE_H__ |
#include "../structures/int_map.h" |
#define DEVICE_MAP_DECLARE INT_MAP_DECLARE |
#define DEVICE_MAP_IMPLEMENT INT_MAP_IMPLEMENT |
/** Device identifier type. |
*/ |
typedef int device_id_t; |
/** Device state type. |
*/ |
typedef enum device_state device_state_t; |
/** Type definition of the device usage statistics. |
* @see device_stats |
*/ |
typedef struct device_stats device_stats_t; |
/** Type definition of the device usage statistics pointer. |
* @see device_stats |
*/ |
typedef device_stats_t * device_stats_ref; |
/** Device state. |
*/ |
enum device_state{ |
/** Device not present or not initialized. |
*/ |
NETIF_NULL = 0, |
/** Device present and stopped. |
*/ |
NETIF_STOPPED, |
/** Device present and active. |
*/ |
NETIF_ACTIVE, |
/** Device present but unable to transmit. |
*/ |
NETIF_CARRIER_LOST |
}; |
/** \todo |
*/ |
#define NIFF_UP ( 1 << 0 ) |
#define NIFF_NOARP ( 1 << 1 ) |
#define NIFF_LOOPBACK ( 1 << 2 ) |
#define NIFF_BROADCAST ( 1 << 3 ) |
#define NIFF_PROMISC ( 1 << 4 ) |
#define NIFF_MULTICAST ( 1 << 5 ) |
/** Device usage statistics. |
* Based on linux_kernel/include/linux/netdevice.h. |
*/ |
struct device_stats{ |
/** Total packets received. |
*/ |
unsigned long rx_packets; |
/** Total packets transmitted. |
*/ |
unsigned long tx_packets; |
/** Total bytes received. |
*/ |
unsigned long rx_bytes; |
/** Total bytes transmitted. |
*/ |
unsigned long tx_bytes; |
/** Bad packets received counter. |
*/ |
unsigned long rx_errors; |
/** Packet transmition problems counter. |
*/ |
unsigned long tx_errors; |
/** No space in buffers counter. |
*/ |
unsigned long rx_dropped; |
/** No space available counter. |
*/ |
unsigned long tx_dropped; |
/** Total multicast packets received. |
*/ |
unsigned long multicast; |
/** The number of collisions due to congestion on the medium. |
*/ |
unsigned long collisions; |
/* detailed rx_errors: */ |
/** Received packet length error counter. |
*/ |
unsigned long rx_length_errors; |
/** Receiver buffer overflow counter. |
*/ |
unsigned long rx_over_errors; |
/** Received packet with crc error counter. |
*/ |
unsigned long rx_crc_errors; |
/** Received frame alignment error counter. |
*/ |
unsigned long rx_frame_errors; |
/** Receiver fifo overrun counter. |
*/ |
unsigned long rx_fifo_errors; |
/** Receiver missed packet counter. |
*/ |
unsigned long rx_missed_errors; |
/* detailed tx_errors */ |
/** Transmitter aborted counter. |
*/ |
unsigned long tx_aborted_errors; |
/** Transmitter carrier errors counter. |
*/ |
unsigned long tx_carrier_errors; |
/** Transmitter fifo overrun counter. |
*/ |
unsigned long tx_fifo_errors; |
/** Transmitter carrier errors counter. |
*/ |
unsigned long tx_heartbeat_errors; |
/** Transmitter window errors counter. |
*/ |
unsigned long tx_window_errors; |
/* for cslip etc */ |
/** Total compressed packets received. |
*/ |
unsigned long rx_compressed; |
/** Total compressed packet transmitted. |
*/ |
unsigned long tx_compressed; |
}; |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:mergeinfo |
/branches/network/uspace/srv/net/include/socket.h |
---|
239,8 → 239,8 |
#define SOL_BLUETOOTH 274 |
*/ |
// |
///** IPX options. |
// */ |
/* * IPX options. |
*/ |
//#define IPX_TYPE 1 |
#endif |
/branches/network/uspace/srv/net/structures/measured_strings.c |
---|
75,7 → 75,7 |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
size_t index; |
size_t length; |
char * next; |
ipc_callid_t callid; |
131,7 → 131,7 |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
size_t index; |
size_t length; |
ipc_callid_t callid; |
166,7 → 166,7 |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
size_t index; |
char * next; |
if(( phone <= 0 ) || ( ! strings ) || ( ! data ) || ( count <= 0 )){ |
207,7 → 207,7 |
ERROR_DECLARE; |
size_t * lengths; |
int index; |
size_t index; |
if(( phone <= 0 ) || ( ! strings ) || ( count <= 0 )){ |
return EINVAL; |
/branches/network/uspace/srv/net/structures/generic_field.h |
---|
49,7 → 49,7 |
typedef name##_t * name##_ref; \ |
\ |
struct name{ \ |
int size; \ |
size_t size; \ |
int next; \ |
type ** items; \ |
int magic; \ |
/branches/network/uspace/srv/net/structures/packet/packet_client.c |
---|
118,17 → 118,17 |
size_t padding; |
if( ! packet_is_valid( packet )) return EINVAL; |
if( packet->addr_len >= addr_len ) return ENOMEM; |
if( packet->addr_len < addr_len ) return ENOMEM; |
padding = packet->addr_len - addr_len; |
if( src ){ |
memcpy(( void * ) packet + packet->src_addr, src, addr_len ); |
bzero(( void * ) packet + packet->src_addr + addr_len, padding ); |
if( padding ) bzero(( void * ) packet + packet->src_addr + addr_len, padding ); |
}else{ |
bzero(( void * ) packet + packet->src_addr + addr_len, packet->addr_len ); |
} |
if( dest ){ |
memcpy(( void * ) packet + packet->dest_addr, dest, addr_len ); |
bzero(( void * ) packet + packet->dest_addr + addr_len, padding ); |
if( padding ) bzero(( void * ) packet + packet->dest_addr + addr_len, padding ); |
}else{ |
bzero(( void * ) packet + packet->dest_addr + addr_len, packet->addr_len ); |
} |
173,7 → 173,7 |
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, & packet_id, & size )) |
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; |
} |
187,7 → 187,7 |
unsigned int size; |
packet_t packet; |
if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, & packet_id, & size )) |
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; |
} |
/branches/network/uspace/srv/net/structures/packet/packet.h |
---|
40,7 → 40,7 |
/** Packet identifier type. |
* Value zero (0) is used as an invalid identifier. |
*/ |
typedef unsigned int packet_id_t; |
typedef int packet_id_t; |
/** Type definition of the packet. |
* @see packet |
/branches/network/uspace/srv/net/structures/packet/packet_server.c |
---|
98,7 → 98,7 |
* The maximal lengths of packets in each queue in the ascending order. |
* The last queue is not limited. |
*/ |
int sizes[ FREE_QUEUES_COUNT ]; |
size_t sizes[ FREE_QUEUES_COUNT ]; |
/** Total packets allocated. |
*/ |
unsigned int count; |
/branches/network/uspace/srv/net/structures/int_map.h |
---|
57,7 → 57,7 |
}; \ |
\ |
struct name{ \ |
int size; \ |
size_t size; \ |
int next; \ |
name##_item_ref items; \ |
int magic; \ |
/branches/network/uspace/srv/net/networking/startup/networking_startup.c |
---|
74,7 → 74,8 |
int networking_phone; |
printf( "\nTask %d - %s", task_get_id(), NAME ); |
printf( "\nTask %d - ", task_get_id()); |
printf( "%s", NAME ); |
// run self tests |
ERROR_PROPAGATE( self_test()); |
// start networking service |
/branches/network/uspace/srv/net/networking/networking.c |
---|
56,7 → 56,8 |
#include "../structures/packet/packet_server.h" |
#include "../il/ip/ip_messages.h" |
#include "../netif/device.h" |
#include "../include/device.h" |
#include "../include/netif_messages.h" |
#if IP_BUNDLE |
432,6 → 433,7 |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.5" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
484,7 → 486,7 |
irq = setting ? strtol( setting->value, NULL, 10 ) : 0; |
setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); |
io = setting ? strtol( setting->value, NULL, 16 ) : 0; |
ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, irq, io )); |
ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io )); |
if( netif->nil ){ |
setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); |
if( ! setting ){ |
491,7 → 493,7 |
setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 ); |
} |
mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service, mtu )); |
ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, mtu, netif->driver->service )); |
internet_service = netif->nil->service; |
}else{ |
internet_service = netif->driver->service; |
498,7 → 500,7 |
} |
// TODO IL_BUNDLE |
ERROR_PROPAGATE( async_req_2_0( netif->il->phone, NET_IL_DEVICE, netif->id, internet_service )); |
ERROR_PROPAGATE( async_req_1_0( netif->driver->phone, NET_NETIF_START, netif->id )); |
ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id )); |
return EOK; |
} |
/branches/network/uspace/srv/net/modules.c |
---|
43,13 → 43,13 |
#define MODULE_WAIT_TIME 10000 |
int connect_to_service( services_t need ){ |
ipcarg_t phone; |
int res; |
int phone; |
int res; |
res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, & phone ); |
res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, ( ipcarg_t * ) & phone ); |
while(( res < 0 ) || ( phone < 0 )){ |
usleep( MODULE_WAIT_TIME ); |
res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, & phone ); |
res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, ( ipcarg_t * ) & phone ); |
} |
return phone; |
} |
57,7 → 57,7 |
int bind_service( services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver ){ |
ERROR_DECLARE; |
ipcarg_t phone; |
int phone; |
ipcarg_t phonehash; |
phone = connect_to_service( need ); |
/branches/network/uspace/srv/net/messages.h |
---|
104,23 → 104,9 |
#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 ) |
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
typedef enum { |
/* ( device_id, irq, io ) */ |
NET_NETIF_PROBE = NET_NETIF_FIRST, |
/* () not supported, should ask networking for a name and register device */ |
NET_NETIF_PROBE_AUTO, |
/* ( device_id, packet_id ) */ |
NET_NETIF_SEND, |
/* ( device_id ) */ |
NET_NETIF_START, |
/* ( device_id ), ipc_data_read( stats ) */ |
NET_NETIF_STATS, |
/* ( device_id ) */ |
NET_NETIF_STOP, |
/* */ |
NET_NETIF_SET_ADDR, |
/* */ |
NET_NETIF_GET_ADDR, |
/* () not supported, registers new device */ |
NET_NET_DEVICE = NET_NET_FIRST, |
/* ( NULL, count ), measured_strings_send( names ), measured_strings_return( values ) */ |
/branches/network/uspace/srv/net/Makefile.module |
---|
35,6 → 35,9 |
CFLAGS += -Iinclude -I../libadt/include |
CHECK_CFLAGS = -fsyntax-only -Wextra -Wno-div-by-zero -Wsystem-headers -Wfloat-equal -Wdeclaration-after-statement -Wundef -Wno-endif-labels -Wshadow -Wlarger-than-1500 -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-format-attribute -Wno-multichar -Wno-deprecated-declarations -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Winvalid-pch -Wlong-long -Wvariadic-macros -Wdisabled-optimization -Wno-pointer-sign |
#-Wtraditional |
LIBS = $(LIBC_PREFIX)/libc.a |
DEFS += $(NET_DEFS) -D $(NAME)_message=module_message -D $(NAME)_start_module=module_start -D $(NAME)_print_name=module_print_name |
46,6 → 49,9 |
all: $(OUTPUT) $(DISAMS) |
check: |
$(CC) $(DEFS) $(CFLAGS) $(CHECK_CFLAGS) *.c |
-include Makefile.depend |
clean: |
/branches/network/uspace/srv/net/il/arp/arp_header.h |
---|
69,7 → 69,7 |
* @see arp_oc.h |
*/ |
uint16_t operation; |
}; |
} __attribute__ ((packed)); |
#endif |
/branches/network/uspace/srv/net/il/arp/arp.c |
---|
48,8 → 48,9 |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../include/byteorder.h" |
#include "../../include/device.h" |
#include "../../include/protocol_map.h" |
#include "../../netif/device.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet.h" |
223,7 → 224,7 |
} |
printf( "\nCache of the existing device %d cleaned", device->device_id ); |
}else{ |
index = protocol_map( service, protocol ); |
index = hardware_map( service ); |
if( ! index ) return ENOENT; |
// create a new device |
device = ( arp_device_ref ) malloc( sizeof( arp_device_t )); |
319,39 → 320,23 |
arp_header_ref header; |
if( ! target ) return NULL; |
rwlock_read_lock( & arp_globals.lock ); |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return NULL; |
} |
if( ! device ) return NULL; |
proto = arp_protos_find( & device->protos, protocol ); |
if(( ! proto ) || ( proto->addr->length != target->length )){ |
rwlock_read_unlock( & arp_globals.lock ); |
return NULL; |
} |
if(( ! proto ) || ( proto->addr->length != target->length )) return NULL; |
addr = arp_addr_find( & proto->addresses, target->value, target->length ); |
if( addr ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return addr; |
} |
if( addr ) return addr; |
// ARP packet content size = header + ( address + translation ) * 2 |
length = 8 + ( CONVERT_SIZE( char, uint8_t, proto->addr->length ) + CONVERT_SIZE( char, uint8_t, device->addr->length )) * 2; |
if( length > device->content ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return NULL; |
} |
if( length > device->content ) return NULL; |
packet = packet_get_4( arp_globals.networking_phone, device->addr_len, device->prefix, length, device->suffix ); |
if( ! packet ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return NULL; |
} |
if( ! packet ) return NULL; |
header = ( arp_header_ref ) packet_suffix( packet, length ); |
header->hardware = device->hardware; |
header->hardware = htons( device->hardware ); |
header->hardware_length = device->addr->length; |
header->protocol = protocol_map( device->service, protocol ); |
header->protocol = htons( protocol_map( device->service, protocol )); |
header->protocol_length = proto->addr->length; |
header->operation = ARPOP_REQUEST; |
header->operation = htons( ARPOP_REQUEST ); |
length = sizeof( arp_header_t ); |
memcpy((( uint8_t * ) header ) + length, device->addr->value, device->addr->length ); |
length += device->addr->length; |
361,8 → 346,7 |
length += device->addr->length; |
memcpy((( uint8_t * ) header ) + length, target->value, target->length ); |
packet_set_addr( packet, ( uint8_t * ) device->addr->value, ( uint8_t * ) device->broadcast_addr->value, CONVERT_SIZE( char, uint8_t, device->addr->length )); |
async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet )); |
rwlock_read_unlock( & arp_globals.lock ); |
async_msg_3( device->phone, NET_NIL_SEND, device_id, packet_get_id( packet ), SERVICE_ARP ); |
return NULL; |
} |
381,23 → 365,15 |
length = packet_get_data_length( packet ); |
if( length <= sizeof( arp_header_t )) return EINVAL; |
rwlock_read_lock( & arp_globals.lock ); |
device = arp_cache_find( & arp_globals.cache, device_id ); |
if( ! device ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
if( ! device ) return ENOENT; |
header = ( arp_header_ref ) packet_get_data( packet ); |
if(( header->hardware != device->hardware ) |
if(( ntohs( header->hardware ) != device->hardware ) |
|| ( length < sizeof( arp_header_t ) + ( header->hardware_length + header->protocol_length ) * 2 )){ |
rwlock_read_unlock( & arp_globals.lock ); |
return EINVAL; |
} |
proto = arp_protos_find( & device->protos, protocol_unmap( device->service, header->protocol )); |
if( ! proto ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
proto = arp_protos_find( & device->protos, protocol_unmap( device->service, ntohs( header->protocol ))); |
if( ! proto ) return ENOENT; |
src_hw = (( uint8_t * ) header ) + sizeof( arp_header_t ); |
src_proto = src_hw + header->hardware_length; |
des_hw = src_proto + header->protocol_length; |
406,7 → 382,6 |
// exists? |
if( hw_source ){ |
if( hw_source->length != CONVERT_SIZE( uint8_t, char, header->hardware_length )){ |
rwlock_read_unlock( & arp_globals.lock ); |
return EINVAL; |
} |
memcpy( hw_source->value, src_hw, hw_source->length ); |
413,7 → 388,6 |
} |
// is my protocol address? |
if( proto->addr->length != CONVERT_SIZE( uint8_t, char, header->hardware_length )){ |
rwlock_read_unlock( & arp_globals.lock ); |
return EINVAL; |
} |
if( ! strncmp( proto->addr->value, ( char * ) des_proto, proto->addr->length )){ |
420,26 → 394,18 |
// not already upadted? |
if( ! hw_source ){ |
hw_source = measured_string_create_bulk(( char * ) src_hw, CONVERT_SIZE( uint8_t, char, header->hardware_length )); |
if( ! hw_source ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return ENOMEM; |
} |
if( ERROR_OCCURRED( arp_addr_add( & proto->addresses, ( char * ) src_proto, CONVERT_SIZE( uint8_t, char, header->protocol_length ), hw_source ))){ |
rwlock_read_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
} |
if( ! hw_source ) return ENOMEM; |
ERROR_PROPAGATE( arp_addr_add( & proto->addresses, ( char * ) src_proto, CONVERT_SIZE( uint8_t, char, header->protocol_length ), hw_source )); |
} |
if( header->operation == ARPOP_REQUEST ){ |
header->operation = ARPOP_REPLY; |
if( ntohs( header->operation ) == ARPOP_REQUEST ){ |
header->operation = htons( ARPOP_REPLY ); |
memcpy( des_proto, src_proto, header->protocol_length ); |
memcpy( src_proto, proto->addr->value, header->protocol_length ); |
memcpy( src_hw, des_hw, header->hardware_length ); |
memcpy( des_hw, hw_source->value, header->hardware_length ); |
packet_set_addr( packet, src_hw, des_hw, header->hardware_length ); |
async_msg_3( device->phone, NET_NETIF_SEND, device_id, SERVICE_ARP, packet_get_id( packet )); |
rwlock_read_unlock( & arp_globals.lock ); |
async_msg_3( device->phone, NET_NIL_SEND, device_id, packet_get_id( packet ), SERVICE_ARP ); |
}else{ |
rwlock_read_unlock( & arp_globals.lock ); |
pq_release( arp_globals.networking_phone, packet_get_id( packet )); |
} |
} |
502,6 → 468,7 |
measured_string_ref translation; |
char * data; |
// printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_ARP_FIRST ); |
* answer_count = 0; |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
515,11 → 482,17 |
return ERROR_CODE; |
case NET_ARP_TRANSLATE: |
ERROR_PROPAGATE( measured_strings_receive( & address, & data, 1 )); |
rwlock_read_lock( & arp_globals.lock ); |
translation = arp_translate_message( IPC_GET_DEVICE( call ), IPC_GET_PROTO( call ), address ); |
free( address ); |
free( data ); |
if( ! translation ) return ENOENT; |
return measured_strings_reply( translation, 1 ); |
if( ! translation ){ |
rwlock_read_unlock( & arp_globals.lock ); |
return ENOENT; |
} |
ERROR_CODE = measured_strings_reply( translation, 1 ); |
rwlock_read_unlock( & arp_globals.lock ); |
return ERROR_CODE; |
case NET_ARP_CLEAR_DEVICE: |
return arp_clear_device_message( IPC_GET_DEVICE( call )); |
case NET_ARP_CLEAN_CACHE: |
541,7 → 514,9 |
break; |
case NET_IL_RECEIVED: |
if( ! ERROR_OCCURRED( packet_translate( arp_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){ |
rwlock_read_lock( & arp_globals.lock ); |
ERROR_CODE = arp_receive_message( IPC_GET_DEVICE( icall ), packet ); |
rwlock_read_unlock( & arp_globals.lock ); |
} |
ipc_answer_0( iid, ERROR_CODE ); |
break; |
/branches/network/uspace/srv/net/il/arp/arp.h |
---|
41,7 → 41,7 |
#include <ipc/ipc.h> |
#include "../../netif/device.h" |
#include "../../include/device.h" |
#include "../../structures/generic_char_map.h" |
#include "../../structures/int_map.h" |
/branches/network/uspace/srv/net/il/ip/ip_header.h |
---|
122,7 → 122,7 |
/** The destination address. |
*/ |
uint32_t destination_address; |
}; |
} __attribute__ ((packed)); |
typedef struct ip_option ip_option_t; |
typedef ip_option * ip_option_ref; |
156,7 → 156,7 |
*/ |
uint8_t:4 overflow; |
#endif |
}; |
} __attribute__ ((packed)); |
#define IPTOS_TOS_MASK 0x1E |
#define IPTOS_PRECEDENCE_SHIFT 5 |
/branches/network/uspace/srv/net/il/ip/ip.c |
---|
46,7 → 46,7 |
#include "../../include/sockaddr.h" |
#include "../../include/socket.h" |
#include "../../netif/device.h" |
#include "../../include/device.h" |
#include "../../structures/measured_strings.h" |
#include "../../structures/module_map.h" |
#include "../../structures/packet/packet_client.h" |
276,8 → 276,38 |
} |
int ip_state_message( device_id_t device_id, device_state_t state ){ |
ERROR_DECLARE; |
ip_netif_ref netif; |
aid_t message; |
ipc_call_t answer; |
measured_string_t address; |
measured_string_ref translation; |
char * data; |
ipcarg_t result; |
netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
if( ! netif ) return ENOENT; |
// TODO state |
printf( "\nip - device %d changed state to %d\n", device_id, state ); |
if( netif->arp ){ |
message = async_send_2( netif->arp->phone, NET_ARP_TRANSLATE, netif->device_id, SERVICE_IP, & answer ); |
address.value = ( char * ) & netif->gateway; |
address.length = CONVERT_SIZE( in_addr_t, char, 1 ); |
if( ERROR_OCCURRED( measured_strings_send( netif->arp->phone, & address, 1 )) |
|| ERROR_OCCURRED( measured_strings_return( netif->arp->phone, & translation, & data, 1 ))){ |
async_wait_for( message, & result ); |
return result; |
} |
async_wait_for( message, & result ); |
if( ! ERROR_OCCURRED( result )){ |
printf( "\n\tgateway translated to\t= %X:%X:%X:%X:%X:%X", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
} |
free( translation ); |
free( data ); |
return result; |
} |
return EOK; |
} |
/branches/network/uspace/srv/net/il/ip/ip.h |
---|
40,7 → 40,7 |
#include <ipc/ipc.h> |
#include "../../include/sockaddr.h" |
#include "../../netif/device.h" |
#include "../../include/device.h" |
#include "../../structures/module_map.h" |
/branches/network/uspace/srv/net/netif/device.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
Deleted: svn:mergeinfo |
/branches/network/uspace/srv/net/netif/netif.c |
---|
49,16 → 49,13 |
#include "../structures/packet/packet_client.h" |
#include "../structures/measured_strings.h" |
#include "device.h" |
#include "../include/device.h" |
#include "../include/netif_messages.h" |
#include "netif.h" |
#include "netif_interface.h" |
#include "netif_wrappers.h" |
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
#define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
#define IPC_GET_IRQ( call ) ( int ) IPC_GET_ARG2( * call ) |
#define IPC_GET_IO( call ) ( int ) IPC_GET_ARG3( * call ) |
#define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
extern netif_globals_t netif_globals; |
DEVICE_MAP_IMPLEMENT( device_map, device_t ) |
67,6 → 64,57 |
int netif_start_module( async_client_conn_t client_connection ); |
int register_message( device_id_t device_id, int phone ); |
int netif_probe_wrapper( device_id_t device_id, int irq, int io ){ |
int result; |
rwlock_write_lock( & netif_globals.lock ); |
result = netif_probe_message( device_id, irq, io ); |
rwlock_write_unlock( & netif_globals.lock ); |
return result; |
} |
int netif_send_wrapper( device_id_t device_id, packet_t packet ){ |
int result; |
rwlock_write_lock( & netif_globals.lock ); |
result = netif_send_message( device_id, packet ); |
rwlock_write_unlock( & netif_globals.lock ); |
return result; |
} |
int netif_start_wrapper( device_id_t device_id ){ |
int result; |
rwlock_write_lock( & netif_globals.lock ); |
result = netif_start_message( device_id ); |
rwlock_write_unlock( & netif_globals.lock ); |
return result; |
} |
int netif_stop_wrapper( device_id_t device_id ){ |
int result; |
rwlock_write_lock( & netif_globals.lock ); |
result = netif_stop_message( device_id ); |
rwlock_write_unlock( & netif_globals.lock ); |
return result; |
} |
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address ){ |
ERROR_DECLARE; |
measured_string_t translation; |
if( ! address ) return EBADMEM; |
rwlock_read_lock( & netif_globals.lock ); |
if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){ |
* address = measured_string_create_bulk( translation.value, translation.length ); |
ERROR_CODE = ( * address ) ? EOK : ENOMEM; |
} |
rwlock_read_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
} |
int find_device( device_id_t device_id, device_ref * device ){ |
if( ! device ) return EBADMEM; |
* device = device_map_find( & netif_globals.device_map, device_id ); |
105,31 → 153,21 |
return EOK; |
case NET_NETIF_PROBE_AUTO: |
rwlock_write_lock( & netif_globals.lock ); |
ERROR_CODE = probe_auto_message(); |
ERROR_CODE = netif_probe_auto_message(); |
rwlock_write_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
case NET_NETIF_PROBE: |
rwlock_write_lock( & netif_globals.lock ); |
ERROR_CODE = probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call )); |
rwlock_write_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
return netif_probe_wrapper( NETIF_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call )); |
case IPC_M_CONNECT_TO_ME: |
rwlock_write_lock( & netif_globals.lock ); |
ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call )); |
ERROR_CODE = register_message( NETIF_GET_DEVICE( call ), IPC_GET_PHONE( call )); |
rwlock_write_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
case NET_NETIF_SEND: |
rwlock_write_lock( & netif_globals.lock ); |
if( ! ERROR_OCCURRED( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )))){ |
ERROR_CODE = send_message( IPC_GET_DEVICE( call ), packet ); |
} |
rwlock_write_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, NETIF_GET_PACKET( call ))); |
return netif_send_wrapper( NETIF_GET_DEVICE( call ), packet ); |
case NET_NETIF_START: |
rwlock_write_lock( & netif_globals.lock ); |
ERROR_CODE = start_message( IPC_GET_DEVICE( call )); |
rwlock_write_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
return netif_start_wrapper( NETIF_GET_DEVICE( call )); |
case NET_NETIF_STATS: |
rwlock_read_lock( & netif_globals.lock ); |
if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){ |
136,7 → 174,7 |
if( length < sizeof( device_stats_t )){ |
ERROR_CODE = EOVERFLOW; |
}else{ |
if( ! ERROR_OCCURRED( get_device_stats( IPC_GET_DEVICE( call ), & stats ))){ |
if( ! ERROR_OCCURRED( netif_get_device_stats( NETIF_GET_DEVICE( call ), & stats ))){ |
ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t )); |
} |
} |
144,19 → 182,16 |
rwlock_read_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
case NET_NETIF_STOP: |
rwlock_write_lock( & netif_globals.lock ); |
ERROR_CODE = stop_message( IPC_GET_DEVICE( call )); |
rwlock_write_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
return netif_stop_wrapper( NETIF_GET_DEVICE( call )); |
case NET_NETIF_GET_ADDR: |
rwlock_read_lock( & netif_globals.lock ); |
if( ! ERROR_OCCURRED( get_addr_message( IPC_GET_DEVICE( call ), & address ))){ |
if( ! ERROR_OCCURRED( netif_get_addr_message( NETIF_GET_DEVICE( call ), & address ))){ |
ERROR_CODE = measured_strings_reply( & address, 1 ); |
} |
rwlock_read_unlock( & netif_globals.lock ); |
return ERROR_CODE; |
} |
return specific_message( callid, call, answer, answer_count ); |
return netif_specific_message( callid, call, answer, answer_count ); |
} |
int netif_start_module( async_client_conn_t client_connection ){ |
167,7 → 202,7 |
device_map_initialize( & netif_globals.device_map ); |
ERROR_PROPAGATE( pm_init()); |
rwlock_initialize( & netif_globals.lock ); |
if( ERROR_OCCURRED( initialize())){ |
if( ERROR_OCCURRED( netif_initialize())){ |
pm_destroy(); |
return ERROR_CODE; |
} |
/branches/network/uspace/srv/net/netif/dp8390/dp8390.c |
---|
1524,7 → 1524,7 |
static void insb(port_t port, void *buf, size_t size) |
{ |
int i; |
size_t i; |
for( i = 0; i < size; ++ i ){ |
*(( uint8_t * )( buf + i )) = inb( port ); |
1533,7 → 1533,7 |
static void insw(port_t port, void *buf, size_t size) |
{ |
int i; |
size_t i; |
for( i = 0; i < size; i += 2 ){ |
*(( uint16_t * )( buf + i )) = inw( port ); |
1542,7 → 1542,7 |
static void outsb(port_t port, void *buf, size_t size) |
{ |
int i; |
size_t i; |
for( i = 0; i < size; ++ i ){ |
outb( port, *(( uint8_t * )( buf + i ))); |
1551,7 → 1551,7 |
static void outsw(port_t port, void *buf, size_t size) |
{ |
int i; |
size_t i; |
for( i = 0; i < size; i += 2 ){ |
outw( port, *(( uint16_t * )( buf + i ))); |
/branches/network/uspace/srv/net/netif/dp8390/Makefile |
---|
46,4 → 46,6 |
$(STRUCTURES)packet/packet_client.c \ |
$(STRUCTURES)packet/packet.c |
NET_DEFS += -D NETIF_BUNDLE=1 |
include $(NET_BASE)Makefile.module |
/branches/network/uspace/srv/net/netif/dp8390/dp8390_module.c |
---|
48,7 → 48,8 |
#include "../../structures/packet/packet_client.h" |
#include "../../structures/measured_strings.h" |
#include "../device.h" |
#include "../../include/device.h" |
#include "../netif.h" |
#include "../netif_interface.h" |
93,11 → 94,11 |
void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
void change_state( device_ref device, device_state_t state ); |
int specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
return ENOTSUP; |
} |
int get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
ERROR_DECLARE; |
device_ref device; |
126,7 → 127,7 |
printf( "%s", NAME ); |
} |
int get_addr_message( device_id_t device_id, measured_string_ref address ){ |
int netif_get_addr_message( device_id_t device_id, measured_string_ref address ){ |
ERROR_DECLARE; |
device_ref device; |
166,13 → 167,14 |
"unable enable interrupts", r); |
} |
*/// } |
ipc_answer_0( iid, EOK ); |
} |
int probe_auto_message( void ){ |
int netif_probe_auto_message( void ){ |
return ENOTSUP; |
} |
int probe_message( device_id_t device_id, int irq, int io ){ |
int netif_probe_message( device_id_t device_id, int irq, int io ){ |
ERROR_DECLARE; |
device_ref device; |
210,7 → 212,7 |
return EOK; |
} |
int send_message( device_id_t device_id, packet_t packet ){ |
int netif_send_message( device_id_t device_id, packet_t packet ){ |
ERROR_DECLARE; |
device_ref device; |
217,6 → 219,10 |
dpeth_t * dep; |
packet_t next; |
uint8_t * data; |
data = packet_get_data( packet ); |
printf( "\nSending packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX", packet_get_id( packet ), packet_get_data_length( packet ), data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ], data[ 16 ], data[ 17 ], data[ 18 ], data[ 19 ], data[ 20 ], data[ 21 ], data[ 22 ], data[ 23 ], data[ 24 ], data[ 25 ], data[ 26 ], data[ 27 ], data[ 28 ], data[ 29 ], data[ 30 ], data[ 31 ], data[ 32 ], data[ 33 ], data[ 34 ], data[ 35 ], data[ 36 ], data[ 37 ], data[ 38 ], data[ 39 ], data[ 40 ], data[ 41 ], data[ 42 ], data[ 43 ], data[ 44 ], data[ 45 ], data[ 46 ], data[ 47 ], data[ 48 ], data[ 49 ], data[ 50 ], data[ 51 ], data[ 52 ], data[ 53 ], data[ 54 ], data[ 55 ], data[ 56 ], data[ 57 ], data[ 58 ], data[ 59 ] ); |
ERROR_PROPAGATE( find_device( device_id, & device )); |
dep = ( dpeth_t * ) device->specific; |
// process packet queue |
230,7 → 236,7 |
return EOK; |
} |
int start_message( device_id_t device_id ){ |
int netif_start_message( device_id_t device_id ){ |
ERROR_DECLARE; |
device_ref device; |
251,7 → 257,7 |
return EOK; |
} |
int stop_message( device_id_t device_id ){ |
int netif_stop_message( device_id_t device_id ){ |
ERROR_DECLARE; |
device_ref device; |
273,7 → 279,7 |
printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
} |
int initialize( void ){ |
int netif_initialize( void ){ |
ipcarg_t phonehash; |
async_set_interrupt_received( irq_handler ); |
/branches/network/uspace/srv/net/netif/lo/lo.c |
---|
47,6 → 47,8 |
#include "../../structures/measured_strings.h" |
#include "../../structures/packet/packet_client.h" |
#include "../../include/device.h" |
#include "../netif.h" |
#include "../netif_interface.h" |
63,21 → 65,23 |
int mtu; |
} lo_globals; |
int change_state_message( device_id_t device_id, device_state_t state ); |
int create( device_id_t device_id, device_ref * device ); |
static int change_state_message( device_id_t device_id, device_state_t state ); |
static int create( device_id_t device_id, device_ref * device ); |
void netif_print_name( void ); |
int specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
//TODO nil send message |
return ENOTSUP; |
} |
int get_addr_message( device_id_t device_id, measured_string_ref address ){ |
int netif_get_addr_message( device_id_t device_id, measured_string_ref address ){ |
if( ! address ) return EBADMEM; |
address->value = DEFAULT_ADDR; |
address->length = DEFAULT_ADDR_LEN; |
return EOK; |
} |
int get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
ERROR_DECLARE; |
device_ref device; |
88,7 → 92,7 |
return EOK; |
} |
int change_state_message( device_id_t device_id, device_state_t state ){ |
static int change_state_message( device_id_t device_id, device_state_t state ){ |
ERROR_DECLARE; |
device_ref device; |
102,7 → 106,7 |
return EOK; |
} |
int create( device_id_t device_id, device_ref * device ){ |
static int create( device_id_t device_id, device_ref * device ){ |
int index; |
if( device_map_count( & netif_globals.device_map ) > 0 ){ |
130,7 → 134,7 |
return EOK; |
} |
int initialize( void ){ |
int netif_initialize( void ){ |
ipcarg_t phonehash; |
return REGISTER_ME( SERVICE_LO, & phonehash ); |
140,7 → 144,7 |
printf( "%s", NAME ); |
} |
int probe_auto_message( void ){ |
int netif_probe_auto_message( void ){ |
/* ERROR_DECLARE; |
device_ref device; |
150,7 → 154,7 |
*/ return ENOTSUP; |
} |
int probe_message( device_id_t device_id, int irq, int io ){ |
int netif_probe_message( device_id_t device_id, int irq, int io ){ |
ERROR_DECLARE; |
device_ref device; |
194,7 → 198,7 |
return EOK; |
} |
int send_message( device_id_t device_id, packet_t packet ){ |
int netif_send_message( device_id_t device_id, packet_t packet ){ |
ERROR_DECLARE; |
device_ref device; |
216,11 → 220,11 |
return EOK; |
} |
int start_message( device_id_t device_id ){ |
int netif_start_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_ACTIVE ); |
} |
int stop_message( device_id_t device_id ){ |
int netif_stop_message( device_id_t device_id ){ |
return change_state_message( device_id, NETIF_STOPPED ); |
} |
/branches/network/uspace/srv/net/netif/lo/Makefile |
---|
44,4 → 44,6 |
$(STRUCTURES)packet/packet_client.c \ |
$(STRUCTURES)packet/packet.c |
NET_DEFS += -D NETIF_BUNDLE=1 |
include $(NET_BASE)Makefile.module |
/branches/network/uspace/srv/net/netif/netif.h |
---|
39,7 → 39,7 |
#include <rwlock.h> |
#include "device.h" |
#include "../include/device.h" |
/** Sends the notification message to the registered network interface layer module. |
* Wrapper of the async_msg_3(). |
/branches/network/uspace/srv/net/netif/netif_interface.h |
---|
38,17 → 38,17 |
#include "../structures/measured_strings.h" |
#include "../structures/packet/packet.h" |
#include "device.h" |
#include "../include/device.h" |
int initialize( void ); |
int probe_auto_message( void ); |
int probe_message( device_id_t device_id, int irq, int io ); |
int send_message( device_id_t device_id, packet_t packet ); |
int start_message( device_id_t device_id ); |
int stop_message( device_id_t device_id ); |
int get_addr_message( device_id_t device_id, measured_string_ref address ); |
int specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
int get_device_stats( device_id_t device_id, device_stats_ref stats ); |
int netif_initialize( void ); |
int netif_probe_auto_message( void ); |
int netif_probe_message( device_id_t device_id, int irq, int io ); |
int netif_send_message( device_id_t device_id, packet_t packet ); |
int netif_start_message( device_id_t device_id ); |
int netif_stop_message( device_id_t device_id ); |
int netif_get_addr_message( device_id_t device_id, measured_string_ref address ); |
int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ); |
#endif |
/branches/network/uspace/srv/net/netif/netif_wrappers.h |
---|
0,0 → 1,52 |
/* |
* 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 netif |
* @{ |
*/ |
#ifndef __NET_NETIF_WRAPPERS_H__ |
#define __NET_NETIF_WRAPPERS_H__ |
#include <ipc/ipc.h> |
#include "../structures/measured_strings.h" |
#include "../structures/packet/packet.h" |
#include "../include/device.h" |
int netif_probe_wrapper( device_id_t device_id, int irq, int io ); |
int netif_send_wrapper( device_id_t device_id, packet_t packet ); |
int netif_start_wrapper( device_id_t device_id ); |
int netif_stop_wrapper( device_id_t device_id ); |
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/sockaddr.c |
---|
99,10 → 99,10 |
if(( ! data ) || ( ! address )) return EINVAL; |
switch( family ){ |
case AF_INET: if( length < INET_ADDRSTRLEN ) return ENOMEM; |
sprintf( address, "%hhu.%hhu.%hhu.%hhu", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ] ); |
snprintf( address, length, "%hhu.%hhu.%hhu.%hhu", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ] ); |
return EOK; |
case AF_INET6: if( length < INET6_ADDRSTRLEN ) return ENOMEM; |
sprintf( address, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ] ); |
snprintf( address, length, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ] ); |
return EOK; |
default: return ENOTSUP; |
} |
/branches/network/uspace/srv/net/Makefile |
---|
53,6 → 53,8 |
CLEANS := $(addsuffix .clean,$(DIRS_ALL)) |
CHECKS := $(addsuffix .check,$(basename $(BUILDS))) |
.PHONY: all build $(BUILDS) $(CLEANS) clean distclean |
all: $(BUILDS) |
59,11 → 61,16 |
build: $(BUILDS) |
check: $(CHECKS) |
clean: $(CLEANS) |
find $(DIRS_ALL) ./ -name '*.o' -follow -exec rm \{\} \; |
distclean: clean |
$(CHECKS): |
-$(MAKE) -C $(basename $@) check |
$(CLEANS): |
-$(MAKE) -C $(basename $@) clean |