Subversion Repositories HelenOS

Rev

Rev 3914 | Rev 4155 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3914 Rev 3991
1
/*
1
/*
2
 * Copyright (c) 2009 Lukas Mejdrech
2
 * Copyright (c) 2009 Lukas Mejdrech
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup net
29
/** @addtogroup net
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <async.h>
36
#include <async.h>
37
#include <ctype.h>
37
#include <ctype.h>
38
#include <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 <unistd.h>
42
#include <unistd.h>
43
 
43
 
44
#include <ipc/ipc.h>
44
#include <ipc/ipc.h>
45
#include <ipc/services.h>
45
#include <ipc/services.h>
46
 
46
 
47
#include "../err.h"
47
#include "../err.h"
48
#include "../messages.h"
48
#include "../messages.h"
49
#include "../modules.h"
49
#include "../modules.h"
50
//#include "../self_test.h"
50
//#include "../self_test.h"
51
 
51
 
52
#include "../structures/char_map.h"
52
#include "../structures/char_map.h"
53
#include "../structures/generic_char_map.h"
53
#include "../structures/generic_char_map.h"
54
#include "../structures/measured_strings.h"
54
#include "../structures/measured_strings.h"
55
#include "../structures/packet/packet.h"
55
#include "../structures/packet/packet.h"
56
#include "../structures/packet/packet_server.h"
56
#include "../structures/packet/packet_server.h"
57
 
57
 
58
#include "../il/ip/ip_messages.h"
58
#include "../il/ip/ip_messages.h"
59
#include "../netif/device.h"
59
#include "../netif/device.h"
60
 
60
 
61
#if IP_BUNDLE
61
#if IP_BUNDLE
62
 
62
 
63
    #include "../ip/ip_module.h"
63
    #include "../ip/ip_module.h"
64
 
64
 
65
#endif
65
#endif
66
 
66
 
67
#if TCP_BUNDLE
67
#if TCP_BUNDLE
68
 
68
 
69
    #include "../tcp/tcp_module.h"
69
    #include "../tcp/tcp_module.h"
70
 
70
 
71
#endif
71
#endif
72
 
72
 
73
#define NAME    "Networking"
73
#define NAME    "Networking"
74
 
74
 
75
#define LO_NAME             "lo"
75
#define LO_NAME             "lo"
76
#define LO_FILENAME         "/sbin/lo"
76
#define LO_FILENAME         "/sbin/lo"
77
#define DP8390_ISA_NAME         "dp8390_isa"
77
#define DP8390_ISA_NAME         "dp8390_isa"
78
#define DP8390_ISA_FILENAME     "/sbin/dp8380_isa"
78
#define DP8390_ISA_FILENAME     "/sbin/dp8380_isa"
79
#define ETHERNET_NAME           "ethernet"
79
#define ETHERNET_NAME           "ethernet"
80
#define ETHERNET_FILENAME       "/sbin/ethernet"
80
#define ETHERNET_FILENAME       "/sbin/ethernet"
81
#define IP_NAME             "ip"
81
#define IP_NAME             "ip"
82
#define IP_FILENAME         "/sbin/ip"
82
#define IP_FILENAME         "/sbin/ip"
83
 
83
 
84
#define IPC_GET_DEVICE( call )  ( device_id_t ) IPC_GET_ARG1( * call )
84
#define IPC_GET_DEVICE( call )  ( device_id_t ) IPC_GET_ARG1( * call )
85
#define IPC_GET_COUNT( call )   ( int ) IPC_GET_ARG2( * call )
85
#define IPC_GET_COUNT( call )   ( int ) IPC_GET_ARG2( * call )
86
 
86
 
87
typedef struct module_struct    module_t;
87
typedef struct module_struct    module_t;
88
typedef module_t *      module_ref;
88
typedef module_t *      module_ref;
89
 
89
 
90
typedef struct netif        netif_t;
90
typedef struct netif        netif_t;
91
typedef netif_t *       netif_ref;
91
typedef netif_t *       netif_ref;
92
 
92
 
93
typedef struct networking_globals   networking_globals_t;
93
typedef struct networking_globals   networking_globals_t;
94
 
94
 
95
DEVICE_MAP_DECLARE( netifs, netif_t )
95
DEVICE_MAP_DECLARE( netifs, netif_t )
96
 
96
 
97
GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t )
97
GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t )
98
 
98
 
99
GENERIC_CHAR_MAP_DECLARE( modules, module_t )
99
GENERIC_CHAR_MAP_DECLARE( modules, module_t )
100
 
100
 
101
struct module_struct{
101
struct module_struct{
102
    task_id_t   task_id;
102
    task_id_t   task_id;
103
    services_t  service;
103
    services_t  service;
104
    int     phone;
104
    int     phone;
105
    int     usage;
105
    int     usage;
106
    const char *    name;
106
    const char *    name;
107
    const char *    filename;
107
    const char *    filename;
108
};
108
};
109
 
109
 
110
/** A present network interface device.
110
/** A present network interface device.
111
 */
111
 */
