Subversion Repositories HelenOS

Rev

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

Rev 3666 Rev 3685
Line 182... Line 182...
182
    ipc_call_t  call;
182
    ipc_call_t  call;
183
    ipcarg_t    arg1, arg2, arg3;
183
    ipcarg_t    arg1, arg2, arg3;
184
    int     res;
184
    int     res;
185
 
185
 
186
    /* Accept the connection */
186
    /* Accept the connection */
-
 
187
//  printf( "\nNET-%d got %d on %x from %x", fibril_get_id(), IPC_GET_METHOD( * icall ), icall->in_phone_hash, iid );
187
    ipc_answer_0( iid, EOK );
188
    ipc_answer_0( iid, EOK );
188
 
189
 
189
    while( true ){
190
    while( true ){
190
        callid = async_get_call( & call );
191
        callid = async_get_call( & call );
191
        arg1 = 0;
192
        arg1 = 0;
192
        arg2 = 0;
193
        arg2 = 0;
193
        arg3 = 0;
194
        arg3 = 0;
-
 
195
//      printf( "\nNET-%d got %d on %x from %x", fibril_get_id(), IPC_GET_METHOD( call ), call.in_phone_hash, callid );
194
#ifdef NETWORKING_module
196
#ifdef NETWORKING_module
195
        if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
197
        if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
196
            res = ip_call( callid );
198
            res = ip_call( callid );
197
            if( res == EOK ){
199
            if( res == EOK ){
198
                res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
200
                res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
Line 245... Line 247...
245
    }
247
    }
246
}
248
}
247
 
249
 
248
int main( int argc, char * argv[] ){
250
int main( int argc, char * argv[] ){
249
 
251
 
250
    printf("\nTask %d - Networking: HelenOS Networking subsystem\n", task_get_id());
252
    printf("\nTask %d - HelenOS Networking subsystem", task_get_id());
251
 
253
 
252
    return start_service( SERVICE_NETWORKING, NULL, NULL, client_connection, networking_initialize );
254
    return start_service( SERVICE_NETWORKING, NULL, NULL, client_connection, networking_initialize );
253
}
255
}
254
 
256
 
255
int networking_call( ipc_callid_t callid ){
257
int networking_call( ipc_callid_t callid ){
Line 320... Line 322...
320
    int         index;
322
    int         index;
321
    measured_string_ref setting;
323
    measured_string_ref setting;
322
    measured_strings_ref    configuration;
324
    measured_strings_ref    configuration;
323
    netif_ref       netif;
325
    netif_ref       netif;
324
 
326
 
325
//  printf( "\nNetworking message: %d\n", method );
-
 
326
    switch( method ){
327
    switch( method ){
327
//      case IPC_M_CONNECT_ME_TO:
-
 
328
        case IPC_M_PHONE_HUNGUP:
328
        case IPC_M_PHONE_HUNGUP:
329
            return EOK;
329
            return EOK;
330
        case NET_NETWORKING_DEVICE:
330
        case NET_NETWORKING_DEVICE:
331
            // TODO configure, register
331
            // TODO configure, register
332
            // arg1 = netif id
332
            // arg1 = netif id
Line 454... Line 454...
454
    ERROR_DECLARE;
454
    ERROR_DECLARE;
455
 
455
 
456
    netif_ref       netif;
456
    netif_ref       netif;
457
    measured_string_ref setting;
457
    measured_string_ref setting;
458
    services_t      internet_service;
458
    services_t      internet_service;
-
 
459
    int         index;
459
 
460
 
460
    // read general configuration
461
    // read general configuration
461
    ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" ));
462
    ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" ));
462
 
463
 
463
    // read network interfaces configuration
464
    // read network interfaces configuration
464
 
465
 
465
    // static loopback initialization
466
    // static loopback initialization
466
    printf( "\nloopback initialization" );
467
//  printf( "\nloopback initialization" );
467
    netif = ( netif_ref ) malloc( sizeof( netif_t ));
468
    netif = ( netif_ref ) malloc( sizeof( netif_t ));
468
    if( ! netif ) return ENOMEM;
469
    if( ! netif ) return ENOMEM;
469
    netif->id = generate_new_device_id();
470
    netif->id = generate_new_device_id();
470
    ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration ));
471
    ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration ));
