Rev 4163 | Rev 4197 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4163 | Rev 4192 | ||
---|---|---|---|
Line 37... | Line 37... | ||
37 | #include <ctype.h> |
37 | #include <ctype.h> |
38 | #include <ddi.h> |
38 | #include <ddi.h> |
39 | #include <errno.h> |
39 | #include <errno.h> |
40 | #include <malloc.h> |
40 | #include <malloc.h> |
41 | #include <stdio.h> |
41 | #include <stdio.h> |
42 | #include <task.h> |
- | |
43 | #include <unistd.h> |
- | |
44 | 42 | ||
45 | #include <ipc/ipc.h> |
43 | #include <ipc/ipc.h> |
46 | #include <ipc/services.h> |
44 | #include <ipc/services.h> |
47 | 45 | ||
48 | #include "../err.h" |
46 | #include "../err.h" |
Line 51... | Line 49... | ||
51 | //#include "../self_test.h" |
49 | //#include "../self_test.h" |
52 | 50 | ||
53 | #include "../structures/char_map.h" |
51 | #include "../structures/char_map.h" |
54 | #include "../structures/generic_char_map.h" |
52 | #include "../structures/generic_char_map.h" |
55 | #include "../structures/measured_strings.h" |
53 | #include "../structures/measured_strings.h" |
- | 54 | #include "../structures/module_map.h" |
|
56 | #include "../structures/packet/packet.h" |
55 | #include "../structures/packet/packet.h" |
57 | #include "../structures/packet/packet_server.h" |
56 | #include "../structures/packet/packet_server.h" |
58 | 57 | ||
59 | #include "../il/ip/ip_messages.h" |
58 | #include "../il/ip/ip_messages.h" |
60 | #include "../netif/device.h" |
59 | #include "../netif/device.h" |
Line 91... | Line 90... | ||
91 | #define CONF_MTU "MTU" |
90 | #define CONF_MTU "MTU" |
92 | 91 | ||
93 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
92 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
94 | #define IPC_GET_COUNT( call ) ( int ) IPC_GET_ARG2( * call ) |
93 | #define IPC_GET_COUNT( call ) ( int ) IPC_GET_ARG2( * call ) |
95 | 94 | ||
96 | typedef struct module_struct module_t; |
- | |
97 | typedef module_t * module_ref; |
- | |
98 | - | ||
99 | typedef struct netif netif_t; |
95 | typedef struct netif netif_t; |
100 | typedef netif_t * netif_ref; |
96 | typedef netif_t * netif_ref; |
101 | 97 | ||
102 | typedef struct networking_globals networking_globals_t; |
98 | typedef struct networking_globals networking_globals_t; |
103 | 99 | ||
104 | DEVICE_MAP_DECLARE( netifs, netif_t ) |
100 | DEVICE_MAP_DECLARE( netifs, netif_t ) |
105 | 101 | ||
106 | GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t ) |
102 | GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t ) |
107 | 103 | ||
108 | GENERIC_CHAR_MAP_DECLARE( modules, module_t ) |
- | |
109 | - | ||
110 | struct module_struct{ |
- | |
111 | task_id_t task_id; |
- | |
112 | services_t service; |
- | |
113 | int phone; |
- | |
114 | int usage; |
- | |
115 | char * name; |
- | |
116 | char * filename; |
- | |
117 | }; |
- | |
118 | - | ||
119 | /** A present network interface device. |
104 | /** A present network interface device. |
120 | */ |
105 | */ |
121 | struct netif{ |
106 | struct netif{ |
122 | /** A system-unique network interface identifier. |
107 | /** A system-unique network interface identifier. |
123 | */ |
108 | */ |
Line 155... | Line 140... | ||
155 | */ |
140 | */ |
156 | measured_strings_t configuration; |
141 | measured_strings_t configuration; |
157 | }; |
142 | }; |
158 | 143 | ||
159 | void networking_print_name( void ); |
144 | void networking_print_name( void ); |
160 | int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id ); |
- | |
161 | measured_string_ref configuration_find( measured_strings_ref configuration, const char * name ); |
145 | measured_string_ref configuration_find( measured_strings_ref configuration, const char * name ); |
162 | int networking_start_module( async_client_conn_t client_connection ); |
146 | int networking_start_module( async_client_conn_t client_connection ); |
163 | int networking_initialize( void ); |
147 | int networking_initialize( void ); |
164 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
148 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
165 | int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
149 | int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
166 | //int parse_line( measured_strings_ref configuration, char * line ); |
150 | //int parse_line( measured_strings_ref configuration, char * line ); |
167 | int add_configuration( measured_strings_ref configuration, const char * name, const char * value ); |
151 | int add_configuration( measured_strings_ref configuration, const char * name, const char * value ); |
168 | int read_configuration( void ); |
152 | int read_configuration( void ); |
- | 153 | int read_netif_configuration( char * name, netif_ref netif ); |
|
169 | task_id_t spawn( char * fname ); |
154 | int start_device( netif_ref netif ); |
170 | int startup( void ); |
155 | int startup( void ); |
171 | device_id_t generate_new_device_id( void ); |
156 | device_id_t generate_new_device_id( void ); |
172 | 157 | ||
173 | static networking_globals_t networking_globals; |
158 | static networking_globals_t networking_globals; |
174 | 159 | ||
175 | DEVICE_MAP_IMPLEMENT( netifs, netif_t ) |
160 | DEVICE_MAP_IMPLEMENT( netifs, netif_t ) |
176 | 161 | ||
177 | GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t ) |
162 | GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t ) |
178 | 163 | ||
179 | GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t ) |
- | |
180 | - | ||
181 | void networking_print_name( void ){ |
164 | void networking_print_name( void ){ |
182 | printf( NAME ); |
165 | printf( NAME ); |
183 | } |
166 | } |
184 | 167 | ||
185 | int add_module( module_ref * module, modules_ref modules, char * name, char * filename, services_t service, task_id_t task_id ){ |
- | |
186 | ERROR_DECLARE; |
- | |
187 | - | ||
188 | module_ref tmp_module; |
- | |
189 | - | ||
190 | tmp_module = ( module_ref ) malloc( sizeof( module_t )); |
- | |
191 | if( ! tmp_module ) return ENOMEM; |
- | |
192 | tmp_module->task_id = task_id; |
- | |
193 | tmp_module->phone = 0; |
- | |
194 | tmp_module->usage = 0; |
- | |
195 | tmp_module->name = name; |
- | |
196 | tmp_module->filename = filename; |
- | |
197 | tmp_module->service = service; |
- | |
198 | if( ERROR_OCCURRED( modules_add( modules, tmp_module->name, 0, tmp_module ))){ |
- | |
199 | free( tmp_module ); |
- | |
200 | return ERROR_CODE; |
- | |
201 | } |
- | |
202 | if( module ) * module = tmp_module; |
- | |
203 | return EOK; |
- | |
204 | } |
- | |
205 | - | ||
206 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
168 | int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
207 | #ifdef NETWORKING_module |
169 | #ifdef NETWORKING_module |
208 | //TODO map to *_message |
170 | //TODO map to *_message |
209 | if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){ |
171 | if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){ |
210 | return ip_message( callid, call, answer, answer_count ); |
172 | return ip_message( callid, call, answer, answer_count ); |
Line 445... | Line 407... | ||
445 | } |
407 | } |
446 | 408 | ||
447 | int read_configuration( void ){ |
409 | int read_configuration( void ){ |
448 | ERROR_DECLARE; |
410 | ERROR_DECLARE; |
449 | 411 | ||
450 | netif_ref netif; |
- | |
451 | measured_string_ref setting; |
- | |
452 | services_t internet_service; |
- | |
453 | int index; |
- | |
454 | int irq; |
- | |
455 | int io; |
- | |
456 | int mtu; |
- | |
457 | - | ||
458 | // read general configuration |
412 | // read general configuration |
459 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" )); |
413 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" )); |
460 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "MTU", "1500" )); |
414 | ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "MTU", "1500" )); |
- | 415 | return EOK; |
|
- | 416 | } |
|
461 | 417 | ||
462 | // read network interfaces configuration |
418 | int read_netif_configuration( char * name, netif_ref netif ){ |
- | 419 | ERROR_DECLARE; |
|
463 | 420 | ||
464 | netif = ( netif_ref ) malloc( sizeof( netif_t )); |
- | |
465 | if( ! netif ) return ENOMEM; |
421 | if( strncmp( name, "lo", 2 ) == 0 ){ |
466 | netif->id = generate_new_device_id(); |
- | |
467 | ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); |
- | |
468 | if( ERROR_OCCURRED( add_configuration( & netif->configuration, "NAME", "eth0" )) |
422 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
469 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )) |
423 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
470 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )) |
424 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
471 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IL", IP_NAME )) |
425 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
472 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IRQ", "9" )) |
426 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
473 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IO", "300" )) |
427 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
474 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" )) |
428 | }else if( strncmp( name, "ne2k", 4 ) == 0 ){ |
475 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.5" )) |
429 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
476 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )) |
430 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
477 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )) |
431 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )); |
478 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )) |
432 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
479 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )) |
433 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
480 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )) |
434 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
481 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "ARP", "ARP" ))){ |
435 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
482 | measured_strings_destroy( & netif->configuration ); |
- | |
483 | free( netif ); |
- | |
484 | return ERROR_CODE; |
- | |
485 | } |
- | |
486 | /* if( ERROR_OCCURRED( add_configuration( & netif->configuration, "NAME", LO_NAME )) |
436 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.5" )); |
487 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETIF", LO_NAME )) |
437 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" )); |
488 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IL", IP_NAME )) |
438 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
489 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_CONFIG", "STATIC" )) |
439 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
490 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )) |
440 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
491 | || ERROR_OCCURRED( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ))){ |
441 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
492 | measured_strings_destroy( & netif->configuration ); |
442 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
493 | free( netif ); |
- | |
494 | return ERROR_CODE; |
- | |
495 | } |
443 | } |
496 | */ // mandatory name |
- | |
497 | setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 ); |
- | |
498 | if( ! setting ){ |
- | |
499 | printf( "\nThe name is missing" ); |
- | |
500 | measured_strings_destroy( & netif->configuration ); |
- | |
501 | free( netif ); |
- | |
502 | return EINVAL; |
444 | return EOK; |
503 | } |
445 | } |
- | 446 | ||
- | 447 | int start_device( netif_ref netif ){ |
|
- | 448 | ERROR_DECLARE; |
|
- | 449 | ||
- | 450 | measured_string_ref setting; |
|
504 | netif->name = setting->value; |
451 | services_t internet_service; |
- | 452 | int irq; |
|
- | 453 | int io; |
|
- | 454 | int mtu; |
|
- | 455 | ||
505 | // mandatory netif |
456 | // mandatory netif |
506 | setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 ); |
457 | setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 ); |
507 | if( ! setting ){ |
- | |
508 | printf( "\nThe network interface driver is missing" ); |
- | |
509 | measured_strings_destroy( & netif->configuration ); |
- | |
510 | free( netif ); |
- | |
511 | return EINVAL; |
- | |
512 | } |
- | |
513 | netif->driver = modules_find( & networking_globals.modules, setting->value, 0 ); |
458 | netif->driver = get_running_module( & networking_globals.modules, setting->value ); |
514 | if( ! netif->driver ){ |
459 | if( ! netif->driver ){ |
515 | printf( "\nThe network interface driver is unknown" ); |
460 | printf( "\nFailed to start the network interface driver %s", setting->value ); |
516 | // TODO register the unknown one |
- | |
517 | measured_strings_destroy( & netif->configuration ); |
- | |
518 | free( netif ); |
- | |
519 | return EINVAL; |
461 | return EINVAL; |
520 | } |
462 | } |
521 | if( ! netif->driver->task_id ){ |
- | |
522 | netif->driver->task_id = spawn( netif->driver->filename ); |
- | |
523 | if( ! netif->driver->task_id ){ |
- | |
524 | printf( "\nFailed to start the network interface driver" ); |
- | |
525 | measured_strings_destroy( & netif->configuration ); |
- | |
526 | free( netif ); |
- | |
527 | return EINVAL; |
- | |
528 | } |
- | |
529 | } |
- | |
530 | // optional network interface layer |
463 | // optional network interface layer |
531 | setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 ); |
464 | setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 ); |
532 | if( setting ){ |
465 | if( setting ){ |
533 | netif->nil = modules_find( & networking_globals.modules, setting->value, 0 ); |
466 | netif->nil = get_running_module( & networking_globals.modules, setting->value ); |
534 | if( ! netif->nil ){ |
467 | if( ! netif->nil ){ |
535 | printf( "\nThe network interface layer is unknown" ); |
468 | printf( "\nFailed to start the network interface layer %s", setting->value ); |
536 | // TODO register the unknown one |
- | |
537 | -- netif->driver->usage; |
- | |
538 | measured_strings_destroy( & netif->configuration ); |
- | |
539 | free( netif ); |
- | |
540 | return EINVAL; |
469 | return EINVAL; |
541 | } |
470 | } |
542 | if( ! netif->nil->task_id ){ |
- | |
543 | netif->nil->task_id = spawn( netif->nil->filename ); |
- | |
544 | if( ! netif->nil->task_id ){ |
- | |
545 | printf( "\nFailed to start the network interface layer" ); |
- | |
546 | -- netif->driver->usage; |
- | |
547 | measured_strings_destroy( & netif->configuration ); |
- | |
548 | free( netif ); |
- | |
549 | return EINVAL; |
- | |
550 | } |
- | |
551 | } |
- | |
552 | }else{ |
471 | }else{ |
553 | netif->nil = NULL; |
472 | netif->nil = NULL; |
554 | } |
473 | } |
555 | // mandatory internet layer |
474 | // mandatory internet layer |
556 | setting = measured_strings_find( & netif->configuration, CONF_IL, 0 ); |
475 | setting = measured_strings_find( & netif->configuration, CONF_IL, 0 ); |
557 | if( ! setting ){ |
- | |
558 | printf( "\nThe internet layer is missing" ); |
- | |
559 | -- netif->driver->usage; |
- | |
560 | -- netif->nil->usage; |
- | |
561 | measured_strings_destroy( & netif->configuration ); |
- | |
562 | free( netif ); |
- | |
563 | return EINVAL; |
- | |
564 | } |
- | |
565 | netif->il = modules_find( & networking_globals.modules, setting->value, 0 ); |
476 | netif->il = get_running_module( & networking_globals.modules, setting->value ); |
566 | if( ! netif->il ){ |
477 | if( ! netif->il ){ |
567 | printf( "\nThe internet layer is unknown" ); |
- | |
568 | // TODO register the unknown one |
- | |
569 | -- netif->driver->usage; |
- | |
570 | -- netif->nil->usage; |
- | |
571 | measured_strings_destroy( & netif->configuration ); |
- | |
572 | free( netif ); |
- | |
573 | return EINVAL; |
- | |
574 | } |
- | |
575 | if( ! netif->il->task_id ){ |
- | |
576 | netif->il->task_id = spawn( netif->il->filename ); |
- | |
577 | if( ! netif->il->task_id ){ |
- | |
578 | printf( "\nFailed to start the internet layer" ); |
478 | printf( "\nFailed to start the internet layer %s", setting->value ); |
579 | -- netif->driver->usage; |
- | |
580 | -- netif->nil->usage; |
- | |
581 | measured_strings_destroy( & netif->configuration ); |
- | |
582 | free( netif ); |
- | |
583 | return EINVAL; |
479 | return EINVAL; |
584 | } |
480 | } |
585 | } |
- | |
586 | index = netifs_add( & networking_globals.netifs, netif->id, netif ); |
- | |
587 | if( index < 0 ){ |
- | |
588 | free( netif ); |
- | |
589 | return index; |
- | |
590 | } |
- | |
591 | if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index ))){ |
- | |
592 | netifs_exclude_index( & networking_globals.netifs, index ); |
- | |
593 | return ERROR_CODE; |
- | |
594 | } |
- | |
595 | // end of the static loopback initialization |
481 | // end of the static loopback initialization |
596 | // startup the loopback interface |
482 | // startup the loopback interface |
597 | if( ! netif->driver->phone ){ |
- | |
598 | netif->driver->phone = connect_to_service( netif->driver->service ); |
- | |
599 | } |
- | |
600 | setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 ); |
483 | setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 ); |
601 | irq = setting ? strtol( setting->value, NULL, 10 ) : 0; |
484 | irq = setting ? strtol( setting->value, NULL, 10 ) : 0; |
602 | setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); |
485 | setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); |
603 | io = setting ? strtol( setting->value, NULL, 16 ) : 0; |
486 | io = setting ? strtol( setting->value, NULL, 16 ) : 0; |
604 | ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, irq, io )); |
487 | ERROR_PROPAGATE( async_req_3_0( netif->driver->phone, NET_NETIF_PROBE, netif->id, irq, io )); |
605 | ++ netif->driver->usage; |
- | |
606 | if( netif->nil ){ |
488 | if( netif->nil ){ |
607 | if( ! netif->nil->phone ){ |
- | |
608 | netif->nil->phone = connect_to_service( netif->nil->service ); |
- | |
609 | } |
- | |
610 | setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); |
489 | setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); |
611 | if( ! setting ){ |
490 | if( ! setting ){ |
612 | setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 ); |
491 | setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 ); |
613 | } |
492 | } |
614 | mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
493 | mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; |
615 | ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service, mtu )); |
494 | ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, netif->driver->service, mtu )); |
616 | ++ netif->nil->usage; |
- | |
617 | internet_service = netif->nil->service; |
495 | internet_service = netif->nil->service; |
618 | }else{ |
496 | }else{ |
619 | internet_service = netif->driver->service; |
497 | internet_service = netif->driver->service; |
620 | } |
498 | } |
621 | if( ! netif->il->phone ){ |
- | |
622 | netif->il->phone = connect_to_service( netif->il->service ); |
- | |
623 | } |
- | |
624 | // TODO IL_BUNDLE |
499 | // TODO IL_BUNDLE |
625 | ERROR_PROPAGATE( async_req_2_0( netif->il->phone, NET_IL_DEVICE, netif->id, internet_service )); |
500 | ERROR_PROPAGATE( async_req_2_0( netif->il->phone, NET_IL_DEVICE, netif->id, internet_service )); |
626 | ++ netif->il->usage; |
- | |
627 | // TODO startup? |
- | |
628 | ERROR_PROPAGATE( async_req_1_0( netif->driver->phone, NET_NETIF_START, netif->id )); |
501 | ERROR_PROPAGATE( async_req_1_0( netif->driver->phone, NET_NETIF_START, netif->id )); |
629 | printf( "\nNew network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name ); |
- | |
630 | return EOK; |
502 | return EOK; |
631 | } |
503 | } |
632 | 504 | ||
633 | task_id_t spawn( char * fname ){ |
- | |
634 | char * argv[ 2 ]; |
- | |
635 | // char * argv[ 4 ]; |
- | |
636 | task_id_t res; |
- | |
637 | - | ||
638 | // printf( "Spawning %s\n", fname ); |
- | |
639 | argv[ 0 ] = fname; |
- | |
640 | argv[ 1 ] = NULL; |
- | |
641 | res = task_spawn( fname, argv ); |
- | |
642 | /* argv[ 0 ] = "/app/trace"; |
- | |
643 | argv[ 1 ] = "+ti"; |
- | |
644 | argv[ 2 ] = fname; |
- | |
645 | argv[ 3 ] = NULL; |
- | |
646 | res = task_spawn( "/app/trace", argv ); |
- | |
647 | */ |
- | |
648 | if( res != 0 ){ |
- | |
649 | /* Success */ |
- | |
650 | usleep( 50000 ); |
- | |
651 | } |
- | |
652 | return res; |
- | |
653 | } |
- | |
654 | - | ||
655 | int startup( void ){ |
505 | int startup( void ){ |
656 | ERROR_DECLARE; |
506 | ERROR_DECLARE; |
657 | 507 | ||
- | 508 | char * conf_files[] = { "lo", "ne2k" }; |
|
- | 509 | int count = sizeof( conf_files ) / sizeof( char * ); |
|
- | 510 | int index; |
|
- | 511 | netif_ref netif; |
|
- | 512 | int i; |
|
- | 513 | measured_string_ref setting; |
|
- | 514 | ||
658 | // read configuration files |
515 | // TODO dynamic configuration |
659 | if( ERROR_OCCURRED( read_configuration())) return ERROR_CODE; |
516 | ERROR_PROPAGATE( read_configuration()); |
- | 517 | ||
- | 518 | for( i = 0; i < count; ++ i ){ |
|
- | 519 | netif = ( netif_ref ) malloc( sizeof( netif_t )); |
|
- | 520 | if( ! netif ) return ENOMEM; |
|
660 | 521 | ||
- | 522 | netif->id = generate_new_device_id(); |
|
- | 523 | if( ! netif->id ) return EXDEV; |
|
- | 524 | ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); |
|
- | 525 | // read configuration files |
|
- | 526 | if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif ))){ |
|
- | 527 | measured_strings_destroy( & netif->configuration ); |
|
- | 528 | free( netif ); |
|
- | 529 | return ERROR_CODE; |
|
- | 530 | } |
|
- | 531 | // mandatory name |
|
- | 532 | setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 ); |
|
- | 533 | if( ! setting ){ |
|
- | 534 | printf( "\nThe name is missing" ); |
|
- | 535 | measured_strings_destroy( & netif->configuration ); |
|
- | 536 | free( netif ); |
|
- | 537 | return EINVAL; |
|
- | 538 | } |
|
- | 539 | netif->name = setting->value; |
|
- | 540 | // add to the netifs map |
|
- | 541 | index = netifs_add( & networking_globals.netifs, netif->id, netif ); |
|
- | 542 | if( index < 0 ){ |
|
- | 543 | measured_strings_destroy( & netif->configuration ); |
|
- | 544 | free( netif ); |
|
- | 545 | return index; |
|
- | 546 | } |
|
- | 547 | // add to the netif names map |
|
- | 548 | if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index )) |
|
661 | // start network interfaces and needed modules |
549 | // start network interfaces and needed modules |
- | 550 | || ERROR_OCCURRED( start_device( netif ))){ |
|
662 | // start_device( "/sbin/lo", "/sbin/dummy_link_layer" ); |
551 | measured_strings_destroy( & netif->configuration ); |
- | 552 | netifs_exclude_index( & networking_globals.netifs, index ); |
|
- | 553 | return ERROR_CODE; |
|
- | 554 | } |
|
- | 555 | // increment modules' usage |
|
- | 556 | ++ netif->driver->usage; |
|
- | 557 | if( netif->nil ) ++ netif->nil->usage; |
|
- | 558 | ++ netif->il->usage; |
|
- | 559 | printf( "\nNew network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name ); |
|
- | 560 | } |
|
663 | return EOK; |
561 | return EOK; |
664 | } |
562 | } |
665 | 563 | ||
666 | /** @} |
564 | /** @} |
667 | */ |
565 | */ |