112
struct netif{
112
struct netif{
113
    /** A system-unique network interface identifier.
113
    /** A system-unique network interface identifier.
114
     */
114
     */
115
    device_id_t     id;
115
    device_id_t     id;
116
    /** A serving network interface driver module index.
116
    /** A serving network interface driver module index.
117
     */
117
     */
118
    module_ref      driver;
118
    module_ref      driver;
119
    /** A serving link layer module index.
119
    /** A serving link layer module index.
120
     */
120
     */
121
    module_ref      nil;
121
    module_ref      nil;
122
    /** A serving internet layer module index.
122
    /** A serving internet layer module index.
123
     */
123
     */
124
    module_ref      il;
124
    module_ref      il;
125
    /** A system-unique network interface name.
125
    /** A system-unique network interface name.
126
     */
126
     */
127
    char *          name;
127
    char *          name;
128
    /** Configuration.
128
    /** Configuration.
129
     */
129
     */
130
    measured_strings_t  configuration;
130
    measured_strings_t  configuration;
131
};
131
};
132
 
132
 
133
/** A networking module global variables.
133
/** A networking module global variables.
134
 */
134
 */
135
struct networking_globals{
135
struct networking_globals{
136
    /** Present network interfaces.
136
    /** Present network interfaces.
137
     */
137
     */
138
    netifs_t        netifs;
138
    netifs_t        netifs;
139
    /** Network interface structure indices by names.
139
    /** Network interface structure indices by names.
140
     */
140
     */
141
    char_map_t      netif_names;
141
    char_map_t      netif_names;
142
    /** Available modules.
142
    /** Available modules.
143
     */
143
     */
144
    modules_t       modules;
144
    modules_t       modules;
145
    /** Global configuration.
145
    /** Global configuration.
146
     */
146
     */
147
    measured_strings_t  configuration;
147
    measured_strings_t  configuration;
148
};
148
};
149
 
149
 
150
void    networking_print_name( void );
150
void    networking_print_name( void );
151
int     add_module( module_ref * module, modules_ref modules, const char const * name, const char const * filename, services_t service, task_id_t task_id );
151
int     add_module( module_ref * module, modules_ref modules, const char const * name, const char const * filename, services_t service, task_id_t task_id );
152
static void client_connection( ipc_callid_t iid, ipc_call_t * icall );
-
 
153
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name );
152
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name );
154
int networking_start_module( async_client_conn_t client_connection );
153
int networking_start_module( async_client_conn_t client_connection );
155
int     networking_initialize( void );
154
int     networking_initialize( void );
156
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
155
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
157
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
156
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
158
//int       parse_line( measured_strings_ref configuration, char * line );
157
//int       parse_line( measured_strings_ref configuration, char * line );
159
int     add_configuration( measured_strings_ref configuration, const char * name, const char * value );
158
int     add_configuration( measured_strings_ref configuration, const char * name, const char * value );
160
int     read_configuration( void );
159
int     read_configuration( void );
161
task_id_t   spawn( const char * fname );
160
task_id_t   spawn( const char * fname );
162
int     startup( void );
161
int     startup( void );
163
device_id_t generate_new_device_id( void );
162
device_id_t generate_new_device_id( void );
164
 
163
 
165
static networking_globals_t networking_globals;
164
static networking_globals_t networking_globals;
166
 
165
 
167
DEVICE_MAP_IMPLEMENT( netifs, netif_t )
166
DEVICE_MAP_IMPLEMENT( netifs, netif_t )
168
 
167
 
169
GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t )
168
GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t )
170
 
169
 
171
GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t )
170
GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t )
172
 
171
 
173
void networking_print_name( void ){
172
void networking_print_name( void ){
174
    printf( NAME );
173
    printf( NAME );
175
}
174
}
176
 
175
 
177
int add_module( module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id ){
176
int add_module( module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id ){
178
    ERROR_DECLARE;
177
    ERROR_DECLARE;
179
 
178
 
180
    module_ref  tmp_module;
179
    module_ref  tmp_module;
181
 
180
 
182
    tmp_module = ( module_ref ) malloc( sizeof( module_t ));
181
    tmp_module = ( module_ref ) malloc( sizeof( module_t ));
183
    if( ! tmp_module ) return ENOMEM;
182
    if( ! tmp_module ) return ENOMEM;
184
    tmp_module->task_id = task_id;
183
    tmp_module->task_id = task_id;
185
    tmp_module->phone = 0;
184
    tmp_module->phone = 0;
186
    tmp_module->usage = 0;
185
    tmp_module->usage = 0;
187
    tmp_module->name = name;
186
    tmp_module->name = name;
188
    tmp_module->filename = filename;
187
    tmp_module->filename = filename;
189
    tmp_module->service = service;
188
    tmp_module->service = service;
190
    if( ERROR_OCCURRED( modules_add( modules, tmp_module->name, 0, tmp_module ))){
189
    if( ERROR_OCCURRED( modules_add( modules, tmp_module->name, 0, tmp_module ))){
191
        free( tmp_module );
190
        free( tmp_module );
192
        return ERROR_CODE;
191
        return ERROR_CODE;
193
    }
192
    }
194
    if( module ) * module = tmp_module;
193
    if( module ) * module = tmp_module;
195
    return EOK;
194
    return EOK;
196
}
195
}
197
 
