/branches/network/uspace/srv/net/crc.c |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/tl/tcp/tcp_header.h |
---|
32,7 → 32,7 |
/** @file |
* TCP header definition. |
* Names according to the linux src/include/linux/tcp.h header file. |
* Based on the RFC~793. |
*/ |
#ifndef __NET_TCP_HEADER_H__ |
40,6 → 40,16 |
#include <sys/types.h> |
/** Returns the actual TCP header length. |
* @param header The TCP packet header. Input parameter. |
*/ |
#define TCP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) |
/** Returns the actual TCP header length. |
* @param header The TCP packet header. Input parameter. |
*/ |
#define TCP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) |
/** Type definition of the transmission datagram header. |
* @see tcp_header |
*/ |
50,105 → 60,162 |
*/ |
typedef tcp_header_t * tcp_header_ref; |
/** Type definition of the transmission datagram header option. |
* @see tcp_option |
*/ |
typedef struct tcp_option tcp_option_t; |
/** Type definition of the transmission datagram header option pointer. |
* @see tcp_option |
*/ |
typedef tcp_option_t * tcp_option_ref; |
/** Type definition of the Maximum segment size TCP option. |
* @see ... |
*/ |
typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t; |
/** Type definition of the Maximum segment size TCP option pointer. |
* @see tcp_max_segment_size_option |
*/ |
typedef tcp_max_segment_size_option_t * tcp_max_segment_size_option_ref; |
/** Transmission datagram header. |
*/ |
struct tcp_header{ |
/** The 16-bit source port number, used by the receiver to reply. |
/** The source port number. |
*/ |
uint16_t source; |
/** The 16-bit destination port number. |
uint16_t source_port; |
/** The destination port number. |
*/ |
uint16_t dest; |
/** The sequence number of the first data byte in this segment. |
* If the SYN control bit is set, the sequence number is the initial sequence number (n) and the first data byte is n+1. |
uint16_t destination_port; |
/** The sequence number of the first data octet in this segment (except when SYN is present). |
* If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1. |
*/ |
uint32_t seq; |
/** If the ACK control bit is set, this field contains the value of the next sequence number that the receiver is expecting to receive. |
uint32_t sequence_number; |
/** If the ACK control bit is set this field contains the value of the next sequence number the sender of the segment is expecting to receive. |
* Once a~connection is established this is always sent. |
* @see acknowledge |
*/ |
uint32_t ack_seq; |
uint32_t acknowledgement_number; |
#ifdef ARCH_IS_BIG_ENDIAN |
/** The number of 32-bit words in the TCP header. |
* It indicates where the data begins. |
/** The number of 32~bit words in the TCP Header. |
* This indicates where the data begins. |
* The TCP header (even one including options) is an integral number of 32~bits long. |
*/ |
uint8_t doff:4; |
uint8_t header_length:4; |
/** Four bits reserved for future use. |
* Must be zero. |
*/ |
uint8_t res1:4; |
uint8_t reserved1:4; |
#else |
/** Four bits reserved for future use. |
* Must be zero. |
*/ |
uint8_t res1:4; |
/** The number of 32-bit words in the TCP header. |
* It indicates where the data begins. |
uint8_t reserved1:4; |
/** The number of 32~bit words in the TCP Header. |
* This indicates where the data begins. |
* The TCP header (even one including options) is an integral number of 32~bits long. |
*/ |
uint8_t doff:4; |
uint8_t header_length:4; |
#endif |
#ifdef ARCH_IS_BIG_ENDIAN |
/** Two bits reserved for future use. |
* Must be zero. |
*/ |
uint8_t res2:2; |
/** Indicates that the urgent pointer field is significant in this segment. |
uint8_t reserved2:2; |
/** Urgent Pointer field significant. |
* @see tcp_header:urgent_pointer |
*/ |
uint8_t urg:1; |
/** Indicates that the acknowledgment field is significant in this segment. |
uint8_t urgent:1; |
/** Acknowledgment field significant |
* @see tcp_header:acknowledgement_number |
*/ |
uint8_t ack:1; |
uint8_t acknowledge:1; |
/** Push function. |
*/ |
uint8_t psh:1; |
/** Resets the connection. |
uint8_t push:1; |
/** Reset the connection. |
*/ |
uint8_t rst:1; |
/** Synchronizes the sequence numbers. |
uint8_t reset:1; |
/** Synchronize the sequence numbers. |
*/ |
uint8_t syn:1; |
/** No more data from sender. |
uint8_t synchronize:1; |
/** No more data from the sender. |
*/ |
uint8_t fin:1; |
uint8_t finalize:1; |
#else |
/** No more data from sender. |
/** No more data from the sender. |
*/ |
uint8_t fin:1; |
/** Synchronizes the sequence numbers. |
uint8_t finalize:1; |
/** Synchronize the sequence numbers. |
*/ |
uint8_t syn:1; |
/** Resets the connection. |
uint8_t synchronize:1; |
/** Reset the connection. |
*/ |
uint8_t rst:1; |
uint8_t reset:1; |
/** Push function. |
*/ |
uint8_t psh:1; |
/** Indicates that the acknowledgment field is significant in this segment. |
uint8_t push:1; |
/** Acknowledgment field significant. |
* @see tcp_header:acknowledgement_number |
*/ |
uint8_t ack:1; |
/** Indicates that the urgent pointer field is significant in this segment. |
uint8_t acknowledge:1; |
/** Urgent Pointer field significant. |
* @see tcp_header:urgent_pointer |
*/ |
uint8_t urg:1; |
uint8_t urgent:1; |
/** Two bits reserved for future use. |
* Must be zero. |
*/ |
uint8_t res2:2; |
uint8_t reserved2:2; |
#endif |
/** Used in ACK segments. |
* It specifies the number of data bytes, beginning with the one indicated in the acknowledgment number field that the receiver (the sender of this segment) is willing to accept. |
/** The number of data octets beginning with the one indicated in the acknowledgment field which the sender of this segment is willing to accept. |
* @see tcp_header:acknowledge |
*/ |
uint16_t window; |
/** The 16-bit one's complement of the one's complement sum of all 16-bit words in a pseudo-header, the TCP header, and the TCP data. |
* While computing the checksum, the checksum field itself is considered zero. |
/** The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header and text. |
* If a~segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a~16~bit word for checksum purposes. |
* The pad is not transmitted as part of the segment. |
* While computing the checksum, the checksum field itself is replaced with zeros. |
* The checksum also coves a~pseudo header conceptually. |
* The pseudo header conceptually prefixed to the TCP header contains the source address, the destination address, the protocol, and the TCP length. |
* This information gives protection against misrouted datagrams. |
* If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic). |
*/ |
uint16_t check; |
/** Points to the first data octet following the urgent data. |
* Only significant when the URG control bit is set. |
uint16_t checksum; |
/** This field communicates the current value of the urgent pointer as a~positive offset from the sequence number in this segment. |
* The urgent pointer points to the sequence number of the octet following the urgent data. |
* This field is only be interpreted in segments with the URG control bit set. |
* @see tcp_header:urgent |
*/ |
uint16_t urg_ptr; |
uint16_t urgent_pointer; |
} __attribute__ ((packed)); |
/** Transmission datagram header option. |
*/ |
struct tcp_option{ |
/** Option type. |
*/ |
uint8_t type; |
/** Option length. |
*/ |
uint8_t length; |
}; |
/** Maximum segment size TCP option. |
*/ |
struct tcp_max_segment_size_option{ |
/** TCP option. |
* @see TCPOPT_MAX_SEGMENT_SIZE |
* @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH |
*/ |
tcp_option_t option; |
/** Maximum segment size in bytes. |
*/ |
uint16_t max_segment_size; |
} __attribute__ ((packed)); |
#endif |
/** @} |
/branches/network/uspace/srv/net/tl/tcp/Makefile |
---|
38,7 → 38,7 |
SOURCES = \ |
$(NAME).c \ |
$(NAME)_module.c \ |
$(NET_BASE)crc.c \ |
$(NET_BASE)checksum.c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(NET_BASE)il/ip/ip_client.c \ |
/branches/network/uspace/srv/net/tl/icmp/icmp_messages.h |
---|
61,10 → 61,6 |
* @see icmp_source_quench_msg() |
*/ |
NET_ICMP_SOURCE_QUENCH, |
/** Sends redirect error message. |
* @see icmp_redirect_msg() |
*/ |
NET_ICMP_REDIRECT, |
/** Sends time exceeded error message. |
* @see icmp_time_exceeded_msg() |
*/ |
/branches/network/uspace/srv/net/tl/icmp/icmp_client.c |
---|
36,6 → 36,7 |
*/ |
#include <errno.h> |
//#include <stdio.h> |
#include <sys/types.h> |
59,6 → 60,8 |
if( code ) * code = header->code; |
if( pointer ) * pointer = header->un.param.pointer; |
if( mtu ) * mtu = header->un.frag.mtu; |
// remove debug dump |
// printf( "ICMP error %d (%d) in packet %d\n", header->type, header->code, packet_get_id( packet )); |
return sizeof( icmp_header_t ); |
} |
/branches/network/uspace/srv/net/tl/icmp/icmp.c |
---|
53,7 → 53,7 |
#include "../../structures/packet/packet_client.h" |
#include "../../include/byteorder.h" |
#include "../../include/crc.h" |
#include "../../include/checksum.h" |
#include "../../include/icmp_api.h" |
#include "../../include/icmp_client.h" |
#include "../../include/icmp_codes.h" |
/branches/network/uspace/srv/net/tl/icmp/Makefile |
---|
39,7 → 39,7 |
$(NAME).c \ |
$(NAME)_module.c \ |
$(NAME)_client.c \ |
$(NET_BASE)crc.c \ |
$(NET_BASE)checksum.c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(NET_BASE)il/ip/ip_client.c \ |
/branches/network/uspace/srv/net/tl/tl_common.c |
---|
56,7 → 56,7 |
const struct sockaddr_in * address_in; |
const struct sockaddr_in6 * address_in6; |
if( addrlen < sizeof( struct sockaddr )) return EINVAL; |
if(( addrlen <= 0 ) || (( size_t ) addrlen < sizeof( struct sockaddr ))) return EINVAL; |
switch( addr->sa_family ){ |
case AF_INET: |
if( addrlen != sizeof( struct sockaddr_in )) return EINVAL; |
/branches/network/uspace/srv/net/tl/udp/udp.c |
---|
38,6 → 38,7 |
#include <async.h> |
#include <fibril_sync.h> |
#include <malloc.h> |
#include <stdio.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
49,7 → 50,7 |
#include "../../structures/dynamic_fifo.h" |
#include "../../structures/packet/packet_client.h" |
#include "../../include/crc.h" |
#include "../../include/checksum.h" |
#include "../../include/in.h" |
#include "../../include/in6.h" |
#include "../../include/inet.h" |
232,7 → 233,9 |
fibril_rwlock_write_lock( & udp_globals.lock ); |
result = udp_process_packet( packet, error ); |
if( result != EOK ){ |
fibril_rwlock_write_unlock( & udp_globals.lock ); |
} |
return result; |
} |
379,6 → 382,7 |
} |
// notify the destination socket |
fibril_rwlock_write_unlock( & udp_globals.lock ); |
async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, 0, 0, 0, ( ipcarg_t ) fragments ); |
return EOK; |
} |
414,7 → 418,7 |
/* |
* Accept the connection |
* - Answer the first IPC_M_CONNECT_ME_TO call. |
* - Answer the first IPC_M_CONNECT_TO_ME call. |
*/ |
ipc_answer_0( callid, EOK ); |
461,7 → 465,9 |
fibril_rwlock_read_lock( & lock ); |
fibril_rwlock_write_lock( & udp_globals.lock ); |
res = udp_sendto_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_GET_DATA_FRAGMENT_SIZE( call ), SOCKET_GET_FLAGS( call )); |
if( res != EOK ){ |
fibril_rwlock_write_unlock( & udp_globals.lock ); |
} |
fibril_rwlock_read_unlock( & lock ); |
free( addr ); |
} |
527,24 → 533,24 |
if(( socket->port <= 0 ) && udp_globals.autobinding ){ |
// bind the socket to a random free port if not bound |
do{ |
// do{ |
// try to find a free port |
// fibril_rwlock_read_unlock( & udp_globals.lock ); |
// fibril_rwlock_write_lock( & udp_globals.lock ); |
// might be changed in the meantime |
if( socket->port <= 0 ){ |
// if( socket->port <= 0 ){ |
if( ERROR_OCCURRED( socket_bind_free_port( & udp_globals.sockets, socket, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, udp_globals.last_used_port ))){ |
fibril_rwlock_write_unlock( & udp_globals.lock ); |
fibril_rwlock_read_lock( & udp_globals.lock ); |
// fibril_rwlock_write_unlock( & udp_globals.lock ); |
// fibril_rwlock_read_lock( & udp_globals.lock ); |
return ERROR_CODE; |
} |
// set the next port as the search starting port number |
udp_globals.last_used_port = socket->port; |
} |
// } |
// fibril_rwlock_write_unlock( & udp_globals.lock ); |
// fibril_rwlock_read_lock( & udp_globals.lock ); |
// might be changed in the meantime |
}while( socket->port <= 0 ); |
// }while( socket->port <= 0 ); |
} |
// TODO do not ask all the time |
602,7 → 608,9 |
return udp_release_and_return( packet, ERROR_CODE ); |
} |
// send the packet |
return ip_send_msg( udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0 ); |
fibril_rwlock_write_unlock( & udp_globals.lock ); |
ip_send_msg( udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0 ); |
return EOK; |
} |
int udp_recvfrom_message( socket_cores_ref local_sockets, int socket_id, int flags, size_t * addrlen ){ |
/branches/network/uspace/srv/net/tl/udp/Makefile |
---|
38,7 → 38,7 |
SOURCES = \ |
$(NAME).c \ |
$(NAME)_module.c \ |
$(NET_BASE)crc.c \ |
$(NET_BASE)checksum.c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(NET_BASE)il/ip/ip_client.c \ |
/branches/network/uspace/srv/net/tl/tl_messages.h |
---|
40,6 → 40,8 |
#include <ipc/ipc.h> |
#include "../messages.h" |
/** Transport layer modules messages. |
*/ |
typedef enum{ |
/branches/network/uspace/srv/net/app/nettest1/nettest1.c |
---|
38,6 → 38,7 |
#include <stdio.h> |
#include <string.h> |
#include <task.h> |
#include <time.h> |
#include "../../include/in.h" |
#include "../../include/in6.h" |
83,10 → 84,10 |
*/ |
int parse_socket_type( const char * name ); |
void refresh_data( char * data, int size ); |
void refresh_data( char * data, size_t size ); |
int sockets_create( int verbose, int * socket_ids, int sockets, int family, sock_type_t type ); |
int sockets_close( int verbose, int * socket_ids, int sockets ); |
int sockets_bind( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen ); |
int sockets_connect( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen ); |
int sockets_sendto( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages ); |
int sockets_recvfrom( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages ); |
int sockets_sendto_recvfrom( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages ); |
138,8 → 139,8 |
return ESOCKTNOSUPPORT; |
} |
void refresh_data( char * data, int size ){ |
int length; |
void refresh_data( char * data, size_t size ){ |
size_t length; |
// fill the data |
length = 0; |
185,17 → 186,16 |
return EOK; |
} |
int sockets_bind( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen ){ |
int sockets_connect( int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen ){ |
ERROR_DECLARE; |
int index; |
if( verbose ) printf( "\tBind\t" ); |
if( verbose ) printf( "\tConnect\t" ); |
fflush( stdout ); |
for( index = 0; index < sockets; ++ index ){ |
if( ERROR_OCCURRED( bind( socket_ids[ index ], address, addrlen ))){ |
printf( "Socket %d (%d) error:\n", index, socket_ids[ index ] ); |
socket_print_error( stderr, ERROR_CODE, "Socket bind: ", "\n" ); |
if( ERROR_OCCURRED( connect( socket_ids[ index ], address, addrlen ))){ |
socket_print_error( stderr, ERROR_CODE, "Socket connect: ", "\n" ); |
return ERROR_CODE; |
} |
if( verbose ) print_mark( index ); |
306,6 → 306,8 |
char * data; |
int value; |
int index; |
struct timeval time_before; |
struct timeval time_after; |
printf( "Task %d - ", task_get_id()); |
printf( "%s\n", NAME ); |
425,28 → 427,28 |
if( verbose ) printf( "1 socket, 1 message\n" ); |
if( ERROR_OCCURRED( gettimeofday( & time_before, NULL ))){ |
fprintf( stderr, "Get time of day error %d\n", ERROR_CODE ); |
return ERROR_CODE; |
} |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, 1, family, type )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, 1 )); |
if( verbose ) printf( "\tOK\n" ); |
if( type == SOCK_DGRAM ){ |
/* ERROR_PROPAGATE( sockets_create( verbose, socket_ids, 1 )); |
ERROR_PROPAGATE( sockets_bind( verbose, socket_ids, 1, address, addrlen )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, 1 )); |
*/ |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, 1, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, 1, address, & addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, 1, address, & addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, 1 )); |
if( verbose ) printf( "\tOK\n" ); |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, 1, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, 1, address, addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, 1, address, addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_recvfrom( verbose, socket_ids, 1, address, & addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, 1 )); |
if( verbose ) printf( "\tOK\n" ); |
454,18 → 456,18 |
if( verbose ) printf( "1 socket, %d messages\n", messages ); |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, 1, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, 1, address, & addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, 1, address, & addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, 1 )); |
if( verbose ) printf( "\tOK\n" ); |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, 1, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, 1, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, 1, address, addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, 1, address, addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_recvfrom( verbose, socket_ids, 1, address, & addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, 1 )); |
if( verbose ) printf( "\tOK\n" ); |
476,24 → 478,19 |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, sockets )); |
if( verbose ) printf( "\tOK\n" ); |
/* ERROR_PROPAGATE( sockets_create( verbose, socket_ids, sockets )); |
ERROR_PROPAGATE( sockets_bind( verbose, socket_ids, sockets, address, addrlen )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, sockets )); |
*/ |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, sockets, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, sockets, address, & addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, sockets, address, & addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, sockets )); |
if( verbose ) printf( "\tOK\n" ); |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, sockets, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, sockets, address, addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, sockets, address, addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_recvfrom( verbose, socket_ids, sockets, address, & addrlen, data, size, 1 )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, sockets )); |
if( verbose ) printf( "\tOK\n" ); |
501,66 → 498,30 |
if( verbose ) printf( "%d sockets, %d messages\n", sockets, messages ); |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, sockets, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, sockets, address, & addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_sendto_recvfrom( verbose, socket_ids, sockets, address, & addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, sockets )); |
if( verbose ) printf( "\tOK\n" ); |
ERROR_PROPAGATE( sockets_create( verbose, socket_ids, sockets, family, type )); |
/* if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, & addrlen )); |
if( type == SOCK_STREAM ){ |
ERROR_PROPAGATE( sockets_connect( verbose, socket_ids, sockets, address, addrlen )); |
} |
*/ ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, sockets, address, addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_sendto( verbose, socket_ids, sockets, address, addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_recvfrom( verbose, socket_ids, sockets, address, & addrlen, data, size, messages )); |
ERROR_PROPAGATE( sockets_close( verbose, socket_ids, sockets )); |
if( verbose ) printf( "\tOK\n" ); |
} |
/* |
if( type == SOCK_STREAM ){ |
// TODO remove tests |
address_in->sin_addr.s_addr = 0x3f26b75a; |
address_in->sin_port = htons( 80 ); |
if( ERROR_OCCURRED( connect( listening_id, address, sizeof( struct sockaddr_in )))){ |
socket_print_error( stderr, ERROR_CODE, "Socket connect: ", "\n" ); |
return ERROR_CODE; |
} |
if( ERROR_OCCURRED( send( listening_id, "ahoj nekdo", 10, 0 ))){ |
socket_print_error( stderr, ERROR_CODE, "Socket send: ", "\n" ); |
return ERROR_CODE; |
} |
value = recv( socket_id, data, size, 0 ); |
fprintf( stderr, "Socket receive: %d\n", value ); |
if( ERROR_OCCURRED( send( listening_id, "ahoj nekdo", 10, 0 ))){ |
socket_print_error( stderr, ERROR_CODE, "Socket send: ", "\n" ); |
return ERROR_CODE; |
} |
value = recvfrom( socket_id, data, size, 0, address, & addrlen ); |
fprintf( stderr, "Socket receive: %d\n", value ); |
if( ERROR_OCCURRED( closesocket( listening_id ))){ |
socket_print_error( stderr, ERROR_CODE, "Close socket: ", "\n" ); |
if( ERROR_OCCURRED( gettimeofday( & time_after, NULL ))){ |
fprintf( stderr, "Get time of day error %d\n", ERROR_CODE ); |
return ERROR_CODE; |
} |
listening_id = socket( family, type, 0 ); |
if( listening_id < 0 ){ |
socket_print_error( stderr, listening_id, "Socket create: ", "\n" ); |
return listening_id; |
} |
if( ERROR_OCCURRED( listen( listening_id, 3 ))){ |
socket_print_error( stderr, ERROR_CODE, "Socket listen: ", "\n" ); |
return ERROR_CODE; |
} |
}else{ |
socket_id = listening_id; |
} |
if( ERROR_OCCURRED( bind( listening_id, address, addrlen ))){ |
socket_print_error( stderr, ERROR_CODE, "Socket bind: ", "\n" ); |
return ERROR_CODE; |
} |
*/ |
if( verbose ) printf( "\tOK\n" ); |
printf( "Tested in %d microseconds\n", tv_sub( & time_after, & time_before )); |
if( verbose ) printf( "Exiting\n" ); |
return EOK; |
/branches/network/uspace/srv/net/app/ping/ping.c |
---|
235,7 → 235,6 |
return ERROR_CODE; |
} |
// TODO timeout? |
icmp_phone = icmp_connect_module( SERVICE_ICMP ); |
if( icmp_phone < 0 ){ |
fprintf( stderr, "ICMP connect error %d\n", icmp_phone ); |
/branches/network/uspace/srv/net/app/echo/echo.c |
---|
297,6 → 297,7 |
if( socket_id <= 0 ){ |
socket_print_error( stderr, socket_id, "Socket accept: ", "\n" ); |
} |
if( verbose ) printf( "Socket %d accepted\n", socket_id ); |
} |
if( socket_id > 0 ){ |
value = recvfrom( socket_id, data, size, 0, address, & addrlen ); |
/branches/network/uspace/srv/net/nil/eth/eth.c |
---|
49,7 → 49,7 |
#include "../../modules.h" |
#include "../../include/byteorder.h" |
#include "../../include/crc.h" |
#include "../../include/checksum.h" |
#include "../../include/ethernet_lsap.h" |
#include "../../include/ethernet_protocols.h" |
#include "../../include/protocol_map.h" |
191,7 → 191,7 |
* @returns ENOMEM if there is not enough memory left. |
* @returns Other error codes as defined for the net_get_device_conf_req() function. |
* @returns Other error codes as defined for the netif_bind_service() function. |
* @returns Other error codes as defined for the netif_get_addr() function. |
* @returns Other error codes as defined for the netif_get_addr_req() function. |
*/ |
int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
363,9 → 363,7 |
if( ! str_lcmp( configuration[ 0 ].value, "DIX", configuration[ 0 ].length )){ |
device->flags |= ETH_DIX; |
}else if( ! str_lcmp( configuration[ 0 ].value, "8023_2_LSAP", configuration[ 0 ].length )){ |
// TODO 8023_2_LSAP |
printf( "8023_2_LSAP is not supported (yet?), DIX used instead\n" ); |
device->flags |= ETH_DIX; |
device->flags |= ETH_8023_2_LSAP; |
}else device->flags |= ETH_8023_2_SNAP; |
if(( configuration[ 1 ].value ) && ( configuration[ 1 ].value[ 0 ] == 'y' )){ |
device->flags |= ETH_DUMMY; |
382,7 → 380,7 |
return device->phone; |
} |
// get hardware address |
if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
if( ERROR_OCCURRED( netif_get_addr_req( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
fibril_rwlock_write_unlock( & eth_globals.devices_lock ); |
free( device ); |
return ERROR_CODE; |
405,7 → 403,7 |
eth_proto_ref eth_process_packet( int flags, packet_t packet ){ |
ERROR_DECLARE; |
eth_header_ex_ref header; |
eth_header_snap_ref header; |
size_t length; |
eth_type_t type; |
size_t prefix; |
419,7 → 417,7 |
} |
if( length < sizeof( eth_header_t ) + ETH_MIN_CONTENT + ( IS_DUMMY( flags ) ? ETH_SUFFIX : 0 )) return NULL; |
data = packet_get_data( packet ); |
header = ( eth_header_ex_ref ) data; |
header = ( eth_header_snap_ref ) data; |
type = ntohs( header->header.ethertype ); |
if( type >= ETH_MIN_PROTO ){ |
// DIX Ethernet |
566,7 → 564,8 |
} |
int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype, size_t mtu ){ |
eth_header_ex_ref header; |
eth_header_snap_ref header; |
eth_header_lsap_ref header_lsap; |
eth_header_ref header_dix; |
eth_fcs_ref fcs; |
uint8_t * src; |
592,8 → 591,7 |
for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
preamble->sfd = ETH_SFD; |
} |
// TODO LSAP only device |
if( IS_DIX( flags ) || IS_8023_2_LSAP( flags )){ |
if( IS_DIX( flags )){ |
header_dix = PACKET_PREFIX( packet, eth_header_t ); |
if( ! header_dix ) return ENOMEM; |
header_dix->ethertype = ( uint16_t ) ethertype; |
600,13 → 598,23 |
memcpy( header_dix->source_address, src_addr, ETH_ADDR ); |
memcpy( header_dix->destination_address, dest, ETH_ADDR ); |
src = & header_dix->destination_address[ 0 ]; |
}else if( IS_8023_2_LSAP( flags )){ |
header_lsap = PACKET_PREFIX( packet, eth_header_lsap_t ); |
if( ! header_lsap ) return ENOMEM; |
header_lsap->header.ethertype = htons( length + sizeof( eth_header_lsap_t )); |
header_lsap->lsap.dsap = lsap_unmap( ntohs( ethertype )); |
header_lsap->lsap.ssap = header_lsap->lsap.dsap; |
header_lsap->lsap.ctrl = IEEE_8023_2_UI; |
memcpy( header_lsap->header.source_address, src_addr, ETH_ADDR ); |
memcpy( header_lsap->header.destination_address, dest, ETH_ADDR ); |
src = & header_lsap->header.destination_address[ 0 ]; |
}else if( IS_8023_2_SNAP( flags )){ |
header = PACKET_PREFIX( packet, eth_header_ex_t ); |
header = PACKET_PREFIX( packet, eth_header_snap_t ); |
if( ! header ) return ENOMEM; |
header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
header->lsap.ssap = header->lsap.dsap; |
header->lsap.ctrl = 0; |
header->lsap.ctrl = IEEE_8023_2_UI; |
for( i = 0; i < 3; ++ i ) header->snap.protocol[ i ] = 0; |
header->snap.ethertype = ( uint16_t ) ethertype; |
memcpy( header->header.source_address, src_addr, ETH_ADDR ); |
/branches/network/uspace/srv/net/nil/eth/Makefile |
---|
35,7 → 35,7 |
SOURCES = \ |
$(NAME).c \ |
$(NAME)_module.c \ |
$(NET_BASE)crc.c \ |
$(NET_BASE)checksum.c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
$(NET_BASE)net/net_remote.c \ |
/branches/network/uspace/srv/net/nil/eth/eth_header.h |
---|
52,35 → 52,49 |
*/ |
#define ETH_SFD 0xD5 |
/** Type definition of the Ethernet header with all the extensions. |
* @see eth_header_ex |
/** IEEE 802.2 unordered information control field. |
*/ |
typedef struct eth_header_ex eth_header_ex_t; |
#define IEEE_8023_2_UI 0x03 |
/** Type definition of the Ethernet header with all the extensions pointer. |
* @see eth_header |
/** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. |
* @see eth_header_snap |
*/ |
typedef eth_header_ex_t * eth_header_ex_ref; |
typedef struct eth_header_snap eth_header_snap_t; |
/** Type definition of the Ethernet header LSAP extension. |
/** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions pointer. |
* @see eth_header_snap |
*/ |
typedef eth_header_snap_t * eth_header_snap_ref; |
/** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. |
* @see eth_header_lsap |
*/ |
typedef struct eth_header_lsap eth_header_lsap_t; |
/** Type definition of the Ethernet header LSAP extension pointer. |
/** Type definition of the Ethernet header IEEE 802.3 + 802.2 extension pointer. |
* @see eth_header_lsap |
*/ |
typedef eth_header_lsap_t * eth_header_lsap_ref; |
/** Type definition of the Ethernet header LSAP extension. |
* @see eth_ieee_lsap |
*/ |
typedef struct eth_ieee_lsap eth_ieee_lsap_t; |
/** Type definition of the Ethernet header LSAP extension pointer. |
* @see eth_ieee_lsap |
*/ |
typedef eth_ieee_lsap_t * eth_ieee_lsap_ref; |
/** Type definition of the Ethernet header SNAP extension. |
* @see eth_header_snap |
* @see eth_snap |
*/ |
typedef struct eth_header_snap eth_header_snap_t; |
typedef struct eth_snap eth_snap_t; |
/** Type definition of the Ethernet header SNAP extension pointer. |
* @see eth_header_snap |
* @see eth_snap |
*/ |
typedef eth_header_snap_t * eth_header_snap_ref; |
typedef eth_snap_t * eth_snap_ref; |
/** Type definition of the Ethernet header preamble. |
* @see preamble |
104,7 → 118,7 |
/** Ethernet header Link Service Access Point extension. |
*/ |
struct eth_header_lsap{ |
struct eth_ieee_lsap{ |
/** Destination Service Access Point identifier. |
* The possible values are assigned by an IEEE committee. |
*/ |
121,7 → 135,7 |
/** Ethernet header SNAP extension. |
*/ |
struct eth_header_snap{ |
struct eth_snap{ |
/** Protocol identifier or organization code. |
*/ |
uint8_t protocol[ 3 ]; |
160,9 → 174,9 |
uint16_t ethertype; |
} __attribute__ ((packed)); |
/** Ethernet header with all the extensions. |
/** Ethernet header IEEE 802.3 + 802.2 extension. |
*/ |
struct eth_header_ex{ |
struct eth_header_lsap{ |
/** Ethernet header. |
*/ |
eth_header_t header; |
170,10 → 184,23 |
* If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being used. |
* If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet without any extensions is being used and the frame content starts rigth after the two fields. |
*/ |
eth_header_lsap_t lsap; |
eth_ieee_lsap_t lsap; |
} __attribute__ ((packed)); |
/** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. |
*/ |
struct eth_header_snap{ |
/** Ethernet header. |
*/ |
eth_header_t header; |
/** LSAP extension. |
* If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being used. |
* If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet without any extensions is being used and the frame content starts rigth after the two fields. |
*/ |
eth_ieee_lsap_t lsap; |
/** SNAP extension. |
*/ |
eth_header_snap_t snap; |
eth_snap_t snap; |
} __attribute__ ((packed)); |
/** Ethernet Frame Check Sequence. |
/branches/network/uspace/srv/net/nil/nildummy/nildummy.c |
---|
87,7 → 87,7 |
* @returns EEXIST if the device with the different service exists. |
* @returns ENOMEM if there is not enough memory left. |
* @returns Other error codes as defined for the netif_bind_service() function. |
* @returns Other error codes as defined for the netif_get_addr() function. |
* @returns Other error codes as defined for the netif_get_addr_req() function. |
*/ |
int nildummy_device_message( device_id_t device_id, services_t service, size_t mtu ); |
208,7 → 208,7 |
return device->phone; |
} |
// get hardware address |
if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
if( ERROR_OCCURRED( netif_get_addr_req( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
free( device ); |
return ERROR_CODE; |
/branches/network/uspace/srv/net/checksum.c |
---|
0,0 → 1,141 |
/* |
* 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 |
* General CRC and checksum computation implementation. |
*/ |
#include <sys/types.h> |
#include "include/checksum.h" |
#define CRC_DIVIDER_BE 0x04C11DB7 |
#define CRC_DIVIDER_LE 0xEDB88320 |
/** IP checksum value for computed zero checksum. |
* Zero is returned as 0xFFFF (not flipped) |
*/ |
#define IP_CHECKSUM_ZERO 0xFFFFu |
uint32_t compute_crc32_le( uint32_t seed, uint8_t * data, size_t length ){ |
size_t index; |
while( length >= 8 ){ |
seed ^= ( * data ); |
for( index = 0; index < 8; ++ index ){ |
if( seed & 1 ){ |
seed = ( seed >> 1 ) ^ (( uint32_t ) CRC_DIVIDER_LE ); |
}else{ |
seed >>= 1; |
} |
} |
++ data; |
length -= 8; |
} |
if( length > 0 ){ |
seed ^= ( * data ) >> ( 8 - length ); |
for( index = 0; index < length; ++ index ){ |
if( seed & 1 ){ |
seed = ( seed >> 1 ) ^ (( uint32_t ) CRC_DIVIDER_LE ); |
}else{ |
seed >>= 1; |
} |
} |
length -= 8; |
} |
return seed; |
} |
uint32_t compute_crc32_be( uint32_t seed, uint8_t * data, size_t length ){ |
size_t index; |
while( length >= 8 ){ |
seed ^= ( * data ) << 24; |
for( index = 0; index < 8; ++ index ){ |
if( seed & 0x80000000 ){ |
seed = ( seed << 1 ) ^ (( uint32_t ) CRC_DIVIDER_BE ); |
}else{ |
seed <<= 1; |
} |
} |
++ data; |
length -= 8; |
} |
if( length > 0 ){ |
seed ^= (( * data ) & ( 0xFF << ( 8 - length ))) << 24; |
for( index = 0; index < length; ++ index ){ |
if( seed & 0x80000000 ){ |
seed = ( seed << 1 ) ^ (( uint32_t ) CRC_DIVIDER_BE ); |
}else{ |
seed <<= 1; |
} |
} |
length -= 8; |
} |
return seed; |
} |
uint32_t compute_checksum( uint32_t seed, uint8_t * data, size_t length ){ |
size_t index; |
// sum all the 16 bit fields |
for( index = 0; index + 1 < length; index += 2 ){ |
seed += ( data[ index ] << 8 ) + data[ index + 1 ]; |
} |
// last odd byte with zero padding |
if( index + 1 == length ){ |
seed += data[ index ] << 8; |
} |
return seed; |
} |
uint16_t compact_checksum( uint32_t sum ){ |
// shorten to the 16 bits |
while( sum >> 16 ) sum = ( sum & 0xFFFF ) + ( sum >> 16 ); |
return ( uint16_t ) sum; |
} |
uint16_t flip_checksum( uint16_t checksum ){ |
// flip, zero is returned as 0xFFFF (not flipped) |
return ( ~ checksum ) ? ( uint16_t ) ( ~ checksum ) : IP_CHECKSUM_ZERO; |
} |
uint16_t ip_checksum( uint8_t * data, size_t length ){ |
return flip_checksum( compact_checksum( compute_checksum( 0, data, length ))); |
} |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/structures/char_map.h |
---|
114,13 → 114,6 |
*/ |
int char_map_find( const char_map_ref map, const char * identifier, size_t length ); |
/** Returns the value assigned to the map. |
* @param map The character string to integer map. Input parameter. |
* @returns The integral value assigned to the map. |
* @returns CHAR_MAP_NULL if the map is not assigned a value. |
*/ |
int char_map_get_value( const char_map_ref map ); |
/** Initializes the map. |
* @param map The character string to integer map. Input/output parameter. |
* @returns EOK on success. |
/branches/network/uspace/srv/net/structures/generic_field.h |
---|
56,7 → 56,7 |
typedef name##_t * name##_ref; \ |
\ |
struct name{ \ |
size_t size; \ |
int size; \ |
int next; \ |
type ** items; \ |
int magic; \ |
/branches/network/uspace/srv/net/structures/packet/packet.h |
---|
52,23 → 52,6 |
*/ |
typedef packet_t * packet_ref; |
/** Type of the received packet. |
*/ |
enum packet_type{ |
/** The packet is from the local subsystem. |
*/ |
PACKET_SELF, |
/** The packet is for all hosts. |
*/ |
PACKET_BROADCAST, |
/** The packet target complies with the local subsystem filter. |
*/ |
PACKET_MULTICAST, |
/** The packet is for the local subsystem from other host. |
*/ |
PACKET_OTHERHOST |
}; |
/** @name Packet management system interface |
*/ |
/*@{*/ |
/branches/network/uspace/srv/net/structures/packet/packet_server.c |
---|
223,6 → 223,8 |
void packet_release( packet_t packet ){ |
int index; |
// remove debug dump |
// printf( "packet %d released\n", packet->packet_id ); |
for( index = 0; ( index < FREE_QUEUES_COUNT - 1 ) && ( packet->length > ps_globals.sizes[ index ] ); ++ index ); |
ps_globals.free[ index ] = pq_add( ps_globals.free[ index ], packet, packet->length, packet->length ); |
assert( ps_globals.free[ index ] ); |
249,6 → 251,8 |
} |
packet_init( packet, addr_len, max_prefix, max_content, max_suffix ); |
fibril_mutex_unlock( & ps_globals.lock ); |
// remove debug dump |
// printf( "packet %d got\n", packet->packet_id ); |
return packet; |
} |
} |
255,6 → 259,8 |
} |
packet = packet_create( length, addr_len, max_prefix, max_content, max_suffix ); |
fibril_mutex_unlock( & ps_globals.lock ); |
// remove debug dump |
printf( "packet %d created\n", packet->packet_id ); |
return packet; |
} |
/branches/network/uspace/srv/net/structures/char_map.c |
---|
67,6 → 67,13 |
*/ |
char_map_ref char_map_find_node( const char_map_ref map, const char * identifier, const size_t length ); |
/** Returns the value assigned to the map. |
* @param map The character string to integer map. Input parameter. |
* @returns The integral value assigned to the map. |
* @returns CHAR_MAP_NULL if the map is not assigned a value. |
*/ |
int char_map_get_value( const char_map_ref map ); |
/** Checks if the map is valid. |
* @param map The character string to integer map. Input parameter. |
* @returns TRUE if the map is valid. |
/branches/network/uspace/srv/net/structures/int_map.h |
---|
68,7 → 68,7 |
}; \ |
\ |
struct name{ \ |
size_t size; \ |
int size; \ |
int next; \ |
name##_item_ref items; \ |
int magic; \ |
/branches/network/uspace/srv/net/include/crc.h |
---|
File deleted |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/branches/network/uspace/srv/net/include/protocol_map.h |
---|
105,6 → 105,22 |
} |
} |
/** Maps the Ethernet protocol identifier to the link service access point identifier. |
* @param ethertype Ethernet protocol identifier. Input parameter. |
* @returns Link service access point identifier. |
* @returns 0 if mapping is not found. |
*/ |
static inline eth_lsap_t lsap_unmap( eth_type_t ethertype ){ |
switch( ethertype ){ |
case ETH_P_IP: |
return ETH_LSAP_IP; |
case ETH_P_ARP: |
return ETH_LSAP_ARP; |
default: |
return 0; |
} |
} |
/** Maps the network interface layer services to the hardware types. |
* @param nil The network interface service. Input parameter. |
* @returns The hardware type of the network interface service. |
/branches/network/uspace/srv/net/include/checksum.h |
---|
0,0 → 1,108 |
/* |
* 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 |
* General CRC and checksum computation. |
*/ |
#ifndef __NET_CHECKSUM_H__ |
#define __NET_CHECKSUM_H__ |
#include <byteorder.h> |
#include <sys/types.h> |
/** Computes CRC32 value. |
* @param seed Initial value. Often used as 0 or ~0. Input parameter. |
* @param data Pointer to the beginning of data to process. Input parameter. |
* @param length Length of the data in bits. Input parameter. |
* @returns The computed CRC32 of the length bits of the data. |
*/ |
#ifdef ARCH_IS_BIG_ENDIAN |
#define compute_crc32( seed, data, length ) compute_crc32_be( seed, ( uint8_t * ) data, length ) |
#else |
#define compute_crc32( seed, data, length ) compute_crc32_le( seed, ( uint8_t * ) data, length ) |
#endif |
/** Computes CRC32 value in the little-endian environment. |
* @param seed Initial value. Often used as 0 or ~0. Input parameter. |
* @param data Pointer to the beginning of data to process. Input parameter. |
* @param length Length of the data in bits. Input parameter. |
* @returns The computed CRC32 of the length bits of the data. |
*/ |
uint32_t compute_crc32_le( uint32_t seed, uint8_t * data, size_t length ); |
/** Computes CRC32 value in the big-endian environment. |
* @param seed Initial value. Often used as 0 or ~0. Input parameter. |
* @param data Pointer to the beginning of data to process. Input parameter. |
* @param length Length of the data in bits. Input parameter. |
* @returns The computed CRC32 of the length bits of the data. |
*/ |
uint32_t compute_crc32_be( uint32_t seed, uint8_t * data, size_t length ); |
/** Computes sum of the 2 byte fields. |
* Padds one zero (0) byte if odd. |
* @param seed Initial value. Often used as 0 or ~0. Input parameter. |
* @param data Pointer to the beginning of data to process. Input parameter. |
* @param length Length of the data in bytes. Input parameter. |
* @returns The computed checksum of the length bytes of the data. |
*/ |
uint32_t compute_checksum( uint32_t seed, uint8_t * data, size_t length ); |
/** Compacts the computed checksum to the 16 bit number adding the carries. |
* @param sum Computed checksum. Input parameter. |
* @returns Compacted computed checksum to the 16 bits. |
*/ |
uint16_t compact_checksum( uint32_t sum ); |
/** Returns or flips the checksum if zero. |
* @param checksum The computed checksum. Input parameter. |
* @returns The internet protocol header checksum. |
* @returns 0xFFFF if the computed checksum is zero. |
*/ |
uint16_t flip_checksum( uint16_t checksum ); |
/** Computes the ip header checksum. |
* To compute the checksum of a new packet, the checksum header field must be zero. |
* To check the checksum of a received packet, the checksum may be left set. |
* The zero (0) value will be returned in this case if valid. |
* @param data The header data. Input parameter. |
* @param length The header length in bytes. Input parameter. |
* @returns The internet protocol header checksum. |
* @returns 0xFFFF if the computed checksum is zero. |
*/ |
uint16_t ip_checksum( uint8_t * data, size_t length ); |
#endif |
/** @} |
*/ |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
/branches/network/uspace/srv/net/include/nil_interface.h |
---|
68,10 → 68,10 |
* @returns EOK on success. |
* @returns EBADMEM if the address parameter is NULL. |
* @returns ENOENT if there no such device. |
* @returns Other error codes as defined for the generic_get_addr() function. |
* @returns Other error codes as defined for the generic_get_addr_req() function. |
*/ |
#define nil_get_addr( nil_phone, device_id, address, data ) \ |
generic_get_addr( nil_phone, NET_NIL_ADDR, device_id, address, data ) |
#define nil_get_addr_req( nil_phone, device_id, address, data ) \ |
generic_get_addr_req( nil_phone, NET_NIL_ADDR, device_id, address, data ) |
/** Returns the device broadcast hardware address. |
* @param nil_phone The network interface layer phone. Input parameter. |
81,10 → 81,10 |
* @returns EOK on success. |
* @returns EBADMEM if the address parameter is NULL. |
* @returns ENOENT if there no such device. |
* @returns Other error codes as defined for the generic_get_addr() function. |
* @returns Other error codes as defined for the generic_get_addr_req() function. |
*/ |
#define nil_get_broadcast_addr( nil_phone, device_id, address, data ) \ |
generic_get_addr( nil_phone, NET_NIL_BROADCAST_ADDR, device_id, address, data ) |
#define nil_get_broadcast_addr_req( nil_phone, device_id, address, data ) \ |
generic_get_addr_req( nil_phone, NET_NIL_BROADCAST_ADDR, device_id, address, data ) |
/** Sends the packet queue. |
* @param nil_phone The network interface layer phone. Input parameter. |
145,6 → 145,17 |
*/ |
int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ); |
/** Creates bidirectional connection with the network interface layer module and registers the message receiver. |
* @param service The network interface layer module service. Input parameter. |
* @param device_id The device identifier. Input parameter. |
* @param me The requesting module service. Input parameter. |
* @param receiver The message receiver. Input parameter. |
* @returns The phone of the needed service. |
* @returns EOK on success. |
* @returns Other error codes as defined for the bind_service() function. |
*/ |
#define nil_bind_service( service, device_id, me, receiver ) \ |
bind_service( service, device_id, me, 0, receiver ); |
/*@}*/ |
#endif |
/branches/network/uspace/srv/net/include/netif_interface.h |
---|
62,9 → 62,9 |
* @returns EOK on success. |
* @returns EBADMEM if the address parameter is NULL. |
* @returns ENOENT if there no such device. |
* @returns Other error codes as defined for the netif_get_addr() function. |
* @returns Other error codes as defined for the netif_get_addr_message() function. |
*/ |
int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ); |
int netif_get_addr_req( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ); |
/** Probes the existence of the device. |
* @param netif_phone The network interface phone. Input parameter. |
112,7 → 112,7 |
*/ |
int netif_stats_req( int netif_phone, device_id_t device_id, device_stats_ref stats ); |
/** Creates bidirectional connection with the network interface module service and registers the message receiver. |
/** Creates bidirectional connection with the network interface module and registers the message receiver. |
* @param service The network interface module service. Input parameter. |
* @param device_id The device identifier. Input parameter. |
* @param me The requesting module service. Input parameter. |
/branches/network/uspace/srv/net/net/net_remote.c |
---|
47,7 → 47,7 |
#include "../structures/measured_strings.h" |
//#include "net_messages.h" |
#include "net_messages.h" |
int net_get_device_conf_req( int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data ){ |
return generic_translate_req( net_phone, NET_NET_GET_DEVICE_CONF, device_id, 0, * configuration, count, configuration, data ); |
/branches/network/uspace/srv/net/net/net.c |
---|
63,6 → 63,7 |
#include "../include/ip_interface.h" |
#include "net.h" |
#include "net_messages.h" |
/** Networking module name. |
*/ |
250,10 → 251,6 |
switch( IPC_GET_METHOD( * call )){ |
case IPC_M_PHONE_HUNGUP: |
return EOK; |
case NET_NET_DEVICE: |
// TODO configure, register |
printf( "Networking: new netif %d\n", IPC_GET_DEVICE( call )); |
return EOK; |
case NET_NET_GET_DEVICE_CONF: |
ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call ))); |
net_get_device_conf_req( 0, IPC_GET_DEVICE( call ), & strings, IPC_GET_COUNT( call ), NULL ); |
347,6 → 344,7 |
// read general configuration |
ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "IPV", "4" )); |
ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "IP_ROUTING", "no" )); |
ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "MTU", "1500" )); |
ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "ICMP_ERROR_REPORTING", "yes" )); //anything else not starting with 'y' |
ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "ICMP_ECHO_REPLYING", "yes" )); //anything else not starting with 'y' |
364,8 → 362,7 |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_NETMASK", "255.0.0.0" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "15535" )); |
}else if( str_lcmp( name, "ne2k", 4 ) == 0 ){ |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
379,11 → 376,9 |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.240" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_NETMASK", "255.255.255.240" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_BROADCAST", "10.0.2.255" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_GATEWAY", "10.0.2.2" )); |
ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
} |
return read_netif_configuration_build( name, netif ); |
/branches/network/uspace/srv/net/net/Makefile |
---|
52,7 → 52,7 |
ifeq ($(NETWORKING), module) |
SOURCES += $(NAME)_bundle.c \ |
$(NET_BASE)crc.c \ |
$(NET_BASE)checksum.c \ |
$(NET_BASE)inet.c \ |
$(NET_BASE)il/arp/arp.c \ |
$(NET_BASE)il/ip/ip.c \ |
/branches/network/uspace/srv/net/net/start/netstart.c |
---|
44,10 → 44,11 |
#include <ipc/services.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "../../modules.h" |
#include "../../self_test.h" |
#include "../net_messages.h" |
/** Networking startup module name. |
*/ |
#define NAME "Networking startup" |
88,8 → 89,9 |
if( ERROR_OCCURRED( ipc_call_sync_0_0( net_phone, NET_NET_STARTUP ))){ |
printf( "ERROR %d\n", ERROR_CODE ); |
return ERROR_CODE; |
}else{ |
printf( "OK\n" ); |
} |
printf( "OK\n" ); |
return EOK; |
} |
/branches/network/uspace/srv/net/net/start/Makefile |
---|
39,7 → 39,7 |
OUTPUT = $(NAME) |
SOURCES = \ |
$(NAME).c \ |
$(NET_BASE)crc.c \ |
$(NET_BASE)checksum.c \ |
$(NET_BASE)modules.c \ |
$(NET_BASE)self_test.c \ |
$(STRUCTURES)char_map.c \ |
/branches/network/uspace/srv/net/socket/socket_messages.h |
---|
87,6 → 87,7 |
#define SOCKET_GET_OPT_NAME( call ) ( int ) IPC_GET_ARG4( call ) |
#define SOCKET_GET_DATA_FRAGMENTS( call ) ( int ) IPC_GET_ARG5( call ) |
#define SOCKET_GET_NEW_SOCKET_ID( call ) ( int ) IPC_GET_ARG5( call ) |
/*@}*/ |
/branches/network/uspace/srv/net/socket/socket_client.c |
---|
310,7 → 310,6 |
callid = async_get_call( & call ); |
switch( IPC_GET_METHOD( call )){ |
// TODO remember the data_fragment_size |
case NET_SOCKET_RECEIVED: |
fibril_rwlock_read_lock( & socket_globals.lock ); |
// find the socket |
340,8 → 339,8 |
if( ! new_socket ){ |
ERROR_CODE = ENOMEM; |
}else{ |
bzero( socket, sizeof( * socket )); |
socket_initialize( new_socket, SOCKET_GET_SOCKET_ID( call ), socket->phone, socket->service ); |
bzero( new_socket, sizeof( * new_socket )); |
socket_initialize( new_socket, SOCKET_GET_NEW_SOCKET_ID( call ), socket->phone, socket->service ); |
ERROR_CODE = sockets_add( socket_get_sockets(), new_socket->socket_id, new_socket ); |
if( ERROR_CODE < 0 ){ |
free( new_socket ); |
350,7 → 349,6 |
fibril_mutex_lock( & socket->accept_lock ); |
if( ERROR_OCCURRED( dyn_fifo_push( & socket->accepted, new_socket->socket_id, SOCKET_MAX_ACCEPTED_SIZE ))){ |
sockets_exclude( socket_get_sockets(), new_socket->socket_id ); |
free( new_socket ); |
}else{ |
// signal the accepted socket |
fibril_condvar_signal( & socket->accept_signal ); |
362,7 → 360,6 |
} |
fibril_rwlock_read_unlock( & socket_globals.lock ); |
break; |
// TODO obsolete? |
case NET_SOCKET_DATA_FRAGMENT_SIZE: |
fibril_rwlock_read_lock( & socket_globals.lock ); |
// find the socket |
506,6 → 503,7 |
socket_ref socket; |
aid_t message_id; |
int result; |
ipc_call_t answer; |
if(( ! cliaddr ) || ( ! addrlen )) return EBADMEM; |
526,14 → 524,19 |
} |
-- socket->blocked; |
// request accept |
message_id = async_send_3( socket->phone, NET_SOCKET_ACCEPT, ( ipcarg_t ) socket->socket_id, ( ipcarg_t ) dyn_fifo_value( & socket->accepted ), socket->service, NULL ); |
message_id = async_send_3( socket->phone, NET_SOCKET_ACCEPT, ( ipcarg_t ) socket->socket_id, 0, socket->service, & answer ); |
// read address |
ipc_data_read_start( socket->phone, cliaddr, * addrlen ); |
fibril_rwlock_read_unlock( & socket_globals.lock ); |
async_wait_for( message_id, ( ipcarg_t * ) & result ); |
if( result > 0 ){ |
// dequeue the accepted apcket if successful |
// dequeue the accepted socket if successful |
dyn_fifo_pop( & socket->accepted ); |
// set address length |
* addrlen = SOCKET_GET_ADDRESS_LENGTH( answer ); |
}else if( result == ENOTSOCK ){ |
// empty the queue if no accepted sockets |
while( dyn_fifo_pop( & socket->accepted ) > 0 ); |
} |
fibril_mutex_unlock( & socket->accept_lock ); |
return result; |
/branches/network/uspace/srv/net/messages.h |
---|
48,14 → 48,13 |
#include "structures/packet/packet.h" |
#define NET_NETIF_COUNT 6 |
#define NET_NET_COUNT 9 |
#define NET_NET_COUNT 3 |
#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_ICMP_COUNT 6 |
#define NET_TL_COUNT 1 |
#define NET_UDP_COUNT 0 |
#define NET_TCP_COUNT 0 |
82,9 → 81,7 |
#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_FIRST ( NET_ARP_LAST + 0 ) |
#define NET_ICMP_LAST ( NET_ICMP_FIRST + NET_ICMP_COUNT ) |
#define NET_TL_FIRST ( NET_ICMP_LAST + 0 ) |
113,7 → 110,6 |
#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 ) |
152,28 → 148,7 |
#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 ){ |
static inline int generic_get_addr_req( int phone, int message, device_id_t device_id, measured_string_ref * address, char ** data ){ |
aid_t message_id; |
ipcarg_t result; |
int string; |
/branches/network/uspace/srv/net/il/arp/arp.c |
---|
328,7 → 328,7 |
} |
device->service = service; |
// bind the new one |
device->phone = bind_service( device->service, ( ipcarg_t ) device->device_id, SERVICE_ARP, 0, arp_globals.client_connection ); |
device->phone = nil_bind_service( device->service, ( ipcarg_t ) device->device_id, SERVICE_ARP, arp_globals.client_connection ); |
if( device->phone < 0 ){ |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
343,7 → 343,7 |
return ERROR_CODE; |
} |
// get hardware address |
if( ERROR_OCCURRED( nil_get_addr( device->phone, device_id, & device->addr, & device->addr_data ))){ |
if( ERROR_OCCURRED( nil_get_addr_req( device->phone, device_id, & device->addr, & device->addr_data ))){ |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
arp_protos_destroy( & device->protos ); |
free( device ); |
350,7 → 350,7 |
return ERROR_CODE; |
} |
// get broadcast address |
if( ERROR_OCCURRED( nil_get_broadcast_addr( device->phone, device_id, & device->broadcast_addr, & device->broadcast_data ))){ |
if( ERROR_OCCURRED( nil_get_broadcast_addr_req( device->phone, device_id, & device->broadcast_addr, & device->broadcast_data ))){ |
fibril_rwlock_write_unlock( & arp_globals.lock ); |
free( device->addr ); |
free( device->addr_data ); |
/branches/network/uspace/srv/net/il/ip/ip_client.c |
---|
117,7 → 117,7 |
struct sockaddr_in * address_in; |
if( !( header && headerlen )) return EBADMEM; |
if( !( src && dest && ( srclen >= sizeof( struct sockaddr )) && ( srclen == destlen ) && ( src->sa_family == dest->sa_family ))) return EINVAL; |
if( !( src && dest && ( srclen > 0 ) && (( size_t ) srclen >= sizeof( struct sockaddr )) && ( srclen == destlen ) && ( src->sa_family == dest->sa_family ))) return EINVAL; |
switch( src->sa_family ){ |
case AF_INET: |
if( srclen != sizeof( struct sockaddr_in )) return EINVAL; |
/branches/network/uspace/srv/net/il/ip/ip.c |
---|
53,7 → 53,7 |
#include "../../include/arp_interface.h" |
#include "../../include/byteorder.h" |
#include "../../include/crc.h" |
#include "../../include/checksum.h" |
#include "../../include/device.h" |
#include "../../include/icmp_client.h" |
#include "../../include/icmp_codes.h" |
271,11 → 271,7 |
} |
} |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast.s_addr, data, INET_ADDRSTRLEN ); |
printf( "\tbroadcast\t= %s\n", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN ); |
printf( "\tdns1\t= %s\n", data ); |
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN ); |
printf( "\tdns2\t= %s\n", data ); |
printf( "\t\tbroadcast\t= %s\n", data ); |
free( data ); |
} |
fibril_rwlock_write_unlock( & ip_globals.netifs_lock ); |
285,7 → 281,7 |
int ip_netif_initialize( ip_netif_ref ip_netif ){ |
ERROR_DECLARE; |
measured_string_t names[] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }, { "IP_ROUTING", 10 }}; |
measured_string_t names[] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "IP_NETMASK", 10 }, { "IP_GATEWAY", 10 }, { "IP_BROADCAST", 12 }, { "ARP", 3 }, { "IP_ROUTING", 10 }}; |
measured_string_ref configuration; |
size_t count = sizeof( names ) / sizeof( measured_string_t ); |
char * data; |
330,9 → 326,7 |
if( ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 2 ].value, ( uint8_t * ) & route->address.s_addr )) |
|| ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 3 ].value, ( uint8_t * ) & route->netmask.s_addr )) |
|| ( inet_pton( AF_INET, configuration[ 4 ].value, ( uint8_t * ) & gateway.s_addr ) == EINVAL ) |
|| ( inet_pton( AF_INET, configuration[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast.s_addr ) == EINVAL ) |
|| ( inet_pton( AF_INET, configuration[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL ) |
|| ( inet_pton( AF_INET, configuration[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){ |
|| ( inet_pton( AF_INET, configuration[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast.s_addr ) == EINVAL )){ |
net_free_settings( configuration, data ); |
return EINVAL; |
} |
341,21 → 335,21 |
net_free_settings( configuration, data ); |
return ENOTSUP; |
} |
if( configuration[ 8 ].value ){ |
ip_netif->arp = get_running_module( & ip_globals.modules, configuration[ 8 ].value ); |
if( configuration[ 6 ].value ){ |
ip_netif->arp = get_running_module( & ip_globals.modules, configuration[ 6 ].value ); |
if( ! ip_netif->arp ){ |
printf( "Failed to start the arp %s\n", configuration[ 8 ].value ); |
printf( "Failed to start the arp %s\n", configuration[ 6 ].value ); |
net_free_settings( configuration, data ); |
return EINVAL; |
} |
} |
if( configuration[ 9 ].value ){ |
ip_netif->routing = ( configuration[ 9 ].value[ 0 ] == 'y' ); |
if( configuration[ 7 ].value ){ |
ip_netif->routing = ( configuration[ 7 ].value[ 0 ] == 'y' ); |
} |
net_free_settings( configuration, data ); |
} |
// binds the netif service which also initializes the device |
ip_netif->phone = bind_service( ip_netif->service, ( ipcarg_t ) ip_netif->device_id, SERVICE_IP, 0, ip_globals.client_connection ); |
ip_netif->phone = nil_bind_service( ip_netif->service, ( ipcarg_t ) ip_netif->device_id, SERVICE_IP, ip_globals.client_connection ); |
if( ip_netif->phone < 0 ){ |
printf( "Failed to contact the nil service %d\n", ip_netif->service ); |
return ip_netif->phone; |
469,7 → 463,7 |
if( addrlen < 0 ){ |
return ip_release_and_return( packet, addrlen ); |
} |
if( addrlen < sizeof( struct sockaddr )){ |
if(( size_t ) addrlen < sizeof( struct sockaddr )){ |
return ip_release_and_return( packet, EINVAL ); |
} |
switch( addr->sa_family ){ |
1290,7 → 1284,7 |
if( !( destination && ( addrlen > 0 ))) return EINVAL; |
if( !( device_id && header && headerlen )) return EBADMEM; |
if( addrlen < sizeof( struct sockaddr )){ |
if(( size_t ) addrlen < sizeof( struct sockaddr )){ |
return EINVAL; |
} |
switch( destination->sa_family ){ |
/branches/network/uspace/srv/net/il/ip/Makefile |
---|
39,7 → 39,7 |
$(NAME).c \ |
$(NAME)_client.c \ |
$(NAME)_module.c \ |
$(NET_BASE)crc.c \ |
$(NET_BASE)checksum.c \ |
$(NET_BASE)inet.c \ |
$(NET_BASE)module.c \ |
$(NET_BASE)modules.c \ |
/branches/network/uspace/srv/net/il/ip/ip.h |
---|
133,12 → 133,6 |
/** Broadcast address. |
*/ |
in_addr_t broadcast; |
/** First DNS address. |
*/ |
in_addr_t dns1; |
/** Second DNS address. |
*/ |
in_addr_t dns2; |
/** Routing table. |
*/ |
ip_routes_t routes; |
/branches/network/uspace/srv/net/netif/netif_remote.c |
---|
48,8 → 48,8 |
#include "netif_messages.h" |
int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){ |
return generic_get_addr( netif_phone, NET_NETIF_GET_ADDR, device_id, address, data ); |
int netif_get_addr_req( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){ |
return generic_get_addr_req( netif_phone, NET_NETIF_GET_ADDR, device_id, address, data ); |
} |
int netif_probe_req( int netif_phone, device_id_t device_id, int irq, int io ){ |
/branches/network/uspace/srv/net/netif/netif.c |
---|
155,7 → 155,7 |
return res; |
} |
int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){ |
int netif_get_addr_req( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){ |
ERROR_DECLARE; |
measured_string_t translation; |
/branches/network/uspace/srv/net/netif/dp8390/dp8390_port.h |
---|
115,7 → 115,6 |
} ether_addr_t; |
/* type.h */ |
//TODO platform dependent types |
typedef unsigned long phys_bytes; /* physical addr/length in bytes */ |
typedef unsigned int vir_bytes; /* virtual addresses and lengths in bytes */ |
/branches/network/uspace/srv/net/netif/dp8390/dp8390.c |
---|
322,14 → 322,20 |
int queue_packet( dpeth_t * dep, packet_t packet ){ |
packet_t tmp; |
if( dep->packet_count > 1 ){ |
if( ! pq_add( pq_previous( dep->packet_queue ), packet, 0, 0 )){ |
if( dep->packet_count >= MAX_PACKETS ){ |
netif_pq_release( packet_get_id( packet )); |
return ELIMIT; |
} |
tmp = dep->packet_queue; |
while( pq_next( tmp )){ |
tmp = pq_next( tmp ); |
} |
if( ! pq_add( tmp, packet, 0, 0 )){ |
return EINVAL; |
} |
}else{ |
tmp = pq_add( dep->packet_queue, packet, 0, 0 ); |
if( ! tmp ) return EINVAL; |
dep->packet_queue = tmp; |
if( ! dep->packet_count ){ |
dep->packet_queue = packet; |
} |
++ dep->packet_count; |
return EBUSY; |
1015,12 → 1021,18 |
dep->de_flags |= DEF_PACK_RECV; |
// dep->de_flags &= ~DEF_READING; |
if( dep->received_count >= MAX_PACKETS ){ |
netif_pq_release( packet_get_id( packet )); |
return ELIMIT; |
}else{ |
queue = pq_add( dep->received_queue, packet, 0, 0 ); |
if( queue ){ |
dep->received_queue = queue; |
++ dep->received_count; |
}else{ |
netif_pq_release( packet_get_id( packet )); |
} |
} |
return OK; |
} |
/branches/network/uspace/srv/net/netif/dp8390/Makefile |
---|
51,7 → 51,7 |
ifeq ($(NETWORKING), module) |
SOURCES += $(NET_BASE)crc.c \ |
SOURCES += $(NET_BASE)checksum.c \ |
$(NET_BASE)nil/eth/eth.c \ |
$(NET_BASE)net/net_remote.c \ |
$(NET_BASE)netif/netif_nil_bundle.c |
/branches/network/uspace/srv/net/netif/dp8390/dp8390.h |
---|
268,6 → 268,10 |
#define SENDQ_NR 1 /* Maximum size of the send queue */ |
#define SENDQ_PAGES 6 /* 6 * DP_PAGESIZE >= 1514 bytes */ |
/** Maximum number of waiting packets to be sent or received. |
*/ |
#define MAX_PACKETS 4 |
typedef struct dpeth |
{ |
/* Packet send queue. |
278,6 → 282,7 |
/* Packet receive queue. |
*/ |
packet_t received_queue; |
int received_count; |
/* The de_base_port field is the starting point of the probe. |
* The conf routine also fills de_linmem and de_irq. If the probe |
/branches/network/uspace/srv/net/netif/dp8390/dp8390_module.c |
---|
158,18 → 158,19 |
} |
assert( dep->de_flags & DEF_ENABLED); |
dep->de_int_pending = 0; |
// TODO remove debug print: |
printf( "I%d: 0x%x\n", device_id, IPC_GET_ISR( call )); |
// remove debug print: |
// printf( "I%d: 0x%x\n", device_id, IPC_GET_ISR( call )); |
dp_check_ints( dep, IPC_GET_ISR( call )); |
if( dep->received_queue ){ |
received = dep->received_queue; |
phone = device->nil_phone; |
dep->received_queue = NULL; |
dep->received_count = 0; |
fibril_rwlock_write_unlock( & netif_globals.lock ); |
// TODO remove debug dump: |
uint8_t * data; |
data = packet_get_data( received ); |
printf( "Receiving 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\n", packet_get_id( received ), packet_get_data_length( received ), 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 ] ); |
// remove debug dump: |
// uint8_t * data; |
// data = packet_get_data( received ); |
// printf( "Receiving 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\n", packet_get_id( received ), packet_get_data_length( received ), 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 ] ); |
nil_received_msg( phone, device_id, received, NULL ); |
}else{ |
fibril_rwlock_write_unlock( & netif_globals.lock ); |
229,10 → 230,10 |
// process packet queue |
do{ |
next = pq_detach( packet ); |
// TODO remove debug dump: |
uint8_t * data; |
data = packet_get_data( packet ); |
printf( "Sending 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\n", 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 ] ); |
// remove debug dump: |
// uint8_t * data; |
// data = packet_get_data( packet ); |
// printf( "Sending 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\n", 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 ] ); |
if( do_pwrite( dep, packet, FALSE ) != EBUSY ){ |
netif_pq_release( packet_get_id( packet )); |
/branches/network/uspace/srv/net/self_test.c |
---|
42,7 → 42,7 |
#include <malloc.h> |
#include <stdio.h> |
#include "include/crc.h" |
#include "include/checksum.h" |
#include "structures/int_map.h" |
#include "structures/char_map.h" |
#include "structures/generic_char_map.h" |
/branches/network/uspace/srv/net/err.h |
---|
61,11 → 61,11 |
*/ |
#ifdef CONFIG_DEBUG |
#define ERROR_OCCURRED( value ) (( ERROR_CODE = ( value )) != EOK ) |
#define ERROR_OCCURRED( value ) ((( ERROR_CODE = ( value )) != EOK ) && ({ printf( "error at %s:%d %d\n", __FILE__, __LINE__, ERROR_CODE ); 1; })) |
#else |
#define ERROR_OCCURRED( value ) ((( ERROR_CODE = ( value )) != EOK ) && ({ printf( "error at %s:%d %d\n", __FILE__, __LINE__, ERROR_CODE ); 1; })) |
#define ERROR_OCCURRED( value ) (( ERROR_CODE = ( value )) != EOK ) |
#endif |