471
    if( ERROR_OCCURED( add_configuration( & netif->configuration, "NAME", LO_NAME ))
472
    if( ERROR_OCCURED( add_configuration( & netif->configuration, "NAME", LO_NAME ))
472
        || ERROR_OCCURED( add_configuration( & netif->configuration, "NETIF", LO_NAME ))
473
    || ERROR_OCCURED( add_configuration( & netif->configuration, "NETIF", LO_NAME ))
473
        || ERROR_OCCURED( add_configuration( & netif->configuration, "IL", IP_NAME ))
474
    || ERROR_OCCURED( add_configuration( & netif->configuration, "IL", IP_NAME ))
-
 
475
    || ERROR_OCCURED( add_configuration( & netif->configuration, "MTU", "1500" ))
474
        || ERROR_OCCURED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" ))
476
    || ERROR_OCCURED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" ))
475
        || ERROR_OCCURED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ))
477
    || ERROR_OCCURED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ))
476
        || ERROR_OCCURED( add_configuration( & netif->configuration, "NETMASK", "255.255.255.255" ))
478
    || ERROR_OCCURED( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ))){
477
        ){
-
 
478
        measured_strings_destroy( & netif->configuration );
479
        measured_strings_destroy( & netif->configuration );
479
        free( netif );
480
        free( netif );
480
        return ERROR_CODE;
481
        return ERROR_CODE;
481
    }
482
    }
482
    // mandatory name
483
    // mandatory name
483
    printf( "\n\tname" );
484
//  printf( "\n\tname" );
484
    setting = measured_strings_find( & netif->configuration, "NAME" );
485
    setting = measured_strings_find( & netif->configuration, "NAME" );
485
    if( ! setting ){
486
    if( ! setting ){
486
        measured_strings_destroy( & netif->configuration );
487
        measured_strings_destroy( & netif->configuration );
487
        free( netif );
488
        free( netif );
488
        return EINVAL;
489
        return EINVAL;
489
    }
490
    }
490
    netif->name = setting->value;
491
    netif->name = setting->value;
491
    printf( " %s OK", netif->name );
492
//  printf( " %s OK", netif->name );
492
    // mandatory netif
493
    // mandatory netif
493
    printf( "\n\tnetif" );
494
//  printf( "\n\tnetif" );
494
    setting = measured_strings_find( & netif->configuration, "NETIF" );
495
    setting = measured_strings_find( & netif->configuration, "NETIF" );
495
    if( ! setting ){
496
    if( ! setting ){
496
        printf( " unknown" );
497
//      printf( " unknown" );
497
        measured_strings_destroy( & netif->configuration );
498
        measured_strings_destroy( & netif->configuration );
498
        free( netif );
499
        free( netif );
499
        return EINVAL;
500
        return EINVAL;
500
    }
501
    }
501
//  printf( " find %s in %d?", setting->value, modules_count( & networking_globals.modules ));
502
//  printf( " find %s in %d?", setting->value, modules_count( & networking_globals.modules ));
502
    netif->driver_module = modules_find( & networking_globals.modules, setting->value );
503
    netif->driver_module = modules_find( & networking_globals.modules, setting->value );
503
    if( ! netif->driver_module ){
504
    if( ! netif->driver_module ){
504
        printf( " not found" );
505
//      printf( " not found" );
505
        // TODO register the unknown one
506
        // TODO register the unknown one
506
        measured_strings_destroy( & netif->configuration );
507
        measured_strings_destroy( & netif->configuration );
507
        free( netif );
508
        free( netif );
508
        return EINVAL;
509
        return EINVAL;
509
    }
510
    }
510
    printf( " found" );
511
//  printf( " found" );
511
    if( ! netif->driver_module->task_id ){
512
    if( ! netif->driver_module->task_id ){
512
        netif->driver_module->task_id = spawn( netif->driver_module->filename );
513
        netif->driver_module->task_id = spawn( netif->driver_module->filename );
513
        if( ! netif->driver_module->task_id ){
514
        if( ! netif->driver_module->task_id ){
514
            measured_strings_destroy( & netif->configuration );
515
            measured_strings_destroy( & netif->configuration );
515
            free( netif );
516
            free( netif );
516
            return EINVAL;
517
            return EINVAL;
517
        }
518
        }
518
    }
519
    }