196
 
198
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
197
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
199
#ifdef NETWORKING_module
198
#ifdef NETWORKING_module
200
        //TODO map to *_message
199
        //TODO map to *_message
201
        if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
200
        if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
202
            return ip_message( callid, call, answer, answer_count );
201
            return ip_message( callid, call, answer, answer_count );
203
/*      }else if( IS_NET_ARP_MESSAGE( call )){
202
/*      }else if( IS_NET_ARP_MESSAGE( call )){
204
            return arp_message( callid, call, answer, answer_count );
203
            return arp_message( callid, call, answer, answer_count );
205
*//*        }else if( IS_NET_RARP_MESSAGE( call )){
204
*//*        }else if( IS_NET_RARP_MESSAGE( call )){
206
            return rarp_message( callid, call, answer, answer_count );
205
            return rarp_message( callid, call, answer, answer_count );
207
*//*        }else if( IS_NET_ICMP_MESSAGE( call )){
206
*//*        }else if( IS_NET_ICMP_MESSAGE( call )){
208
            return icmp_message( callid, call, answer, answer_count );
207
            return icmp_message( callid, call, answer, answer_count );
209
*//*        }else if( IS_NET_UDP_MESSAGE( call )){
208
*//*        }else if( IS_NET_UDP_MESSAGE( call )){
210
            return udp_message( callid, call, answer, answer_count );
209
            return udp_message( callid, call, answer, answer_count );
211
*/      }else if( IS_NET_TCP_MESSAGE( call )){
210
*/      }else if( IS_NET_TCP_MESSAGE( call )){
212
            return tcp_message( callid, call, answer, answer_count );
211
            return tcp_message( callid, call, answer, answer_count );
213
/*      }else if( IS_NET_SOCKET_MESSAGE( call )){
212
/*      }else if( IS_NET_SOCKET_MESSAGE( call )){
214
            return socket_message( callid, call, answer, answer_count );
213
            return socket_message( callid, call, answer, answer_count );
215
*//*        }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){
214
*//*        }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){
216
            return ethernet_message( callid, call, answer, answer_count );
215
            return ethernet_message( callid, call, answer, answer_count );
217
*/      }else{
216
*/      }else{
218
#endif
217
#endif
219
            if( IS_NET_PACKET_MESSAGE( call )){
218
            if( IS_NET_PACKET_MESSAGE( call )){
220
                return packet_server_message( callid, call, answer, answer_count );
219
                return packet_server_message( callid, call, answer, answer_count );
221
            }else{
220
            }else{
222
                return net_message( callid, call, answer, answer_count );
221
                return net_message( callid, call, answer, answer_count );
223
            }
222
            }
224
#ifdef NETWORKING_module
223
#ifdef NETWORKING_module
225
        }
224
        }
226
#endif
225
#endif
227
}
226
}
228
 
227
 
229
int networking_start_module( async_client_conn_t client_connection ){
228
int networking_start_module( async_client_conn_t client_connection ){
230
    ERROR_DECLARE;
229
    ERROR_DECLARE;
231
 
230
 
232
    ipcarg_t    phonehash;
231
    ipcarg_t    phonehash;
233
 
232
 
234
    async_set_client_connection( client_connection );
233
    async_set_client_connection( client_connection );
235
    ERROR_PROPAGATE( pm_init());
234
    ERROR_PROPAGATE( pm_init());
236
    if( ERROR_OCCURRED( networking_initialize())
235
    if( ERROR_OCCURRED( networking_initialize())
237
    || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){
236
    || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){
238
        pm_destroy();
237
        pm_destroy();
239
        return ERROR_CODE;
238
        return ERROR_CODE;
240
    }
239
    }
241
 
240
 
242
    async_manager();
241
    async_manager();
243
 
242
 
244
    pm_destroy();
243
    pm_destroy();
245
    return EOK;
244
    return EOK;
246
}
245
}
247
 
246
 
248
int networking_initialize( void ){
247
int networking_initialize( void ){
249
    ERROR_DECLARE;
248
    ERROR_DECLARE;
250
 
249
 
251
    task_id_t   task_id;
250
    task_id_t   task_id;
252
 
251
 
253
    netifs_initialize( & networking_globals.netifs );
252
    netifs_initialize( & networking_globals.netifs );
254
    char_map_initialize( & networking_globals.netif_names );
253
    char_map_initialize( & networking_globals.netif_names );
255
    modules_initialize( & networking_globals.modules );
254
    modules_initialize( & networking_globals.modules );
256
    measured_strings_initialize( & networking_globals.configuration );
255
    measured_strings_initialize( & networking_globals.configuration );
257
 
256
 
258
    // run self tests
257
    // run self tests
259
//  ERROR_PROPAGATE( self_test());
258
//  ERROR_PROPAGATE( self_test());
260
 
259
 
261
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0 ));
260
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0 ));
262
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, DP8390_ISA_NAME, DP8390_ISA_FILENAME, SERVICE_DP8390_ISA, 0 ));
261
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, DP8390_ISA_NAME, DP8390_ISA_FILENAME, SERVICE_DP8390_ISA, 0 ));
263
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0 ));
262
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0 ));
264
 
