Rev 4243 | Rev 4271 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4261 | ||
---|---|---|---|
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 | #include <async.h> |
36 | #include <async.h> |
37 | #include <ctype.h> |
37 | #include <ctype.h> |
38 | #include <ddi.h> |
38 | #include <ddi.h> |
39 | #include <errno.h> |
39 | #include <errno.h> |
40 | #include <malloc.h> |
40 | #include <malloc.h> |
41 | #include <stdio.h> |
41 | #include <stdio.h> |
42 | 42 | ||
43 | #include <ipc/ipc.h> |
43 | #include <ipc/ipc.h> |
44 | #include <ipc/services.h> |
44 | #include <ipc/services.h> |
45 | 45 | ||
46 | #include "../err.h" |
46 | #include "../err.h" |
47 | #include "../messages.h" |
47 | #include "../messages.h" |
48 | #include "../modules.h" |
48 | #include "../modules.h" |
49 | //#include "../self_test.h" |
49 | //#include "../self_test.h" |
50 | 50 | ||
51 | #include "../structures/char_map.h" |
51 | #include "../structures/char_map.h" |
52 | #include "../structures/generic_char_map.h" |
52 | #include "../structures/generic_char_map.h" |
53 | #include "../structures/measured_strings.h" |
53 | #include "../structures/measured_strings.h" |
54 | #include "../structures/module_map.h" |
54 | #include "../structures/module_map.h" |
55 | #include "../structures/packet/packet.h" |
55 | #include "../structures/packet/packet.h" |
56 | #include "../structures/packet/packet_server.h" |
56 | #include "../structures/packet/packet_server.h" |
57 | 57 | ||
58 | #include "../il/ip/ip_messages.h" |
58 | #include "../il/ip/ip_messages.h" |
59 | #include "../include/device.h" |
59 | #include "../include/device.h" |
60 | #include "../include/netif_messages.h" |
60 | #include "../include/netif_messages.h" |
- | 61 | #include "../include/nil_messages.h" |
|
61 | 62 | /* |
|
62 | #if IP_BUNDLE |
63 | #if IP_BUNDLE |
63 | 64 | ||
64 | #include "../ip/ip_module.h" |
65 | #include "../ip/ip_module.h" |
65 | 66 | ||
66 | #endif |
67 | #endif |
67 | 68 | ||
68 | #if TCP_BUNDLE |
69 | #if TCP_BUNDLE |
69 | 70 | ||
70 | #include "../tcp/tcp_module.h" |
71 | #include "../tcp/tcp_module.h" |
71 | 72 | ||
72 | #endif |
73 | #endif |
73 | 74 | */ |
|
74 | #define NAME "Networking" |
75 | #define NAME "Networking" |
75 | 76 | ||
76 | #define LO_NAME "lo" |
77 | #define LO_NAME "lo" |
77 | #define LO_FILENAME "/srv/lo" |
78 | #define LO_FILENAME "/srv/lo" |
78 | #define DP8390_NAME "dp8390" |
79 | #define DP8390_NAME "dp8390" |
79 | #define DP8390_FILENAME "/srv/dp8390" |
80 | #define DP8390_FILENAME "/srv/dp8390" |
80 | #define ETHERNET_NAME "ethernet" |
81 | #define ETHERNET_NAME "ethernet" |
81 | #define ETHERNET_FILENAME "/srv/eth" |
82 | #define ETHERNET_FILENAME "/srv/eth" |
82 | #define IP_NAME "ip" |
83 | #define IP_NAME "ip" |
83 | #define IP_FILENAME "/srv/ip" |
84 | #define IP_FILENAME "/srv/ip" |
84 | 85 | ||
85 | #define CONF_NAME "NAME" |
86 | #define CONF_NAME "NAME" |
86 | #define CONF_NETIF "NETIF" |
87 | #define CONF_NETIF "NETIF" |
87 | #define CONF_NIL "NIL" |
88 | #define CONF_NIL "NIL" |
88 | #define CONF_IL "IL" |
89 | #define CONF_IL "IL" |
89 | #define CONF_IRQ "IRQ" |
90 | #define CONF_IRQ "IRQ" |
90 | #define CONF_IO "IO" |
91 | #define CONF_IO "IO" |
91 | #define CONF_MTU "MTU" |
92 | #define CONF_MTU "MTU" |
92 | 93 | ||
93 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
94 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
94 | #define IPC_GET_COUNT( call ) ( int ) IPC_GET_ARG2( * call ) |
95 | #define IPC_GET_COUNT( call ) ( int ) IPC_GET_ARG2( * call ) |
95 | 96 | ||
96 | typedef struct netif netif_t; |
97 | typedef struct netif netif_t; |
97 | typedef netif_t * netif_ref; |
98 | typedef netif_t * netif_ref; |
98 | 99 | ||
99 | typedef struct networking_globals networking_globals_t; |
100 | typedef struct networking_globals networking_globals_t; |
100 | 101 | ||
101 | DEVICE_MAP_DECLARE( netifs, netif_t ) |
102 | DEVICE_MAP_DECLARE( netifs, netif_t ) |
102 | 103 | ||
103 | GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t ) |
104 | GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t ) |
104 | 105 | ||
105 | /** A present network interface device. |
106 | /** A present network interface device. |
106 | */ |
107 | */ |
107 | struct netif{ |
108 | struct netif{ |
108 | /** A system-unique network interface identifier. |
109 | /** A system-unique network interface identifier. |
109 | */ |
110 | */ |
110 | device_id_t id; |
111 | device_id_t id; |
111 | /** A serving network interface driver module index. |
112 | /** A serving network interface driver module index. |
112 | */ |
113 | */ |
113 | module_ref driver; |
114 | module_ref driver; |
114 | /** A serving link layer module index. |
115 | /** A serving link layer module index. |
115 | */ |
116 | */ |
116 | module_ref nil; |
117 | module_ref nil; |
117 | /** A serving internet layer module index. |
118 | /** A serving internet layer module index. |
118 | */ |
119 | */ |
119 | module_ref il; |
120 | module_ref il; |
120 | /** A system-unique network interface name. |
121 | /** A system-unique network interface name. |
121 | */ |
122 | */ |
122 | char * name; |
123 | char * name; |
123 | /** Configuration. |
124 | /** Configuration. |
124 | */ |
125 | */ |
125 | measured_strings_t configuration; |
126 | measured_strings_t configuration; |
126 | }; |
127 | }; |
127 | 128 | ||
128 | /** A networking module global variables. |
129 | /** A networking module global variables. |
129 | */ |
130 | */ |
130 | struct networking_globals{ |
131 | struct networking_globals{ |
131 | /** Present network interfaces. |
132 | /** Present network interfaces. |
132 | */ |
133 | */ |
133 | netifs_t netifs; |
134 | netifs_t netifs; |
134 | /** Network interface structure indices by names. |
135 | /** Network interface structure indices by names. |
135 | */ |
136 | */ |
136 | char_map_t netif_names; |
137 | char_map_t netif_names; |
137 | /** Available modules. |
138 | /** Available modules. |
138 | */ |
139 | */ |
139 | modules_t modules; |
140 | modules_t modules; |
140 | /** Global configuration. |
141 | /** Global configuration. |
141 | */ |
142 | */ |
142 | measured_strings_t configuration; |
143 | measured_strings_t configuration; |
143 | }; |
144 | }; |
144 | 145 | ||
145 | void networking_print_name( void ); |
146 | void networking_print_name( void ); |
146 | measured_string_ref configuration_find( measured_strings_ref configuration, const char * name ); |
147 | measured_string_ref configuration_find( measured_strings_ref configuration, const char * name ); |
147 | int networking_start_module( async_client_conn_t client_connection ); |
148 | int networking_start_module( async_client_conn_t client_connection ); |
148 | int networking_initialize( void ); |
149 | int networking_initialize( void ); |
149 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
150 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
150 | int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
151 | int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
151 | //int parse_line( measured_strings_ref configuration, char * line ); |
152 | //int parse_line( measured_strings_ref configuration, char * line ); |
152 | int add_configuration( measured_strings_ref configuration, const char * name, const char * value ); |
153 | int add_configuration( measured_strings_ref configuration, const char * name, const char * value ); |
153 | int read_configuration( void ); |
154 | int read_configuration( void ); |
154 | int read_netif_configuration( char * name, netif_ref netif ); |
155 | int read_netif_configuration( char * name, netif_ref netif ); |
155 | int start_device( netif_ref netif ); |
156 | int start_device( netif_ref netif ); |
156 | int startup( void ); |
157 | int startup( void ); |
157 | device_id_t generate_new_device_id( void ); |
158 | device_id_t generate_new_device_id( void ); |
158 | 159 | ||
159 | static networking_globals_t networking_globals; |
160 | static networking_globals_t networking_globals; |
160 | 161 | ||
161 | DEVICE_MAP_IMPLEMENT( netifs, netif_t ) |
162 | DEVICE_MAP_IMPLEMENT( netifs, netif_t ) |
162 | 163 | ||
163 | GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t ) |
164 | GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t ) |
164 | 165 | ||
165 | void networking_print_name( void ){ |
166 | void networking_print_name( void ){ |
166 | printf( "%s", NAME ); |
167 | printf( "%s", NAME ); |
167 | } |
168 | } |
168 | 169 | ||
169 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
170 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
170 | #ifdef NETWORKING_module |
171 | /*#ifdef NETWORKING_module |
171 | //TODO map to *_message |
172 | //TODO map to *_message |
172 | if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){ |
173 | if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){ |
173 | return ip_message( callid, call, answer, answer_count ); |
174 | return ip_message( callid, call, answer, answer_count ); |
174 | /* }else if( IS_NET_ARP_MESSAGE( call )){ |
175 | *//* }else if( IS_NET_ARP_MESSAGE( call )){ |
175 | return arp_message( callid, call, answer, answer_count ); |
176 | return arp_message( callid, call, answer, answer_count ); |
176 | *//* }else if( IS_NET_RARP_MESSAGE( call )){ |
177 | *//* }else if( IS_NET_RARP_MESSAGE( call )){ |
177 | return rarp_message( callid, call, answer, answer_count ); |
178 | return rarp_message( callid, call, answer, answer_count ); |
178 | *//* }else if( IS_NET_ICMP_MESSAGE( call )){ |
179 | *//* }else if( IS_NET_ICMP_MESSAGE( call )){ |
179 | return icmp_message( callid, call, answer, answer_count ); |
180 | return icmp_message( callid, call, answer, answer_count ); |
180 | *//* }else if( IS_NET_UDP_MESSAGE( call )){ |
181 | *//* }else if( IS_NET_UDP_MESSAGE( call )){ |
181 | return udp_message( callid, call, answer, answer_count ); |
182 | return udp_message( callid, call, answer, answer_count ); |
182 | */ }else if( IS_NET_TCP_MESSAGE( call )){ |
183 | *//* }else if( IS_NET_TCP_MESSAGE( call )){ |
183 | return tcp_message( callid, call, answer, answer_count ); |
184 | return tcp_message( callid, call, answer, answer_count ); |
184 | /* }else if( IS_NET_SOCKET_MESSAGE( call )){ |
185 | *//* }else if( IS_NET_SOCKET_MESSAGE( call )){ |
185 | return socket_message( callid, call, answer, answer_count ); |
186 | return socket_message( callid, call, answer, answer_count ); |
186 | *//* }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){ |
187 | *//* }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){ |
187 | return ethernet_message( callid, call, answer, answer_count ); |
188 | return ethernet_message( callid, call, answer, answer_count ); |
188 | */ }else{ |
189 | *//* }else{ |
189 | #endif |
190 | #endif |
190 | if( IS_NET_PACKET_MESSAGE( call )){ |
191 | */ if( IS_NET_PACKET_MESSAGE( call )){ |
191 | return packet_server_message( callid, call, answer, answer_count ); |
192 | return packet_server_message( callid, call, answer, answer_count ); |
192 | }else{ |
193 | }else{ |
193 | return net_message( callid, call, answer, answer_count ); |
194 | return net_message( callid, call, answer, answer_count ); |
194 | } |
195 | } |
195 | #ifdef NETWORKING_module |
196 | /*#ifdef NETWORKING_module |
196 | } |
197 | } |
197 | #endif |
198 | #endif |
- | 199 | */ |
|
198 | } |
200 | } |
199 | 201 | ||
200 | int networking_start_module( async_client_conn_t client_connection ){ |
202 | int networking_start_module( async_client_conn_t client_connection ){ |
201 | ERROR_DECLARE; |
203 | ERROR_DECLARE; |
202 | 204 | ||
203 | ipcarg_t phonehash; |
205 | ipcarg_t phonehash; |
204 | 206 | ||
205 | async_set_client_connection( client_connection ); |
207 | async_set_client_connection( client_connection ); |
206 | ERROR_PROPAGATE( pm_init()); |
208 | ERROR_PROPAGATE( pm_init()); |
207 | if( ERROR_OCCURRED( networking_initialize()) |
209 | if( ERROR_OCCURRED( networking_initialize()) |
208 | || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){ |
210 | || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){ |
209 | pm_destroy(); |
211 | pm_destroy(); |
210 | return ERROR_CODE; |
212 | return ERROR_CODE; |
211 | } |
213 | } |
212 | 214 | ||
213 | async_manager(); |
215 | async_manager(); |
214 | 216 | ||
215 | pm_destroy(); |
217 | pm_destroy(); |
216 | return EOK; |
218 | return EOK; |
217 | } |
219 | } |
218 | 220 | ||
219 | int networking_initialize( void ){ |
221 | int networking_initialize( void ){ |
220 | ERROR_DECLARE; |
222 | ERROR_DECLARE; |
221 | 223 | ||
222 | task_id_t task_id; |
224 | task_id_t task_id; |
223 | 225 | ||
224 | netifs_initialize( & networking_globals.netifs ); |
226 | netifs_initialize( & networking_globals.netifs ); |
225 | char_map_initialize( & networking_globals.netif_names ); |
227 | char_map_initialize( & networking_globals.netif_names ); |
226 | modules_initialize( & networking_globals.modules ); |
228 | modules_initialize( & networking_globals.modules ); |
227 | measured_strings_initialize( & networking_globals.configuration ); |
229 | measured_strings_initialize( & networking_globals.configuration ); |
228 | 230 | ||
229 | // run self tests |
231 | // run self tests |
230 | // ERROR_PROPAGATE( self_test()); |
232 | // ERROR_PROPAGATE( self_test()); |
231 | 233 | ||
232 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0 )); |
234 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0 )); |
233 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0 )); |
235 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0 )); |
234 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0 )); |
236 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0 )); |
235 | 237 | ||
236 | #ifdef NETWORKING_modular |
238 | //#ifdef NETWORKING_modular |
237 | task_id = spawn( "/srv/ip" ); |
239 | task_id = spawn( "/srv/ip" ); |
238 | if( ! task_id ) return EINVAL; |
240 | if( ! task_id ) return EINVAL; |
239 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id )); |
241 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id )); |
240 | // if( ! spawn( "/srv/udp" )) return EINVAL; |
242 | // if( ! spawn( "/srv/udp" )) return EINVAL; |
241 | // if( ! spawn( "/srv/tcp" )) return EINVAL; |
243 | // if( ! spawn( "/srv/tcp" )) return EINVAL; |
242 | // if( ! spawn( "/srv/socket" )) return EINVAL; |
244 | // if( ! spawn( "/srv/socket" )) return EINVAL; |
243 | // not always necesssary |
245 | // not always necesssary |
244 | // if( ! spawn( "/srv/arp" )) return EINVAL; |
246 | // if( ! spawn( "/srv/arp" )) return EINVAL; |
245 | // if( ! spawn( "/srv/rarp" )) return EINVAL; |
247 | // if( ! spawn( "/srv/rarp" )) return EINVAL; |
246 | // if( ! spawn( "/srv/icmp" )) return EINVAL; |
248 | // if( ! spawn( "/srv/icmp" )) return EINVAL; |
247 | 249 | /* |
|
248 | #else |
250 | #else |
249 | #ifdef NETWORKING_module |
251 | #ifdef NETWORKING_module |
250 | ipcarg_t phonehash; |
252 | ipcarg_t phonehash; |
251 | 253 | ||
252 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
254 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash )); |
253 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id())); |
255 | ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id())); |
254 | ERROR_PROPAGATE( ip_initialize()); |
256 | ERROR_PROPAGATE( ip_initialize()); |
255 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash )); |
257 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash )); |
256 | // ERROR_PROPAGATE( arp_initialize()); |
258 | // ERROR_PROPAGATE( arp_initialize()); |
257 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash )); |
259 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash )); |
258 | // ERROR_PROPAGATE( rarp_initialize()); |
260 | // ERROR_PROPAGATE( rarp_initialize()); |
259 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash )); |
261 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash )); |
260 | // ERROR_PROPAGATE( icmp_initialize()); |
262 | // ERROR_PROPAGATE( icmp_initialize()); |
261 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash )); |
263 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash )); |
262 | // ERROR_PROPAGATE( udp_initialize()); |
264 | // ERROR_PROPAGATE( udp_initialize()); |
263 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash )); |
265 | ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash )); |
264 | ERROR_PROPAGATE( tcp_initialize()); |
266 | ERROR_PROPAGATE( tcp_initialize()); |
265 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash )); |
267 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash )); |
266 | // ERROR_PROPAGATE( socket_initialize()); |
268 | // ERROR_PROPAGATE( socket_initialize()); |
267 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash )); |
269 | // ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash )); |
268 | // ERROR_PROPAGATE( ethernet_initialize()); |
270 | // ERROR_PROPAGATE( ethernet_initialize()); |
269 | #endif |
271 | #endif |
270 | #endif |
272 | #endif |
271 | 273 | */ |
|
272 | return EOK; |
274 | return EOK; |
273 | } |
275 | } |
274 | 276 | ||
275 | //TODO as ip.c |
277 | //TODO as ip.c |
276 | int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
278 | int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
277 | ERROR_DECLARE; |
279 | ERROR_DECLARE; |
278 | 280 | ||
279 | measured_string_ref strings; |
281 | measured_string_ref strings; |
280 | char * data; |
282 | char * data; |
281 | int index; |
283 | int index; |
282 | measured_string_ref setting; |
284 | measured_string_ref setting; |
283 | measured_strings_ref configuration; |
285 | measured_strings_ref configuration; |
284 | netif_ref netif; |
286 | netif_ref netif; |
285 | 287 | ||
286 | * answer_count = 0; |
288 | * answer_count = 0; |
287 | switch( IPC_GET_METHOD( * call )){ |
289 | switch( IPC_GET_METHOD( * call )){ |
288 | case IPC_M_PHONE_HUNGUP: |
290 | case IPC_M_PHONE_HUNGUP: |
289 | return EOK; |
291 | return EOK; |
290 | case NET_NET_DEVICE: |
292 | case NET_NET_DEVICE: |
291 | // TODO configure, register |
293 | // TODO configure, register |
292 | printf( "\nNetworking: new netif %d", IPC_GET_DEVICE( call )); |
294 | printf( "\nNetworking: new netif %d", IPC_GET_DEVICE( call )); |
293 | return EOK; |
295 | return EOK; |
294 | case NET_NET_GET_DEVICE_CONF: |
296 | case NET_NET_GET_DEVICE_CONF: |
295 | ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call ))); |
297 | ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call ))); |
296 | netif = netifs_find( & networking_globals.netifs, IPC_GET_DEVICE( call )); |
298 | netif = netifs_find( & networking_globals.netifs, IPC_GET_DEVICE( call )); |
297 | if( netif ){ |
299 | if( netif ){ |
298 | configuration = & netif->configuration; |
300 | configuration = & netif->configuration; |
299 | }else{ |
301 | }else{ |
300 | configuration = NULL; |
302 | configuration = NULL; |
301 | } |
303 | } |
302 | for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){ |
304 | for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){ |
303 | setting = measured_strings_find( configuration, strings[ index ].value, 0 ); |
305 | setting = measured_strings_find( configuration, strings[ index ].value, 0 ); |
304 | if( ! setting ){ |
306 | if( ! setting ){ |
305 | setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 ); |
307 | setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 ); |
306 | } |
308 | } |
307 | if( setting ){ |
309 | if( setting ){ |
308 | strings[ index ].length = setting->length; |
310 | strings[ index ].length = setting->length; |
309 | strings[ index ].value = setting->value; |
311 | strings[ index ].value = setting->value; |
310 | }else{ |
312 | }else{ |
311 | strings[ index ].length = 0; |
313 | strings[ index ].length = 0; |
312 | strings[ index ].value = NULL; |
314 | strings[ index ].value = NULL; |
313 | } |
315 | } |
314 | } |
316 | } |
315 | // strings should not contain received data anymore |
317 | // strings should not contain received data anymore |
316 | free( data ); |
318 | free( data ); |
317 | ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call )); |
319 | ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call )); |
318 | free( strings ); |
320 | free( strings ); |
319 | return ERROR_CODE; |
321 | return ERROR_CODE; |
320 | case NET_NET_GET_CONF: |
322 | case NET_NET_GET_CONF: |
321 | // arg1 = count |
323 | // arg1 = count |
322 | ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call ))); |
324 | ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call ))); |
323 | for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){ |
325 | for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){ |
324 | setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 ); |
326 | setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 ); |
325 | if( setting ){ |
327 | if( setting ){ |
326 | strings[ index ].length = setting->length; |
328 | strings[ index ].length = setting->length; |
327 | strings[ index ].value = setting->value; |
329 | strings[ index ].value = setting->value; |
328 | }else{ |
330 | }else{ |
329 | strings[ index ].length = 0; |
331 | strings[ index ].length = 0; |
330 | strings[ index ].value = NULL; |
332 | strings[ index ].value = NULL; |
331 | } |
333 | } |
332 | } |
334 | } |
333 | // strings should not contain received data anymore |
335 | // strings should not contain received data anymore |
334 | free( data ); |
336 | free( data ); |
335 | ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call )); |
337 | ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call )); |
336 | free( strings ); |
338 | free( strings ); |
337 | return ERROR_CODE; |
339 | return ERROR_CODE; |
338 | case NET_NET_STARTUP: |
340 | case NET_NET_STARTUP: |
339 | return startup(); |
341 | return startup(); |
340 | } |
342 | } |
341 | return ENOTSUP; |
343 | return ENOTSUP; |
342 | } |
344 | } |
343 | 345 | ||
344 | /* |
346 | /* |
345 | int parse_line( measured_strings_ref configuration, char * line ){ |
347 | int parse_line( measured_strings_ref configuration, char * line ){ |
346 | ERROR_DECLARE; |
348 | ERROR_DECLARE; |
347 | 349 | ||
348 | measured_string_ref setting; |
350 | measured_string_ref setting; |
349 | char * name; |
351 | char * name; |
350 | char * value; |
352 | char * value; |
351 | 353 | ||
352 | // from the beginning |
354 | // from the beginning |
353 | name = line; |
355 | name = line; |
354 | // skip spaces |
356 | // skip spaces |
355 | while( isspace( * name )) ++ name; |
357 | while( isspace( * name )) ++ name; |
356 | // remember the name start |
358 | // remember the name start |
357 | value = name; |
359 | value = name; |
358 | // skip the name |
360 | // skip the name |
359 | while( isalnum( * value ) || ( * value == '_' )){ |
361 | while( isalnum( * value ) || ( * value == '_' )){ |
360 | // make uppercase |
362 | // make uppercase |
361 | // * value = toupper( * value ); |
363 | // * value = toupper( * value ); |
362 | ++ value; |
364 | ++ value; |
363 | } |
365 | } |
364 | if( * value == '=' ){ |
366 | if( * value == '=' ){ |
365 | // terminate the name |
367 | // terminate the name |
366 | * value = '\0'; |
368 | * value = '\0'; |
367 | }else{ |
369 | }else{ |
368 | // terminate the name |
370 | // terminate the name |
369 | * value = '\0'; |
371 | * value = '\0'; |
370 | // skip until '=' |
372 | // skip until '=' |
371 | ++ value; |
373 | ++ value; |
372 | while(( * value ) && ( * value != '=' )) ++ value; |
374 | while(( * value ) && ( * value != '=' )) ++ value; |
373 | // not found? |
375 | // not found? |
374 | if( * value != '=' ) return EINVAL; |
376 | if( * value != '=' ) return EINVAL; |
375 | } |
377 | } |
376 | ++ value; |
378 | ++ value; |
377 | // skip spaces |
379 | // skip spaces |
378 | while( isspace( * value )) ++ value; |
380 | while( isspace( * value )) ++ value; |
379 | // create a bulk measured string till the end |
381 | // create a bulk measured string till the end |
380 | setting = measured_string_create_bulk( value, -1 ); |
382 | setting = measured_string_create_bulk( value, -1 ); |
381 | if( ! setting ) return ENOMEM; |
383 | if( ! setting ) return ENOMEM; |
382 | // add the configuration setting |
384 | // add the configuration setting |
383 | if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ |
385 | if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ |
384 | free( setting ); |
386 | free( setting ); |
385 | return ERROR_CODE; |
387 | return ERROR_CODE; |
386 | } |
388 | } |
387 | return EOK; |
389 | return EOK; |
388 | } |
390 | } |
389 | */ |
391 | */ |
390 | 392 | ||
391 | int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){ |
393 | int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){ |
392 | ERROR_DECLARE; |
394 | ERROR_DECLARE; |
393 | 395 | ||
394 | measured_string_ref setting; |
396 | measured_string_ref setting; |
395 | 397 | ||
396 | setting = measured_string_create_bulk( value, 0 ); |
398 | setting = measured_string_create_bulk( value, 0 ); |
397 | if( ! setting ) return ENOMEM; |
399 | if( ! setting ) return ENOMEM; |
398 | // add the configuration setting |
400 | // add the configuration setting |
399 | if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ |
401 | if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ |
400 | free( setting ); |
402 | free( setting ); |
401 | return ERROR_CODE; |
403 | return ERROR_CODE; |
402 | } |
404 | } |
403 | return EOK; |
405 | return EOK; |
404 | } |
406 | } |
405 | 407 | ||
406 | device_id_t generate_new_device_id( void ){ |
408 | device_id_t generate_new_device_id( void ){ |
407 | return device_assign_devno(); |
409 | return device_assign_devno(); |
408 | } |
410 | } |
409 | 411 | ||
410 | int read_configuration( void ){ |
412 | int read_configuration( void ){ |
411 | ERROR_DECLARE; |
413 | ERROR_DECLARE; |
412 | 414 | ||
413 | // read general configuration |
415 | // read general configuration |
414 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" )); |
416 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" )); |
415 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "MTU", "1500" )); |
417 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "MTU", "1500" )); |
416 | return EOK; |
418 | return EOK; |
417 | } |
419 | } |
418 | 420 | ||
419 | int read_netif_configuration( char * name, netif_ref netif ){ |
421 | int read_netif_configuration( char * name, netif_ref netif ){ |
420 | ERROR_DECLARE; |
422 | ERROR_DECLARE; |
421 | 423 | ||
422 | if( strncmp( name, "lo", 2 ) == 0 ){ |
424 | if( strncmp( name, "lo", 2 ) == 0 ){ |
423 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
425 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
424 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
426 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
425 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
427 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
426 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
428 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
427 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
429 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
428 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
430 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
429 | }else if( strncmp( name, "ne2k", 4 ) == 0 ){ |
431 | }else if( strncmp( name, "ne2k", 4 ) == 0 ){ |
430 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
432 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
431 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
433 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
- | 434 | #ifdef NETWORKING_module |
|
- | 435 | // ethernet bundled in dp8390 |
|
- | 436 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME )); |
|
- | 437 | #else |
|
- | 438 | // standalone ethernet |
|
432 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )); |
439 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )); |
- | 440 | #endif |
|
433 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
441 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
434 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
442 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
435 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
443 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
436 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); |
444 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); |
437 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
445 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
438 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.5" )); |
446 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.5" )); |
439 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
447 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
440 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
448 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
441 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
449 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
442 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
450 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
443 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
451 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
444 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
452 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
445 | } |
453 | } |
446 | return EOK; |
454 | return EOK; |
447 | } |
455 | } |
448 | 456 | ||
449 | int start_device( netif_ref netif ){ |
457 | int start_device( netif_ref netif ){ |
450 | ERROR_DECLARE; |
458 | ERROR_DECLARE; |
451 | 459 | ||
452 | measured_string_ref setting; |
460 | measured_string_ref setting; |
453 | services_t internet_service; |
461 | services_t internet_service; |
454 | int irq; |
462 | int irq; |
455 | int io; |
463 | int io; |
456 | int mtu; |
464 | int mtu; |
457 | 465 | ||
458 | // mandatory netif |
466 | // mandatory netif |
459 | setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 ); |
467 | setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 ); |
460 | netif->driver = get_running_module( & networking_globals.modules, setting->value ); |
468 | netif->driver = get_running_module( & networking_globals.modules, setting->value ); |
461 | if( ! netif->driver ){ |
469 | if( ! netif->driver ){ |
462 | printf( "\nFailed to start the network interface driver %s", setting->value ); |
470 | printf( "\nFailed to start the network interface driver %s", setting->value ); |
463 | return EINVAL; |
471 | return EINVAL; |
464 | } |
472 | } |
465 | // optional network interface layer |
473 | // optional network interface layer |
466 | setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 ); |
474 | setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 ); |
467 | if( setting ){ |
475 | if( setting ){ |
468 | netif->nil = get_running_module( & networking_globals.modules, setting->value ); |
476 | netif->nil = get_running_module( & networking_globals.modules, setting->value ); |
469 | if( ! netif->nil ){ |
477 | if( ! netif->nil ){ |
470 | printf( "\nFailed to start the network interface layer %s", setting->value ); |
478 | printf( "\nFailed to start the network interface layer %s", setting->value ); |
471 | return EINVAL; |
479 | return EINVAL; |
472 | } |
480 | } |
473 | }else{ |
481 | }else{ |
474 | netif->nil = NULL; |
482 | netif->nil = NULL; |
475 | } |
483 | } |
476 | // mandatory internet layer |
484 | // mandatory internet layer |
477 | setting = measured_strings_find( & netif->configuration, CONF_IL, 0 ); |
485 | setting = measured_strings_find( & netif->configuration, CONF_IL, 0 ); |
478 | netif->il = get_running_module( & networking_globals.modules, setting->value ); |
486 | netif->il = get_running_module( & networking_globals.modules, setting->value ); |
479 | if( ! netif->il ){ |
487 | if( ! netif->il ){ |
480 | printf( "\nFailed to start the internet layer %s", setting->value ); |
488 | printf( "\nFailed to start the internet layer %s", setting->value ); |
481 | return EINVAL; |
489 | return EINVAL; |
482 | } |
490 | } |
483 | // end of the static loopback initialization |
491 | // end of the static loopback initialization |
484 | // startup the loopback interface |
492 | // startup the loopback interface |
485 | setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 ); |
493 | setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 ); |
486 | irq = setting ? strtol( setting->value, NULL, 10 ) : 0; |
494 | irq = setting ? strtol( setting->value, NULL, 10 ) : 0; |
487 | setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); |
495 | setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); |
488 | io = setting ? strtol( setting->value, NULL, 16 ) : 0; |
496 | io = setting ? strtol( setting->value, NULL, 16 ) : 0; |
489 | ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io )); |
497 | ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io )); |
490 | if( netif->nil ){ |
498 | if( netif->nil ){ |
491 | setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); |
499 | setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); |
492 | if( ! setting ){ |
500 | if( ! setting ){ |
493 | setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 ); |
501 | setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 ); |
494 | } |
502 | } |
495 | mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
503 | mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
496 | ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, mtu, netif->driver->service )); |
504 | ERROR_PROPAGATE( nil_device_req( netif->nil->phone, netif->id, mtu, netif->driver->service )); |
497 | internet_service = netif->nil->service; |
505 | internet_service = netif->nil->service; |
498 | }else{ |
506 | }else{ |
499 | internet_service = netif->driver->service; |
507 | internet_service = netif->driver->service; |
500 | } |
508 | } |
501 | // TODO IL_BUNDLE |
509 | // TODO IL_BUNDLE |
502 | ERROR_PROPAGATE( async_req_2_0( netif->il->phone, NET_IL_DEVICE, netif->id, internet_service )); |
510 | ERROR_PROPAGATE( async_req_3_0( netif->il->phone, NET_IL_DEVICE, netif->id, 0, internet_service )); |
503 | ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id )); |
511 | ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id )); |
504 | return EOK; |
512 | return EOK; |
505 | } |
513 | } |
506 | 514 | ||
507 | int startup( void ){ |
515 | int startup( void ){ |
508 | ERROR_DECLARE; |
516 | ERROR_DECLARE; |
509 | 517 | ||
510 | char * conf_files[] = { "lo", "ne2k" }; |
518 | char * conf_files[] = { "lo", "ne2k" }; |
511 | int count = sizeof( conf_files ) / sizeof( char * ); |
519 | int count = sizeof( conf_files ) / sizeof( char * ); |
512 | int index; |
520 | int index; |
513 | netif_ref netif; |
521 | netif_ref netif; |
514 | int i; |
522 | int i; |
515 | measured_string_ref setting; |
523 | measured_string_ref setting; |
516 | 524 | ||
517 | // TODO dynamic configuration |
525 | // TODO dynamic configuration |
518 | ERROR_PROPAGATE( read_configuration()); |
526 | ERROR_PROPAGATE( read_configuration()); |
519 | 527 | ||
520 | for( i = 0; i < count; ++ i ){ |
528 | for( i = 0; i < count; ++ i ){ |
521 | netif = ( netif_ref ) malloc( sizeof( netif_t )); |
529 | netif = ( netif_ref ) malloc( sizeof( netif_t )); |
522 | if( ! netif ) return ENOMEM; |
530 | if( ! netif ) return ENOMEM; |
523 | 531 | ||
524 | netif->id = generate_new_device_id(); |
532 | netif->id = generate_new_device_id(); |
525 | if( ! netif->id ) return EXDEV; |
533 | if( ! netif->id ) return EXDEV; |
526 | ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); |
534 | ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); |
527 | // read configuration files |
535 | // read configuration files |
528 | if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif ))){ |
536 | if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif ))){ |
529 | measured_strings_destroy( & netif->configuration ); |
537 | measured_strings_destroy( & netif->configuration ); |
530 | free( netif ); |
538 | free( netif ); |
531 | return ERROR_CODE; |
539 | return ERROR_CODE; |
532 | } |
540 | } |
533 | // mandatory name |
541 | // mandatory name |
534 | setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 ); |
542 | setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 ); |
535 | if( ! setting ){ |
543 | if( ! setting ){ |
536 | printf( "\nThe name is missing" ); |
544 | printf( "\nThe name is missing" ); |
537 | measured_strings_destroy( & netif->configuration ); |
545 | measured_strings_destroy( & netif->configuration ); |
538 | free( netif ); |
546 | free( netif ); |
539 | return EINVAL; |
547 | return EINVAL; |
540 | } |
548 | } |
541 | netif->name = setting->value; |
549 | netif->name = setting->value; |
542 | // add to the netifs map |
550 | // add to the netifs map |
543 | index = netifs_add( & networking_globals.netifs, netif->id, netif ); |
551 | index = netifs_add( & networking_globals.netifs, netif->id, netif ); |
544 | if( index < 0 ){ |
552 | if( index < 0 ){ |
545 | measured_strings_destroy( & netif->configuration ); |
553 | measured_strings_destroy( & netif->configuration ); |
546 | free( netif ); |
554 | free( netif ); |
547 | return index; |
555 | return index; |
548 | } |
556 | } |
549 | // add to the netif names map |
557 | // add to the netif names map |
550 | if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index )) |
558 | if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index )) |
551 | // start network interfaces and needed modules |
559 | // start network interfaces and needed modules |
552 | || ERROR_OCCURRED( start_device( netif ))){ |
560 | || ERROR_OCCURRED( start_device( netif ))){ |
553 | measured_strings_destroy( & netif->configuration ); |
561 | measured_strings_destroy( & netif->configuration ); |
554 | netifs_exclude_index( & networking_globals.netifs, index ); |
562 | netifs_exclude_index( & networking_globals.netifs, index ); |
555 | return ERROR_CODE; |
563 | return ERROR_CODE; |
556 | } |
564 | } |
557 | // increment modules' usage |
565 | // increment modules' usage |
558 | ++ netif->driver->usage; |
566 | ++ netif->driver->usage; |
559 | if( netif->nil ) ++ netif->nil->usage; |
567 | if( netif->nil ) ++ netif->nil->usage; |
560 | ++ netif->il->usage; |
568 | ++ netif->il->usage; |
561 | printf( "\nNew network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name ); |
569 | printf( "\nNew network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name ); |
562 | } |
570 | } |
563 | return EOK; |
571 | return EOK; |
564 | } |
572 | } |
565 | 573 | ||
566 | /** @} |
574 | /** @} |
567 | */ |
575 | */ |
568 | 576 |