519
    if( ! netif->driver_module->phone ){
-
 
520
        printf( " connect?" );
-
 
521
        netif->driver_module->phone = connect_to_service( netif->driver_module->service );
-
 
522
    }
-
 
523
    printf( " connected" );
-
 
524
    if( ERROR_OCCURED( ipc_call_sync_1_0( netif->driver_module->phone, NET_NETIF_PROBE, netif->id ))){
-
 
525
        measured_strings_destroy( & netif->configuration );
-
 
526
        free( netif );
-
 
527
        return ERROR_CODE;
-
 
528
    }
-
 
529
    ++ netif->driver_module->usage;
-
 
530
    printf( " OK" );
520
//  printf( " OK" );
531
    // optional link layer
521
    // optional link layer
532
    printf( "\n\tlink layer" );
522
//  printf( "\n\tlink layer" );
533
    setting = measured_strings_find( & netif->configuration, "LL" );
523
    setting = measured_strings_find( & netif->configuration, "LL" );
534
    if( setting ){
524
    if( setting ){
535
        netif->link_layer_module = modules_find( & networking_globals.modules, setting->value );
525
        netif->link_layer_module = modules_find( & networking_globals.modules, setting->value );
536
        if( ! netif->link_layer_module ){
526
        if( ! netif->link_layer_module ){
537
            // TODO register the unknown one
527
            // TODO register the unknown one
Line 547... Line 537...
547
                measured_strings_destroy( & netif->configuration );
537
                measured_strings_destroy( & netif->configuration );
548
                free( netif );
538
                free( netif );
549
                return EINVAL;
539
                return EINVAL;
550
            }
540
            }
551
        }
541
        }
552
        if( ! netif->link_layer_module->phone ){
-
 
553
            netif->link_layer_module->phone = connect_to_service( netif->link_layer_module->service );
-
 
554
        }
-
 
555
        if( ERROR_OCCURED( ipc_call_sync_2_0( netif->link_layer_module->phone, NET_LL_DEVICE, netif->id, netif->driver_module->service ))){
-
 
556
            -- netif->driver_module->usage;
-
 
557
            measured_strings_destroy( & netif->configuration );
-
 
558
            free( netif );
-
 
559
            return ERROR_CODE;
-
 
560
        }
-
 
561
        ++ netif->link_layer_module->usage;
-
 
562
        internet_service = netif->link_layer_module->service;
-
 
563
        printf( " OK" );
-
 
564
    }else{
542
    }else{
565
        internet_service = netif->driver_module->service;
543
        netif->link_layer_module = NULL;
566
        printf( " none" );
-
 
567
    }
544
    }
568
    // mandatory internet layer
545
    // mandatory internet layer
569
    printf( "\n\tinternet layer" );
546
//  printf( "\n\tinternet layer" );
570
    setting = measured_strings_find( & netif->configuration, "IL" );
547
    setting = measured_strings_find( & netif->configuration, "IL" );
571
    if( ! setting ){
548
    if( ! setting ){
572
        -- netif->driver_module->usage;
549
        -- netif->driver_module->usage;
573
        -- netif->link_layer_module->usage;
550
        -- netif->link_layer_module->usage;
574
        measured_strings_destroy( & netif->configuration );
551
        measured_strings_destroy( & netif->configuration );
575
        free( netif );
552
        free( netif );
576
        return EINVAL;
553
        return EINVAL;
577
    }
554
    }
578
    printf( " set %s", setting->value );
555
//  printf( " set %s", setting->value );
579
    netif->internet_layer_module = modules_find( & networking_globals.modules, setting->value );
556
    netif->internet_layer_module = modules_find( & networking_globals.modules, setting->value );
580
    if( ! netif->internet_layer_module ){
557
    if( ! netif->internet_layer_module ){
581
        // TODO register the unknown one
558
        // TODO register the unknown one
582
        -- netif->driver_module->usage;
559
        -- netif->driver_module->usage;
583
        -- netif->link_layer_module->usage;
560
        -- netif->link_layer_module->usage;
584
        measured_strings_destroy( & netif->configuration );
561
        measured_strings_destroy( & netif->configuration );
585
        free( netif );
562
        free( netif );
586
        return EINVAL;
563
        return EINVAL;
587
    }
564
    }
588
    printf( " found" );