263
 
265
#ifdef NETWORKING_modular
264
#ifdef NETWORKING_modular
266
    task_id = spawn( "/sbin/ip" );
265
    task_id = spawn( "/sbin/ip" );
267
    if( ! task_id ) return EINVAL;
266
    if( ! task_id ) return EINVAL;
268
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id ));
267
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id ));
269
//  if( ! spawn( "/sbin/udp" )) return EINVAL;
268
//  if( ! spawn( "/sbin/udp" )) return EINVAL;
270
    if( ! spawn( "/sbin/tcp" )) return EINVAL;
269
    if( ! spawn( "/sbin/tcp" )) return EINVAL;
271
//  if( ! spawn( "/sbin/socket" )) return EINVAL;
270
//  if( ! spawn( "/sbin/socket" )) return EINVAL;
272
//  not always necesssary
271
//  not always necesssary
273
//  if( ! spawn( "/sbin/arp" )) return EINVAL;
272
//  if( ! spawn( "/sbin/arp" )) return EINVAL;
274
//  if( ! spawn( "/sbin/rarp" )) return EINVAL;
273
//  if( ! spawn( "/sbin/rarp" )) return EINVAL;
275
//  if( ! spawn( "/sbin/icmp" )) return EINVAL;
274
//  if( ! spawn( "/sbin/icmp" )) return EINVAL;
276
 
275
 
277
#else
276
#else
278
#ifdef NETWORKING_module
277
#ifdef NETWORKING_module
279
    ipcarg_t    phonehash;
278
    ipcarg_t    phonehash;
280
 
279
 
281
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
280
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
282
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id()));
281
    ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id()));
283
    ERROR_PROPAGATE( ip_initialize());
282
    ERROR_PROPAGATE( ip_initialize());
284
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
283
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
285
//  ERROR_PROPAGATE( arp_initialize());
284
//  ERROR_PROPAGATE( arp_initialize());
286
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
285
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
287
//  ERROR_PROPAGATE( rarp_initialize());
286
//  ERROR_PROPAGATE( rarp_initialize());
288
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
287
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
289
//  ERROR_PROPAGATE( icmp_initialize());
288
//  ERROR_PROPAGATE( icmp_initialize());
290
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
289
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
291
//  ERROR_PROPAGATE( udp_initialize());
290
//  ERROR_PROPAGATE( udp_initialize());
292
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
291
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
293
    ERROR_PROPAGATE( tcp_initialize());
292
    ERROR_PROPAGATE( tcp_initialize());
294
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash ));
293
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash ));
295
//  ERROR_PROPAGATE( socket_initialize());
294
//  ERROR_PROPAGATE( socket_initialize());
296
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash ));
295
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash ));
297
//  ERROR_PROPAGATE( ethernet_initialize());
296
//  ERROR_PROPAGATE( ethernet_initialize());
298
#endif
297
#endif
299
#endif
298
#endif
300
 
299
 
301
    return EOK;
300
    return EOK;
302
}
301
}
303
 
302
 
304
//TODO as ip.c
303
//TODO as ip.c
305
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
304
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
306
    ERROR_DECLARE;
305
    ERROR_DECLARE;
307
 
306
 
308
    measured_string_ref strings;
307
    measured_string_ref strings;
309
    char *          data;
308
    char *          data;
310
    int         index;
309
    int         index;
311
    measured_string_ref setting;
310
    measured_string_ref setting;
312
    measured_strings_ref    configuration;
311
    measured_strings_ref    configuration;
313
    netif_ref       netif;
312
    netif_ref       netif;
314
 
313
 
315
    * answer_count = 0;
314
    * answer_count = 0;
316
    switch( IPC_GET_METHOD( * call )){
315
    switch( IPC_GET_METHOD( * call )){
317
        case IPC_M_PHONE_HUNGUP:
316
        case IPC_M_PHONE_HUNGUP:
318
            return EOK;
317
            return EOK;
319
        case NET_NET_DEVICE:
318
        case NET_NET_DEVICE:
320
            // TODO configure, register
319
            // TODO configure, register
321
            printf( "\nNetworking: new netif %d", IPC_GET_DEVICE( call ));
320
            printf( "\nNetworking: new netif %d", IPC_GET_DEVICE( call ));
322
            return EOK;
321
            return EOK;
323
        case NET_NET_GET_DEVICE_CONF:
322
        case NET_NET_GET_DEVICE_CONF:
324
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
323
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
325
            netif = netifs_find( & networking_globals.netifs, IPC_GET_DEVICE( call ));
324
            netif = netifs_find( & networking_globals.netifs, IPC_GET_DEVICE( call ));
326
            if( netif ){
325
            if( netif ){
327
                configuration = & netif->configuration;
326
                configuration = & netif->configuration;
328
            }else{
327
            }else{
329
                configuration = NULL;
328
                configuration = NULL;
330
            }
329
            }
331
            for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
330
            for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
332
                setting = measured_strings_find( configuration, strings[ index ].value, 0 );
331
                setting = measured_strings_find( configuration, strings[ index ].value, 0 );
333
                if( ! setting ){
332
                if( ! setting ){
334
                    setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
333
                    setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
335
                }
334
                }
336
                if( setting ){
335
                if( setting ){
337
                    strings[ index ].length = setting->length;
336
                    strings[ index ].length = setting->length;
338
                    strings[ index ].value = setting->value;
337
                    strings[ index ].value = setting->value;
339
                }else{
338
                }else{
340
                    strings[ index ].length = 0;
339
                    strings[ index ].length = 0;
341
                    strings[ index ].value = NULL;
340
                    strings[ index ].value = NULL;
342
                }
341
                }
343
            }
342
            }
