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