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