344
            // strings should not contain received data anymore
343
            // strings should not contain received data anymore
345
            free( data );
344
            free( data );
346
            ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
345
            ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
347
            free( strings );
346
            free( strings );
348
            return ERROR_CODE;
347
            return ERROR_CODE;
349
        case NET_NET_GET_CONF:
348
        case NET_NET_GET_CONF:
350
            // arg1 = count
349
            // arg1 = count
351
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
350
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
352
            for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
351
            for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
353
                setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
352
                setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
354
                if( setting ){
353
                if( setting ){
355
                    strings[ index ].length = setting->length;
354
                    strings[ index ].length = setting->length;
356
                    strings[ index ].value = setting->value;
355
                    strings[ index ].value = setting->value;
357
                }else{
356
                }else{
358
                    strings[ index ].length = 0;
357
                    strings[ index ].length = 0;
359
                    strings[ index ].value = NULL;
358
                    strings[ index ].value = NULL;
360
                }
359
                }
361
            }
360
            }
362
            // strings should not contain received data anymore
361
            // strings should not contain received data anymore
363
            free( data );
362
            free( data );
364
            ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
363
            ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
365
            free( strings );
364
            free( strings );
366
            return ERROR_CODE;
365
            return ERROR_CODE;
367
        case NET_NET_STARTUP:
366
        case NET_NET_STARTUP:
368
            return startup();
367
            return startup();
369
    }
368
    }
370
    return ENOTSUP;
369
    return ENOTSUP;
371
}
370
}
372
 
371
 
373
/*
372
/*
374
int parse_line( measured_strings_ref configuration, char * line ){
373
int parse_line( measured_strings_ref configuration, char * line ){
375
    ERROR_DECLARE;
374
    ERROR_DECLARE;
376
 
375
 
377
    measured_string_ref setting;
376
    measured_string_ref setting;
378
    char *          name;
377
    char *          name;
379
    char *          value;
378
    char *          value;
380
 
379
 
381
    // from the beginning
380
    // from the beginning
382
    name = line;
381
    name = line;
383
    // skip spaces
382
    // skip spaces
384
    while( isspace( * name )) ++ name;
383
    while( isspace( * name )) ++ name;
385
    // remember the name start
384
    // remember the name start
386
    value = name;
385
    value = name;
387
    // skip the name
386
    // skip the name
388
    while( isalnum( * value ) || ( * value == '_' )){
387
    while( isalnum( * value ) || ( * value == '_' )){
389
        // make uppercase
388
        // make uppercase
390
//      * value = toupper( * value );
389
//      * value = toupper( * value );
391
        ++ value;
390
        ++ value;
392
    }
391
    }
393
    if( * value == '=' ){
392
    if( * value == '=' ){
394
        // terminate the name
393
        // terminate the name
395
        * value = '\0';
394
        * value = '\0';
396
    }else{
395
    }else{
397
        // terminate the name
396
        // terminate the name
398
        * value = '\0';
397
        * value = '\0';
399
        // skip until '='
398
        // skip until '='
400
        ++ value;
399
        ++ value;
401
        while(( * value ) && ( * value != '=' )) ++ value;
400
        while(( * value ) && ( * value != '=' )) ++ value;
402
        // not found?
401
        // not found?
403
        if( * value != '=' ) return EINVAL;
402
        if( * value != '=' ) return EINVAL;
404
    }
403
    }
405
    ++ value;
404
    ++ value;
406
    // skip spaces
405
    // skip spaces
407
    while( isspace( * value )) ++ value;
406
    while( isspace( * value )) ++ value;
408
    // create a bulk measured string till the end
407
    // create a bulk measured string till the end
409
    setting = measured_string_create_bulk( value, -1 );
408
    setting = measured_string_create_bulk( value, -1 );
410
    if( ! setting ) return ENOMEM;
409
    if( ! setting ) return ENOMEM;
411
    // add the configuration setting
410
    // add the configuration setting
412
    if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
411
    if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
413
        free( setting );
412
        free( setting );
414
        return ERROR_CODE;
413
        return ERROR_CODE;
415
    }
414
    }
416
    return EOK;
415
    return EOK;
417
}
416
}
418
*/
417
*/
419
 
