Subversion Repositories HelenOS

Rev

Rev 3685 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3685 Rev 3846
Line 37... Line 37...
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"
Line 97... Line 102...
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
     */
Line 136... Line 141...
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
 
Line 167... Line 171...
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;
Line 181... Line 185...
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 );
Line 193... Line 200...
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;
Line 325... Line 310...
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{
Line 358... Line 343...
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;
Line 376... Line 361...
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
 
Line 421... Line 406...
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
}
Line 437... Line 422...
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;
Line 480... Line 465...
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 ){