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