418
 
420
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 ){
421
    ERROR_DECLARE;
420
    ERROR_DECLARE;
422
 
421
 
423
    measured_string_ref setting;
422
    measured_string_ref setting;
424
 
423
 
425
    setting = measured_string_create_bulk( value, 0 );
424
    setting = measured_string_create_bulk( value, 0 );
426
    if( ! setting ) return ENOMEM;
425
    if( ! setting ) return ENOMEM;
427
    // add the configuration setting
426
    // add the configuration setting
428
    if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
427
    if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
429
        free( setting );
428
        free( setting );
430
        return ERROR_CODE;
429
        return ERROR_CODE;
431
    }
430
    }
432
    return EOK;
431
    return EOK;
433
}
432
}
434
 
433
 
435
device_id_t generate_new_device_id( void ){
434
device_id_t generate_new_device_id( void ){
436
    return netifs_count( & networking_globals.netifs ) + 1;
435
    return netifs_count( & networking_globals.netifs ) + 1;
437
}
436
}
438
 
437
 
439
int read_configuration( void ){
438
int read_configuration( void ){
440
    ERROR_DECLARE;
439
    ERROR_DECLARE;
441
 
440
 
442
    netif_ref       netif;
441
    netif_ref       netif;
443
    measured_string_ref setting;
442
    measured_string_ref setting;
444
    services_t      internet_service;
443
    services_t      internet_service;
445
    int         index;
444
    int         index;
446
 
445
 
447
    // read general configuration
446
    // read general configuration
448
    ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" ));
447
    ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" ));
449
 
448
 
450
    // read network interfaces configuration
449
    // read network interfaces configuration
451
 
450
 
452
    // static loopback initialization
451
    // static loopback initialization
453
//  printf( "\nloopback initialization" );
452
//  printf( "\nloopback initialization" );
454
    netif = ( netif_ref ) malloc( sizeof( netif_t ));
453
    netif = ( netif_ref ) malloc( sizeof( netif_t ));
455
    if( ! netif ) return ENOMEM;
454
    if( ! netif ) return ENOMEM;
456
    netif->id = generate_new_device_id();
455
    netif->id = generate_new_device_id();
457
    ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration ));
456
    ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration ));
458
    if( ERROR_OCCURRED( add_configuration( & netif->configuration, "NAME", LO_NAME ))
457
    if( ERROR_OCCURRED( add_configuration( & netif->configuration, "NAME", LO_NAME ))
459
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETIF", LO_NAME ))
458
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETIF", LO_NAME ))
460
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "IL", IP_NAME ))
459
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "IL", IP_NAME ))
461
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "MTU", "1500" ))
460
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "MTU", "1500" ))
462
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" ))
461
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" ))
463
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ))
462
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ))
464
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ))){
463
    || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ))){
465
        measured_strings_destroy( & netif->configuration );
464
        measured_strings_destroy( & netif->configuration );
466
        free( netif );
465
        free( netif );
467
        return ERROR_CODE;
466
        return ERROR_CODE;
468
    }
467
    }
469
    // mandatory name
468
    // mandatory name
470
//  printf( "\n\tname" );
469
//  printf( "\n\tname" );
471
    setting = measured_strings_find( & netif->configuration, "NAME", 0 );
470
    setting = measured_strings_find( & netif->configuration, "NAME", 0 );
472
    if( ! setting ){
471
    if( ! setting ){
473
        measured_strings_destroy( & netif->configuration );
472
        measured_strings_destroy( & netif->configuration );
474
        free( netif );
473
        free( netif );
475
        return EINVAL;
474
        return EINVAL;
476
    }
475
    }
477
    netif->name = setting->value;
476
    netif->name = setting->value;
478
//  printf( " %s OK", netif->name );
477
//  printf( " %s OK", netif->name );
479
    // mandatory netif
478
    // mandatory netif
480
//  printf( "\n\tnetif" );
479
//  printf( "\n\tnetif" );
481
    setting = measured_strings_find( & netif->configuration, "NETIF", 0 );
480
    setting = measured_strings_find( & netif->configuration, "NETIF", 0 );
482
    if( ! setting ){
481
    if( ! setting ){
483
//      printf( " unknown" );
482
//      printf( " unknown" );
484
        measured_strings_destroy( & netif->configuration );
483
        measured_strings_destroy( & netif->configuration );
485
        free( netif );
484
        free( netif );
486
        return EINVAL;
485
        return EINVAL;
487
    }
486
    }
488
//  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 ));
489
    netif->driver = modules_find( & networking_globals.modules, setting->value, 0 );
488
    netif->driver = modules_find( & networking_globals.modules, setting->value, 0 );
490
    if( ! netif->driver ){
489
    if( ! netif->driver ){
491
//      printf( " not found" );
490
//      printf( " not found" );
492
        // TODO register the unknown one
491
        // TODO register the unknown one
493
        measured_strings_destroy( & netif->configuration );
492
        measured_strings_destroy( & netif->configuration );
494
        free( netif );
493
        free( netif );
495
        return EINVAL;
494
        return EINVAL;
496
    }
495
    }