565
//  printf( " found" );
589
    if( ! netif->internet_layer_module->task_id ){
566
    if( ! netif->internet_layer_module->task_id ){
590
        netif->internet_layer_module->task_id = spawn( netif->internet_layer_module->filename );
567
        netif->internet_layer_module->task_id = spawn( netif->internet_layer_module->filename );
591
        if( ! netif->internet_layer_module->task_id ){
568
        if( ! netif->internet_layer_module->task_id ){
592
            -- netif->driver_module->usage;
569
            -- netif->driver_module->usage;
593
            -- netif->link_layer_module->usage;
570
            -- netif->link_layer_module->usage;
594
            measured_strings_destroy( & netif->configuration );
571
            measured_strings_destroy( & netif->configuration );
595
            free( netif );
572
            free( netif );
596
            return EINVAL;
573
            return EINVAL;
597
        }
574
        }
598
    }
575
    }
599
    if( ! netif->internet_layer_module->phone ){
576
    index = netifs_add( & networking_globals.netifs, netif->id, netif );
600
        printf( " connect" );
577
    if( index < 0 ){
601
        netif->internet_layer_module->phone = connect_to_service( netif->internet_layer_module->service );
-
 
602
    }
-
 
603
    if( ERROR_OCCURED( ipc_call_sync_2_0( netif->internet_layer_module->phone, NET_IL_DEVICE, netif->id, internet_service ))){
-
 
604
        measured_strings_destroy( & netif->configuration );
-
 
605
        free( netif );
578
        free( netif );
606
        return ERROR_CODE;
579
        return ERROR_CODE;
607
    }
580
    }
608
    ++ netif->internet_layer_module->usage;
-
 
609
    printf( " OK" );
-
 
610
    if( ERROR_OCCURED( netifs_add( & networking_globals.netifs, netif->id, netif ))){
581
    if( ERROR_OCCURED( char_map_add( & networking_globals.netif_names, netif->name, index ))){
611
        free( netif );
582
        netifs_exclude_index( & networking_globals.netifs, index );
612
        return ERROR_CODE;
583
        return ERROR_CODE;
613
    }
584
    }
614
    printf( "\nloopback OK" );
585
//  printf( "\nloopback OK" );
615
    // end of static loopback initialization
586
    // end of the static loopback initialization
-
 
587
    // startup the loopback interface
-
 
588
    if( ! netif->driver_module->phone ){
-
 
589
//      printf( " connect?" );
-
 
590
        netif->driver_module->phone = connect_to_service( netif->driver_module->service );
-
 
591
    }
-
 
592
//  printf( " connected" );
-
 
593
    ERROR_PROPAGATE( async_req_1_0( netif->driver_module->phone, NET_NETIF_PROBE, netif->id ));
-
 
594
    ++ netif->driver_module->usage;
-
 
595
    if( netif->link_layer_module ){
-
 
596
        if( ! netif->link_layer_module->phone ){
-
 
597
            netif->link_layer_module->phone = connect_to_service( netif->link_layer_module->service );
-
 
598
        }
-
 
599
        ERROR_PROPAGATE( async_req_2_0( netif->link_layer_module->phone, NET_LL_DEVICE, netif->id, netif->driver_module->service ));
-
 
600
        ++ netif->link_layer_module->usage;
-
 
601
        internet_service = netif->link_layer_module->service;
-
 
602
//      printf( " OK" );
-
 
603
    }else{
-
 
604
        internet_service = netif->driver_module->service;
-
 
605
//      printf( " none" );
-
 
606
    }
-
 
607
    if( ! netif->internet_layer_module->phone ){
-
 
608
//      printf( " connect" );
-
 
609
        netif->internet_layer_module->phone = connect_to_service( netif->internet_layer_module->service );
-
 
610
    }
-
 
611
    ERROR_PROPAGATE( async_req_2_0( netif->internet_layer_module->phone, NET_IL_DEVICE, netif->id, internet_service ));
-
 
612
    ++ netif->internet_layer_module->usage;
-
 
613
    ERROR_PROPAGATE( async_req_1_0( netif->driver_module->phone, NET_NETIF_START, netif->id ));
-
 
614
//  printf( "\n LO OK" );
616
    return EOK;
615
    return EOK;
617
}
616
}
618
 
617
 
619
task_id_t spawn( const char * fname ){
618
task_id_t spawn( const char * fname ){
620
    const char  * argv[ 2 ];
619
    const char  * argv[ 2 ];