Rev 4327 | Rev 4351 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4327 | Rev 4332 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup net |
29 | /** @addtogroup net |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * |
34 | * |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <stdio.h> |
37 | #include <stdio.h> |
38 | 38 | ||
39 | #include <ipc/ipc.h> |
39 | #include <ipc/ipc.h> |
40 | 40 | ||
41 | #include "../messages.h" |
41 | #include "../messages.h" |
42 | 42 | ||
43 | #include "../include/ip_interface.h" |
43 | #include "../include/ip_interface.h" |
44 | 44 | ||
45 | #include "../structures/measured_strings.h" |
45 | #include "../structures/measured_strings.h" |
46 | #include "../structures/module_map.h" |
46 | #include "../structures/module_map.h" |
47 | #include "../structures/packet/packet_server.h" |
47 | #include "../structures/packet/packet_server.h" |
48 | 48 | ||
49 | #include "../il/arp/arp_module.h" |
49 | #include "../il/arp/arp_module.h" |
50 | #include "../il/ip/ip_module.h" |
50 | #include "../il/ip/ip_module.h" |
51 | 51 | ||
52 | #include "net.h" |
52 | #include "net.h" |
53 | 53 | ||
54 | extern net_globals_t net_globals; |
54 | extern net_globals_t net_globals; |
55 | 55 | ||
56 | int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
56 | int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
57 | if( IS_NET_IL_MESSAGE( call )){ |
57 | if( IS_NET_IL_MESSAGE( call )){ |
58 | switch( IPC_GET_TARGET( call )){ |
58 | switch( IPC_GET_TARGET( call )){ |
59 | case SERVICE_IP: |
59 | case SERVICE_IP: |
60 | return ip_message( callid, call, answer, answer_count ); |
60 | return ip_message( callid, call, answer, answer_count ); |
61 | default: |
61 | default: |
62 | return EINVAL; |
62 | return EINVAL; |
63 | } |
63 | } |
64 | }else if( IS_NET_IP_MESSAGE( call )){ |
64 | }else if( IS_NET_IP_MESSAGE( call )){ |
65 | return ip_message( callid, call, answer, answer_count ); |
65 | return ip_message( callid, call, answer, answer_count ); |
66 | }else if( IS_NET_ARP_MESSAGE( call )){ |
66 | }else if( IS_NET_ARP_MESSAGE( call )){ |
67 | return arp_message( callid, call, answer, answer_count ); |
67 | return arp_message( callid, call, answer, answer_count ); |
68 | /* }else if( IS_NET_RARP_MESSAGE( call )){ |
68 | /* }else if( IS_NET_RARP_MESSAGE( call )){ |
69 | return rarp_message( callid, call, answer, answer_count ); |
69 | return rarp_message( callid, call, answer, answer_count ); |
70 | }else if( IS_NET_ICMP_MESSAGE( call )){ |
70 | }else if( IS_NET_ICMP_MESSAGE( call )){ |
71 | return icmp_message( callid, call, answer, answer_count ); |
71 | return icmp_message( callid, call, answer, answer_count ); |
72 | }else if( IS_NET_UDP_MESSAGE( call )){ |
72 | }else if( IS_NET_UDP_MESSAGE( call )){ |
73 | return udp_message( callid, call, answer, answer_count ); |
73 | return udp_message( callid, call, answer, answer_count ); |
74 | }else if( IS_NET_TCP_MESSAGE( call )){ |
74 | }else if( IS_NET_TCP_MESSAGE( call )){ |
75 | return tcp_message( callid, call, answer, answer_count ); |
75 | return tcp_message( callid, call, answer, answer_count ); |
76 | }else if( IS_NET_SOCKET_MESSAGE( call )){ |
76 | }else if( IS_NET_SOCKET_MESSAGE( call )){ |
77 | return socket_message( callid, call, answer, answer_count ); |
77 | return socket_message( callid, call, answer, answer_count ); |
78 | */ }else{ |
78 | */ }else{ |
79 | if( IS_NET_PACKET_MESSAGE( call )){ |
79 | if( IS_NET_PACKET_MESSAGE( call )){ |
80 | return packet_server_message( callid, call, answer, answer_count ); |
80 | return packet_server_message( callid, call, answer, answer_count ); |
81 | }else{ |
81 | }else{ |
82 | return net_message( callid, call, answer, answer_count ); |
82 | return net_message( callid, call, answer, answer_count ); |
83 | } |
83 | } |
84 | } |
84 | } |
85 | } |
85 | } |
86 | 86 | ||
87 | int net_initialize( void ){ |
87 | int net_initialize( void ){ |
88 | ERROR_DECLARE; |
88 | ERROR_DECLARE; |
89 | 89 | ||
90 | ipcarg_t phonehash; |
90 | ipcarg_t phonehash; |
91 | 91 | ||
92 | netifs_initialize( & net_globals.netifs ); |
92 | netifs_initialize( & net_globals.netifs ); |
93 | char_map_initialize( & net_globals.netif_names ); |
93 | char_map_initialize( & net_globals.netif_names ); |
94 | modules_initialize( & net_globals.modules ); |
94 | modules_initialize( & net_globals.modules ); |
95 | measured_strings_initialize( & net_globals.configuration ); |
95 | measured_strings_initialize( & net_globals.configuration ); |
96 | 96 | ||
97 | // run self tests |
97 | // run self tests |
98 | // ERROR_PROPAGATE( self_test()); |
98 | // ERROR_PROPAGATE( self_test()); |
99 | 99 | ||
100 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service )); |
100 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service )); |
101 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service )); |
101 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service )); |
102 | 102 | ||
103 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
103 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
104 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module )); |
104 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module )); |
105 | ERROR_PROPAGATE( ip_initialize()); |
105 | ERROR_PROPAGATE( ip_initialize()); |
106 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash )); |
106 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash )); |
107 | ERROR_PROPAGATE( arp_initialize()); |
107 | ERROR_PROPAGATE( arp_initialize()); |
108 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash )); |
108 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash )); |
109 | // ERROR_PROPAGATE( rarp_initialize()); |
109 | // ERROR_PROPAGATE( rarp_initialize()); |
110 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash )); |
110 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash )); |
111 | // ERROR_PROPAGATE( icmp_initialize()); |
111 | // ERROR_PROPAGATE( icmp_initialize()); |
112 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash )); |
112 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash )); |
113 | // ERROR_PROPAGATE( udp_initialize()); |
113 | // ERROR_PROPAGATE( udp_initialize()); |
114 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash )); |
114 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash )); |
115 | // ERROR_PROPAGATE( tcp_initialize()); |
115 | // ERROR_PROPAGATE( tcp_initialize()); |
116 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash )); |
116 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash )); |
117 | // ERROR_PROPAGATE( socket_initialize()); |
117 | // ERROR_PROPAGATE( socket_initialize()); |
118 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash )); |
118 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash )); |
119 | // ERROR_PROPAGATE( ethernet_initialize()); |
119 | // ERROR_PROPAGATE( ethernet_initialize()); |
120 | return EOK; |
120 | return EOK; |
121 | } |
121 | } |
122 | 122 | ||
123 | int read_netif_configuration( char * name, netif_ref netif ){ |
123 | int read_netif_configuration( char * name, netif_ref netif ){ |
124 | ERROR_DECLARE; |
124 | ERROR_DECLARE; |
125 | 125 | ||
126 | if( str_lcmp( name, "lo", 2 ) == 0 ){ |
126 | if( str_lcmp( name, "lo", 2 ) == 0 ){ |
127 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
127 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
128 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
128 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
129 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
129 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
130 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
130 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
131 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
131 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
132 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
132 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
133 | }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){ |
133 | }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){ |
134 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
134 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
135 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
135 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
136 | // ethernet bundled in dp8390 |
136 | // ethernet bundled in dp8390 |
137 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME )); |
137 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME )); |
- | 138 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_MODE", "DIX" )); |
|
138 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
139 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
139 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
140 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
140 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
141 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
141 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); |
142 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); |
142 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
143 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
143 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); |
144 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); |
144 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
145 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
145 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
146 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
146 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
147 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
147 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
148 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
148 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
149 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
149 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
150 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
150 | } |
151 | } |
151 | return EOK; |
152 | return EOK; |
152 | } |
153 | } |
153 | 154 | ||
154 | /** @} |
155 | /** @} |
155 | */ |
156 | */ |
156 | 157 |