497
//  printf( " found" );
496
//  printf( " found" );
498
    if( ! netif->driver->task_id ){
497
    if( ! netif->driver->task_id ){
499
        netif->driver->task_id = spawn( netif->driver->filename );
498
        netif->driver->task_id = spawn( netif->driver->filename );
500
        if( ! netif->driver->task_id ){
499
        if( ! netif->driver->task_id ){
501
            measured_strings_destroy( & netif->configuration );
500
            measured_strings_destroy( & netif->configuration );
502
            free( netif );
501
            free( netif );
503
            return EINVAL;
502
            return EINVAL;
504
        }
503
        }
505
    }
504
    }
506
//  printf( " OK" );
505
//  printf( " OK" );
507
    // optional link layer
506
    // optional link layer
508
//  printf( "\n\tlink layer" );
507
//  printf( "\n\tlink layer" );
509
    setting = measured_strings_find( & netif->configuration, "NIL", 0 );
508
    setting = measured_strings_find( & netif->configuration, "NIL", 0 );
510
    if( setting ){
509
    if( setting ){
511
        netif->nil = modules_find( & networking_globals.modules, setting->value, 0 );
510
        netif->nil = modules_find( & networking_globals.modules, setting->value, 0 );
512
        if( ! netif->nil ){
511
        if( ! netif->nil ){
513
            // TODO register the unknown one
512
            // TODO register the unknown one
514
            -- netif->driver->usage;
513
            -- netif->driver->usage;
515
            measured_strings_destroy( & netif->configuration );
514
            measured_strings_destroy( & netif->configuration );
516
            free( netif );
515
            free( netif );
517
            return EINVAL;
516
            return EINVAL;
518
        }
517
        }
519
        if( ! netif->nil->task_id ){
518
        if( ! netif->nil->task_id ){
520
            netif->nil->task_id = spawn( netif->nil->filename );
519
            netif->nil->task_id = spawn( netif->nil->filename );
521
            if( ! netif->nil->task_id ){
520
            if( ! netif->nil->task_id ){
522
                -- netif->driver->usage;
521
                -- netif->driver->usage;
523
                measured_strings_destroy( & netif->configuration );
522
                measured_strings_destroy( & netif->configuration );
524
                free( netif );
523
                free( netif );
525
                return EINVAL;
524
                return EINVAL;
526
            }
525
            }
527
        }
526
        }
528
    }else{
527
    }else{
529
        netif->nil = NULL;
528
        netif->nil = NULL;
530
    }
529
    }
531
    // mandatory internet layer
530
    // mandatory internet layer
532
//  printf( "\n\tinternet layer" );
531
//  printf( "\n\tinternet layer" );
533
    setting = measured_strings_find( & netif->configuration, "IL", 0 );
532
    setting = measured_strings_find( & netif->configuration, "IL", 0 );
534
    if( ! setting ){
533
    if( ! setting ){
535
        -- netif->driver->usage;
534
        -- netif->driver->usage;
536
        -- netif->nil->usage;
535
        -- netif->nil->usage;
537
        measured_strings_destroy( & netif->configuration );
536
        measured_strings_destroy( & netif->configuration );
538
        free( netif );
537
        free( netif );
539
        return EINVAL;
538
        return EINVAL;
540
    }
539
    }
541
//  printf( " set %s", setting->value );
540
//  printf( " set %s", setting->value );
542
    netif->il = modules_find( & networking_globals.modules, setting->value, 0 );
541
    netif->il = modules_find( & networking_globals.modules, setting->value, 0 );
543
    if( ! netif->il ){
542
    if( ! netif->il ){
544
        // TODO register the unknown one
543
        // TODO register the unknown one
545
        -- netif->driver->usage;
544
        -- netif->driver->usage;
546
        -- netif->nil->usage;
545
        -- netif->nil->usage;
547
        measured_strings_destroy( & netif->configuration );
546
        measured_strings_destroy( & netif->configuration );
548
        free( netif );
547
        free( netif );
549
        return EINVAL;
548
        return EINVAL;
550
    }
549
    }
551
//  printf( " found" );
550
//  printf( " found" );
552
    if( ! netif->il->task_id ){
551
    if( ! netif->il->task_id ){
553
        netif->il->task_id = spawn( netif->il->filename );
552
        netif->il->task_id = spawn( netif->il->filename );
554
        if( ! netif->il->task_id ){
553
        if( ! netif->il->task_id ){
555
            -- netif->driver->usage;
554
            -- netif->driver->usage;
556
            -- netif->nil->usage;
555
            -- netif->nil->usage;
557
            measured_strings_destroy( & netif->configuration );
556
            measured_strings_destroy( & netif->configuration );
558
            free( netif );
557
            free( netif );
559
            return EINVAL;
558
            return EINVAL;
560
        }
559
        }
561
    }
560
    }
562
    index = netifs_add( & networking_globals.netifs, netif->id, netif );
