Rev 4719 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4307 | mejdrech | 1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | /** @addtogroup net |
||
30 | * @{ |
||
31 | */ |
||
32 | |||
33 | /** @file |
||
4350 | mejdrech | 34 | * Wrapper for the bundled networking and TCP/IP stact modules. |
35 | * Distributes messages and initializes all module parts. |
||
4307 | mejdrech | 36 | */ |
37 | |||
4695 | mejdrech | 38 | #include <string.h> |
4307 | mejdrech | 39 | |
40 | #include <ipc/ipc.h> |
||
41 | |||
42 | #include "../messages.h" |
||
43 | |||
44 | #include "../include/ip_interface.h" |
||
45 | |||
46 | #include "../structures/measured_strings.h" |
||
47 | #include "../structures/module_map.h" |
||
48 | #include "../structures/packet/packet_server.h" |
||
49 | |||
50 | #include "../il/arp/arp_module.h" |
||
51 | #include "../il/ip/ip_module.h" |
||
4719 | mejdrech | 52 | #include "../tl/icmp/icmp_module.h" |
4505 | mejdrech | 53 | #include "../tl/udp/udp_module.h" |
54 | #include "../tl/tcp/tcp_module.h" |
||
4307 | mejdrech | 55 | |
56 | #include "net.h" |
||
57 | |||
4350 | mejdrech | 58 | /** Networking module global data. |
59 | */ |
||
4307 | mejdrech | 60 | extern net_globals_t net_globals; |
61 | |||
62 | int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
||
4505 | mejdrech | 63 | if(( IPC_GET_METHOD( * call ) == IPC_M_CONNECT_TO_ME ) |
4574 | mejdrech | 64 | || IS_NET_IL_MESSAGE( call ) |
65 | || IS_NET_TL_MESSAGE( call ) |
||
66 | || IS_NET_SOCKET_MESSAGE( call )){ |
||
4307 | mejdrech | 67 | switch( IPC_GET_TARGET( call )){ |
68 | case SERVICE_IP: |
||
69 | return ip_message( callid, call, answer, answer_count ); |
||
4350 | mejdrech | 70 | case SERVICE_ARP: |
71 | return arp_message( callid, call, answer, answer_count ); |
||
4708 | mejdrech | 72 | case SERVICE_ICMP: |
73 | return icmp_message( callid, call, answer, answer_count ); |
||
4505 | mejdrech | 74 | case SERVICE_UDP: |
75 | return udp_message( callid, call, answer, answer_count ); |
||
76 | case SERVICE_TCP: |
||
77 | return tcp_message( callid, call, answer, answer_count ); |
||
78 | default: |
||
79 | return EINVAL; |
||
80 | } |
||
4695 | mejdrech | 81 | }else if( IS_NET_IP_MESSAGE( call )){ |
4307 | mejdrech | 82 | return ip_message( callid, call, answer, answer_count ); |
83 | }else if( IS_NET_ARP_MESSAGE( call )){ |
||
84 | return arp_message( callid, call, answer, answer_count ); |
||
4719 | mejdrech | 85 | }else if( IS_NET_ICMP_MESSAGE( call )){ |
4307 | mejdrech | 86 | return icmp_message( callid, call, answer, answer_count ); |
4707 | mejdrech | 87 | }else if( IS_NET_UDP_MESSAGE( call )){ |
4307 | mejdrech | 88 | return udp_message( callid, call, answer, answer_count ); |
89 | }else if( IS_NET_TCP_MESSAGE( call )){ |
||
90 | return tcp_message( callid, call, answer, answer_count ); |
||
4574 | mejdrech | 91 | }else{ |
4307 | mejdrech | 92 | if( IS_NET_PACKET_MESSAGE( call )){ |
93 | return packet_server_message( callid, call, answer, answer_count ); |
||
94 | }else{ |
||
95 | return net_message( callid, call, answer, answer_count ); |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | |||
4720 | mejdrech | 100 | int net_initialize_build( async_client_conn_t client_connection ){ |
4307 | mejdrech | 101 | ERROR_DECLARE; |
102 | |||
103 | ipcarg_t phonehash; |
||
104 | |||
105 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
||
106 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module )); |
||
4351 | mejdrech | 107 | ERROR_PROPAGATE( ip_initialize( client_connection )); |
4307 | mejdrech | 108 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash )); |
4351 | mejdrech | 109 | ERROR_PROPAGATE( arp_initialize( client_connection )); |
4707 | mejdrech | 110 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash )); |
111 | ERROR_PROPAGATE( icmp_initialize( client_connection )); |
||
4505 | mejdrech | 112 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash )); |
113 | ERROR_PROPAGATE( udp_initialize( client_connection )); |
||
114 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash )); |
||
115 | ERROR_PROPAGATE( tcp_initialize( client_connection )); |
||
4307 | mejdrech | 116 | return EOK; |
117 | } |
||
118 | |||
4720 | mejdrech | 119 | int read_netif_configuration_build( char * name, netif_ref netif ){ |
4307 | mejdrech | 120 | ERROR_DECLARE; |
121 | |||
4327 | mejdrech | 122 | if( str_lcmp( name, "lo", 2 ) == 0 ){ |
4720 | mejdrech | 123 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", LO_NAME )); |
4327 | mejdrech | 124 | }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){ |
4307 | mejdrech | 125 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME )); |
126 | } |
||
127 | return EOK; |
||
128 | } |
||
129 | |||
130 | /** @} |
||
131 | */ |