561
    index = netifs_add( & networking_globals.netifs, netif->id, netif );
563
    if( index < 0 ){
562
    if( index < 0 ){
564
        free( netif );
563
        free( netif );
565
        return ERROR_CODE;
564
        return ERROR_CODE;
566
    }
565
    }
567
    if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index ))){
566
    if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index ))){
568
        netifs_exclude_index( & networking_globals.netifs, index );
567
        netifs_exclude_index( & networking_globals.netifs, index );
569
        return ERROR_CODE;
568
        return ERROR_CODE;
570
    }
569
    }
571
//  printf( "\nloopback OK" );
570
//  printf( "\nloopback OK" );
572
    // end of the static loopback initialization
571
    // end of the static loopback initialization
573
    // startup the loopback interface
572
    // startup the loopback interface
574
    if( ! netif->driver->phone ){
573
    if( ! netif->driver->phone ){
575
//      printf( " connect?" );
574
//      printf( " connect?" );
576
        netif->driver->phone = connect_to_service( netif->driver->service );
575
        netif->driver->phone = connect_to_service( netif->driver->service );
577
    }
576
    }
578
//  printf( " connected" );
577
//  printf( " connected" );
579
    // TODO io, irq
578
    // TODO io, irq
580
    ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, 0, 0 ));
579
    ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, 0, 0 ));
581
    ++ netif->driver->usage;
580
    ++ netif->driver->usage;
582
    if( netif->nil ){
581
    if( netif->nil ){
583
        if( ! netif->nil->phone ){
582
        if( ! netif->nil->phone ){
584
            netif->nil->phone = connect_to_service( netif->nil->service );
583
            netif->nil->phone = connect_to_service( netif->nil->service );
585
        }
584
        }
586
        ERROR_PROPAGATE( async_req_2_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service ));
585
        ERROR_PROPAGATE( async_req_2_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service ));
587
        ++ netif->nil->usage;
586
        ++ netif->nil->usage;
588
        internet_service = netif->nil->service;
587
        internet_service = netif->nil->service;
589
//      printf( " OK" );
588
//      printf( " OK" );
590
    }else{
589
    }else{
591
        internet_service = netif->driver->service;
590
        internet_service = netif->driver->service;
592
//      printf( " none" );
591
//      printf( " none" );
593
    }
592
    }
594
    if( ! netif->il->phone ){
593
    if( ! netif->il->phone ){
595
//      printf( " connect" );
594
//      printf( " connect" );
596
        netif->il->phone = connect_to_service( netif->il->service );
595
        netif->il->phone = connect_to_service( netif->il->service );
597
    }
596
    }
598
    // TODO IL_BUNDLE
597
    // TODO IL_BUNDLE
599
    ERROR_PROPAGATE( async_req_2_0( netif->il->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 ));
600
    ++ netif->il->usage;
599
    ++ netif->il->usage;
601
    // TODO startup?
600
    // TODO startup?
602
    ERROR_PROPAGATE( async_req_1_0( netif->driver->phone, NET_NETIF_START, netif->id ));
601
    ERROR_PROPAGATE( async_req_1_0( netif->driver->phone, NET_NETIF_START, netif->id ));
603
//  printf( "\n LO OK" );
602
//  printf( "\n LO OK" );
604
    return EOK;
603
    return EOK;
605
}
604
}
606
 
605
 
607
task_id_t spawn( const char * fname ){
606
task_id_t spawn( const char * fname ){
608
    const char  * argv[ 2 ];
607
    const char  * argv[ 2 ];
609
    task_id_t   res;
608
    task_id_t   res;
610
 
609
 
611
//  printf( "Spawning %s\n", fname );
610
//  printf( "Spawning %s\n", fname );
612
    argv[ 0 ] = fname;
611
    argv[ 0 ] = fname;
613
    argv[ 1 ] = NULL;
612
    argv[ 1 ] = NULL;
614
    res = task_spawn( fname, argv );
613
    res = task_spawn( fname, argv );
615
    if( res != 0 ){
614
    if( res != 0 ){
616
        /* Success */
615
        /* Success */
617
        usleep( 50000 );
616
        usleep( 50000 );
618
    }
617
    }
619
    return res;
618
    return res;
620
}
619
}
621
 
620
 
622
int startup( void ){
621
int startup( void ){
623
    ERROR_DECLARE;
622
    ERROR_DECLARE;
624
 
623
 
625
    // read configuration files
624
    // read configuration files
626
    if( ERROR_OCCURRED( read_configuration())) return ERROR_CODE;
625
    if( ERROR_OCCURRED( read_configuration())) return ERROR_CODE;
627
 
626
 
628
    // start network interfaces and needed modules
627
    // start network interfaces and needed modules
629
//  start_device( "/sbin/lo", "/sbin/dummy_link_layer" );
628
//  start_device( "/sbin/lo", "/sbin/dummy_link_layer" );
630
    return EOK;
629
    return EOK;
631
}
630
}
632
 
631
 
633
/** @}
632
/** @}
634
 */
633
 */
635
 
634