Changeset 71b00dcc in mainline for uspace/srv/net/net/net.c


Ignore:
Timestamp:
2010-03-07T22:51:38Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
60ab6c3
Parents:
b5cbff4 (diff), 31c80a5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~lukasmejdrech/helenos/network.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/net/net.c

    rb5cbff4 r71b00dcc  
    7777 *  @see NAME
    7878 */
    79 void    module_print_name( void );
     79void module_print_name(void);
    8080
    8181/** Starts the networking module.
     
    8686 *  @returns Other error codes as defined for the REGISTER_ME() macro function.
    8787 */
    88 int module_start( async_client_conn_t client_connection );
     88int module_start(async_client_conn_t client_connection);
    8989
    9090/** \todo
    9191 */
    92 int     read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration );
     92int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
    9393
    9494/** \todo
    9595 */
    96 int     parse_line( measured_strings_ref configuration, char * line );
     96int parse_line(measured_strings_ref configuration, char * line);
    9797
    9898/** Reads the networking subsystem global configuration.
     
    100100 *  @returns Other error codes as defined for the add_configuration() function.
    101101 */
    102 int             read_configuration( void );
     102int read_configuration(void);
    103103
    104104/** Starts the network interface according to its configuration.
     
    113113 *  @returns Other error codes as defined for the needed internet layer registering function.
    114114 */
    115 int             start_device( netif_ref netif );
     115int start_device(netif_ref netif);
    116116
    117117/** Reads the configuration and starts all network interfaces.
     
    124124 *  @returns Other error codes as defined for the start_device() function.
    125125 */
    126 int             startup( void );
     126int startup(void);
    127127
    128128/** Generates new system-unique device identifier.
    129129 *  @returns The system-unique devic identifier.
    130130 */
    131 device_id_t     generate_new_device_id( void );
     131device_id_t generate_new_device_id(void);
    132132
    133133/** Returns the configured values.
     
    139139 *  @returns EOK.
    140140 */
    141 int     net_get_conf( measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data );
     141int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
    142142
    143143/** Initializes the networking module.
     
    146146 *  @returns ENOMEM if there is not enough memory left.
    147147 */
    148 int     net_initialize( async_client_conn_t client_connection );
     148int net_initialize(async_client_conn_t client_connection);
    149149
    150150/** Reads the network interface specific configuration.
     
    154154 *  @returns Other error codes as defined for the add_configuration() function.
    155155 */
    156 int     read_netif_configuration( const char * name, netif_ref netif );
     156int read_netif_configuration(const char * name, netif_ref netif);
    157157
    158158/** Networking module global data.
     
    160160net_globals_t   net_globals;
    161161
    162 DEVICE_MAP_IMPLEMENT( netifs, netif_t )
    163 
    164 GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t )
    165 
    166 void module_print_name( void ){
    167         printf( "%s", NAME );
    168 }
    169 
    170 int module_start( async_client_conn_t client_connection ){
    171         ERROR_DECLARE;
    172 
    173         ipcarg_t        phonehash;
    174 
    175         async_set_client_connection( client_connection );
    176         ERROR_PROPAGATE( pm_init());
    177         if( ERROR_OCCURRED( net_initialize( client_connection ))
    178         || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){
     162DEVICE_MAP_IMPLEMENT(netifs, netif_t)
     163
     164GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
     165
     166void module_print_name(void){
     167        printf("%s", NAME);
     168}
     169
     170int module_start(async_client_conn_t client_connection){
     171        ERROR_DECLARE;
     172
     173        ipcarg_t phonehash;
     174
     175        async_set_client_connection(client_connection);
     176        ERROR_PROPAGATE(pm_init());
     177        if(ERROR_OCCURRED(net_initialize(client_connection))
     178                || ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){
    179179                pm_destroy();
    180180                return ERROR_CODE;
     
    187187}
    188188
    189 int net_initialize( async_client_conn_t client_connection ){
    190         ERROR_DECLARE;
    191 
    192         netifs_initialize( & net_globals.netifs );
    193         char_map_initialize( & net_globals.netif_names );
    194         modules_initialize( & net_globals.modules );
    195         measured_strings_initialize( & net_globals.configuration );
     189int net_initialize(async_client_conn_t client_connection){
     190        ERROR_DECLARE;
     191
     192        netifs_initialize(&net_globals.netifs);
     193        char_map_initialize(&net_globals.netif_names);
     194        modules_initialize(&net_globals.modules);
     195        measured_strings_initialize(&net_globals.configuration);
    196196
    197197        // TODO dynamic configuration
    198         ERROR_PROPAGATE( read_configuration());
    199 
    200         ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service ));
    201         ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service ));
    202         ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service ));
    203         ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service ));
     198        ERROR_PROPAGATE(read_configuration());
     199
     200        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
     201        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
     202        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service));
     203        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service));
    204204
    205205        // build specific initialization
    206         return net_initialize_build( client_connection );
    207 }
    208 
    209 int     net_get_device_conf_req( int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data ){
    210         netif_ref       netif;
    211 
    212         if( !( configuration && ( count > 0 ))) return EINVAL;
    213         netif = netifs_find( & net_globals.netifs, device_id );
    214         if( netif ){
    215                 return net_get_conf( & netif->configuration, * configuration, count, data );
     206        return net_initialize_build(client_connection);
     207}
     208
     209int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
     210        netif_ref netif;
     211
     212        if(!(configuration && (count > 0))){
     213                return EINVAL;
     214        }
     215        netif = netifs_find(&net_globals.netifs, device_id);
     216        if(netif){
     217                return net_get_conf(&netif->configuration, * configuration, count, data);
    216218        }else{
    217                 return net_get_conf( NULL, * configuration, count, data );
    218         }
    219 }
    220 
    221 int     net_get_conf_req( int net_phone, measured_string_ref * configuration, size_t count, char ** data ){
    222         if( !( configuration && ( count > 0 ))) return EINVAL;
    223         return net_get_conf( NULL, * configuration, count, data );
    224 }
    225 
    226 int     net_get_conf( measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data ){
    227         measured_string_ref     setting;
    228         size_t                          index;
    229 
    230         if( data ) * data = NULL;
    231         for( index = 0; index < count; ++ index ){
    232                 setting = measured_strings_find( netif_conf, configuration[ index ].value, 0 );
    233                 if( ! setting ){
    234                         setting = measured_strings_find( & net_globals.configuration, configuration[ index ].value, 0 );
    235                 }
    236                 if( setting ){
    237                         configuration[ index ].length = setting->length;
    238                         configuration[ index ].value = setting->value;
     219                return net_get_conf(NULL, * configuration, count, data);
     220        }
     221}
     222
     223int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
     224        if(!(configuration && (count > 0))){
     225                return EINVAL;
     226        }
     227        return net_get_conf(NULL, * configuration, count, data);
     228}
     229
     230int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data){
     231        measured_string_ref setting;
     232        size_t index;
     233
     234        if(data){
     235                *data = NULL;
     236        }
     237        for(index = 0; index < count; ++ index){
     238                setting = measured_strings_find(netif_conf, configuration[index].value, 0);
     239                if(! setting){
     240                        setting = measured_strings_find(&net_globals.configuration, configuration[index].value, 0);
     241                }
     242                if(setting){
     243                        configuration[index].length = setting->length;
     244                        configuration[index].value = setting->value;
    239245                }else{
    240                         configuration[ index ].length = 0;
    241                         configuration[ index ].value = NULL;
    242                 }
    243         }
    244         return EOK;
    245 }
    246 
    247 void net_free_settings( measured_string_ref settings, char * data ){
    248 }
    249 
    250 int net_connect_module( services_t service ){
    251         return EOK;
    252 }
    253 
    254 int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
    255         ERROR_DECLARE;
    256 
    257         measured_string_ref     strings;
    258         char *                          data;
    259 
    260         * answer_count = 0;
    261         switch( IPC_GET_METHOD( * call )){
     246                        configuration[index].length = 0;
     247                        configuration[index].value = NULL;
     248                }
     249        }
     250        return EOK;
     251}
     252
     253void net_free_settings(measured_string_ref settings, char * data){
     254}
     255
     256int net_connect_module(services_t service){
     257        return EOK;
     258}
     259
     260int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     261        ERROR_DECLARE;
     262
     263        measured_string_ref strings;
     264        char * data;
     265
     266        *answer_count = 0;
     267        switch(IPC_GET_METHOD(*call)){
    262268                case IPC_M_PHONE_HUNGUP:
    263269                        return EOK;
    264270                case NET_NET_GET_DEVICE_CONF:
    265                         ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
    266                         net_get_device_conf_req( 0, IPC_GET_DEVICE( call ), & strings, IPC_GET_COUNT( call ), NULL );
     271                        ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call)));
     272                        net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings, IPC_GET_COUNT(call), NULL);
    267273                        // strings should not contain received data anymore
    268                         free( data );
    269                         ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
    270                         free( strings );
     274                        free(data);
     275                        ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
     276                        free(strings);
    271277                        return ERROR_CODE;
    272278                case NET_NET_GET_CONF:
    273                         ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
    274                         net_get_conf_req( 0, & strings, IPC_GET_COUNT( call ), NULL );
     279                        ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call)));
     280                        net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
    275281                        // strings should not contain received data anymore
    276                         free( data );
    277                         ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
    278                         free( strings );
     282                        free(data);
     283                        ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
     284                        free(strings);
    279285                        return ERROR_CODE;
    280286                case NET_NET_STARTUP:
     
    284290}
    285291
    286 int read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration ){
    287         ERROR_DECLARE;
    288 
    289         size_t  index = 0;
    290         char    line[ BUFFER_SIZE ];
    291         FILE *  cfg;
    292         int             read;
    293         int             line_number = 0;
     292int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration){
     293        ERROR_DECLARE;
     294
     295        size_t index = 0;
     296        char line[BUFFER_SIZE];
     297        FILE * cfg;
     298        int read;
     299        int line_number = 0;
    294300
    295301        // construct the full filename
    296         printf( "Reading file %s/%s\n", directory, filename );
    297         if( snprintf( line, BUFFER_SIZE, "%s/%s", directory, filename ) > BUFFER_SIZE ){
     302        printf("Reading file %s/%s\n", directory, filename);
     303        if(snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE){
    298304                return EOVERFLOW;
    299305        }
    300306        // open the file
    301         cfg = fopen( line, "r" );
    302         if( ! cfg ){
     307        cfg = fopen(line, "r");
     308        if(! cfg){
    303309                return ENOENT;
    304310        }
     
    306312        // read the configuration line by line
    307313        // until an error or the end of file
    308         while(( ! ferror( cfg )) && ( ! feof( cfg ))){
    309                 read = fgetc( cfg );
    310                 if(( read > 0 ) && ( read != '\n' ) && ( read != '\r' )){
    311                         if( index >= BUFFER_SIZE ){
    312                                 line[ BUFFER_SIZE - 1 ] = '\0';
    313                                 printf( "line %d too long: %s\n", line_number, line );
     314        while((! ferror(cfg)) && (! feof(cfg))){
     315                read = fgetc(cfg);
     316                if((read > 0) && (read != '\n') && (read != '\r')){
     317                        if(index >= BUFFER_SIZE){
     318                                line[BUFFER_SIZE - 1] = '\0';
     319                                printf("line %d too long: %s\n", line_number, line);
    314320                                // no space left in the line buffer
    315321                                return EOVERFLOW;
    316322                        }else{
    317323                                // append the character
    318                                 line[ index ] = (char) read;
     324                                line[index] = (char) read;
    319325                                ++ index;
    320326                        }
    321327                }else{
    322328                        // on error or new line
    323                         line[ index ] = '\0';
     329                        line[index] = '\0';
    324330                        ++ line_number;
    325                         if( ERROR_OCCURRED( parse_line( configuration, line ))){
    326                                 printf( "error on line %d: %s\n", line_number, line );
    327                                 //fclose( cfg );
     331                        if(ERROR_OCCURRED(parse_line(configuration, line))){
     332                                printf("error on line %d: %s\n", line_number, line);
     333                                //fclose(cfg);
    328334                                //return ERROR_CODE;
    329335                        }
     
    331337                }
    332338        }
    333         fclose( cfg );
    334         return EOK;
    335 }
    336 
    337 int parse_line( measured_strings_ref configuration, char * line ){
    338         ERROR_DECLARE;
    339 
    340         measured_string_ref     setting;
    341         char *                          name;
    342         char *                          value;
     339        fclose(cfg);
     340        return EOK;
     341}
     342
     343int parse_line(measured_strings_ref configuration, char * line){
     344        ERROR_DECLARE;
     345
     346        measured_string_ref setting;
     347        char * name;
     348        char * value;
    343349
    344350        // from the beginning
     
    346352
    347353        // skip comments and blank lines
    348         if(( * name == '#' ) || ( * name == '\0' )){
     354        if((*name == '#') || (*name == '\0')){
    349355                return EOK;
    350356        }
    351357        // skip spaces
    352         while( isspace( * name )) ++ name;
     358        while(isspace(*name)){
     359                ++ name;
     360        }
    353361
    354362        // remember the name start
    355363        value = name;
    356364        // skip the name
    357         while( isalnum( * value ) || ( * value == '_' )){
     365        while(isalnum(*value) || (*value == '_')){
    358366                // make uppercase
    359 //              * value = toupper( * value );
     367//              *value = toupper(*value);
    360368                ++ value;
    361369        }
    362370
    363         if( * value == '=' ){
     371        if(*value == '='){
    364372                // terminate the name
    365                 * value = '\0';
     373                *value = '\0';
    366374        }else{
    367375                // terminate the name
    368                 * value = '\0';
     376                *value = '\0';
    369377                // skip until '='
    370378                ++ value;
    371                 while(( * value ) && ( * value != '=' )) ++ value;
     379                while((*value) && (*value != '=')){
     380                        ++ value;
     381                }
    372382                // not found?
    373                 if( * value != '=' ) return EINVAL;
     383                if(*value != '='){
     384                        return EINVAL;
     385                }
    374386        }
    375387
    376388        ++ value;
    377389        // skip spaces
    378         while( isspace( * value )) ++ value;
     390        while(isspace(*value)){
     391                ++ value;
     392        }
    379393        // create a bulk measured string till the end
    380         setting = measured_string_create_bulk( value, 0 );
    381         if( ! setting ) return ENOMEM;
     394        setting = measured_string_create_bulk(value, 0);
     395        if(! setting){
     396                return ENOMEM;
     397        }
    382398
    383399        // add the configuration setting
    384         if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
    385                 free( setting );
     400        if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
     401                free(setting);
    386402                return ERROR_CODE;
    387403        }
     
    389405}
    390406
    391 int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){
    392         ERROR_DECLARE;
    393 
    394         measured_string_ref     setting;
    395 
    396         setting = measured_string_create_bulk( value, 0 );
    397         if( ! setting ) return ENOMEM;
     407int add_configuration(measured_strings_ref configuration, const char * name, const char * value){
     408        ERROR_DECLARE;
     409
     410        measured_string_ref setting;
     411
     412        setting = measured_string_create_bulk(value, 0);
     413        if(! setting){
     414                return ENOMEM;
     415        }
    398416        // add the configuration setting
    399         if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
    400                 free( setting );
     417        if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
     418                free(setting);
    401419                return ERROR_CODE;
    402420        }
     
    404422}
    405423
    406 device_id_t generate_new_device_id( void ){
     424device_id_t generate_new_device_id(void){
    407425        return device_assign_devno();
    408426}
    409427
    410 int read_configuration( void ){
     428int read_configuration(void){
    411429        // read the general configuration file
    412         return read_configuration_file( CONF_DIR, CONF_GENERAL_FILE, & net_globals.configuration );
    413 }
    414 
    415 int read_netif_configuration( const char * name, netif_ref netif ){
     430        return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
     431}
     432
     433int read_netif_configuration(const char * name, netif_ref netif){
    416434        // read the netif configuration file
    417         return read_configuration_file( CONF_DIR, name, & netif->configuration );
    418 }
    419 
    420 int start_device( netif_ref netif ){
    421         ERROR_DECLARE;
    422 
    423         measured_string_ref     setting;
    424         services_t                      internet_service;
    425         int                                     irq;
    426         int                                     io;
    427         int                                     mtu;
     435        return read_configuration_file(CONF_DIR, name, &netif->configuration);
     436}
     437
     438int start_device(netif_ref netif){
     439        ERROR_DECLARE;
     440
     441        measured_string_ref setting;
     442        services_t internet_service;
     443        int irq;
     444        int io;
     445        int mtu;
    428446
    429447        // mandatory netif
    430         setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 );
    431         netif->driver = get_running_module( & net_globals.modules, setting->value );
    432         if( ! netif->driver ){
    433                 printf( "Failed to start the network interface driver %s\n", setting->value );
     448        setting = measured_strings_find(&netif->configuration, CONF_NETIF, 0);
     449        netif->driver = get_running_module(&net_globals.modules, setting->value);
     450        if(! netif->driver){
     451                printf("Failed to start the network interface driver %s\n", setting->value);
    434452                return EINVAL;
    435453        }
    436454        // optional network interface layer
    437         setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 );
    438         if( setting ){
    439                 netif->nil = get_running_module( & net_globals.modules, setting->value );
    440                 if( ! netif->nil ){
    441                         printf( "Failed to start the network interface layer %s\n", setting->value );
     455        setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
     456        if(setting){
     457                netif->nil = get_running_module(&net_globals.modules, setting->value);
     458                if(! netif->nil){
     459                        printf("Failed to start the network interface layer %s\n", setting->value);
    442460                        return EINVAL;
    443461                }
     
    446464        }
    447465        // mandatory internet layer
    448         setting = measured_strings_find( & netif->configuration, CONF_IL, 0 );
    449         netif->il = get_running_module( & net_globals.modules, setting->value );
    450         if( ! netif->il ){
    451                 printf( "Failed to start the internet layer %s\n", setting->value );
     466        setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
     467        netif->il = get_running_module(&net_globals.modules, setting->value);
     468        if(! netif->il){
     469                printf("Failed to start the internet layer %s\n", setting->value);
    452470                return EINVAL;
    453471        }
    454472        // end of the static loopback initialization
    455473        // startup the loopback interface
    456         setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 );
    457         irq = setting ? strtol( setting->value, NULL, 10 ) : 0;
    458         setting = measured_strings_find( & netif->configuration, CONF_IO, 0 );
    459         io = setting ? strtol( setting->value, NULL, 16 ) : 0;
    460         ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io ));
    461         if( netif->nil ){
    462                 setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 );
    463                 if( ! setting ){
    464                         setting = measured_strings_find( & net_globals.configuration, CONF_MTU, 0 );
    465                 }
    466                 mtu = setting ? strtol( setting->value, NULL, 10 ) : 0;
    467                 ERROR_PROPAGATE( nil_device_req( netif->nil->phone, netif->id, mtu, netif->driver->service ));
     474        setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
     475        irq = setting ? strtol(setting->value, NULL, 10) : 0;
     476        setting = measured_strings_find(&netif->configuration, CONF_IO, 0);
     477        io = setting ? strtol(setting->value, NULL, 16) : 0;
     478        ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io));
     479        if(netif->nil){
     480                setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
     481                if(! setting){
     482                        setting = measured_strings_find(&net_globals.configuration, CONF_MTU, 0);
     483                }
     484                mtu = setting ? strtol(setting->value, NULL, 10) : 0;
     485                ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu, netif->driver->service));
    468486                internet_service = netif->nil->service;
    469487        }else{
    470488                internet_service = netif->driver->service;
    471489        }
    472         switch( netif->il->service ){
     490        switch(netif->il->service){
    473491                case SERVICE_IP:
    474                         ERROR_PROPAGATE( ip_device_req( netif->il->phone, netif->id, internet_service ));
     492                        ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id, internet_service));
    475493                        break;
    476494                default:
    477495                        return ENOENT;
    478496        }
    479         ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id ));
    480         return EOK;
    481 }
    482 
    483 int startup( void ){
     497        ERROR_PROPAGATE(netif_start_req(netif->driver->phone, netif->id));
     498        return EOK;
     499}
     500
     501int startup(void){
    484502        ERROR_DECLARE;
    485503
    486504#ifdef CONFIG_NETIF_DP8390
    487         const char *            conf_files[] = { "lo", "ne2k" };
     505        const char * conf_files[] = {"lo", "ne2k"};
    488506#else
    489         const char *            conf_files[] = { "lo" };
     507        const char * conf_files[] = {"lo"};
    490508#endif
    491509
    492         int                     count = sizeof( conf_files ) / sizeof( char * );
    493         int                     index;
    494         netif_ref       netif;
    495         int                     i;
    496         measured_string_ref     setting;
    497 
    498         for( i = 0; i < count; ++ i ){
    499                 netif = ( netif_ref ) malloc( sizeof( netif_t ));
    500                 if( ! netif ) return ENOMEM;
     510        int count = sizeof(conf_files) / sizeof(char *);
     511        int index;
     512        netif_ref netif;
     513        int i;
     514        measured_string_ref setting;
     515
     516        for(i = 0; i < count; ++ i){
     517                netif = (netif_ref) malloc(sizeof(netif_t));
     518                if(! netif){
     519                        return ENOMEM;
     520                }
    501521
    502522                netif->id = generate_new_device_id();
    503                 if( ! netif->id ) return EXDEV;
    504                 ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration ));
     523                if(! netif->id){
     524                        return EXDEV;
     525                }
     526                ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
    505527                // read configuration files
    506                 if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif ))){
    507                         measured_strings_destroy( & netif->configuration );
    508                         free( netif );
     528                if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){
     529                        measured_strings_destroy(&netif->configuration);
     530                        free(netif);
    509531                        return ERROR_CODE;
    510532                }
    511533                // mandatory name
    512                 setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 );
    513                 if( ! setting ){
    514                         printf( "The name is missing\n" );
    515                         measured_strings_destroy( & netif->configuration );
    516                         free( netif );
     534                setting = measured_strings_find(&netif->configuration, CONF_NAME, 0);
     535                if(! setting){
     536                        printf("The name is missing\n");
     537                        measured_strings_destroy(&netif->configuration);
     538                        free(netif);
    517539                        return EINVAL;
    518540                }
    519541                netif->name = setting->value;
    520542                // add to the netifs map
    521                 index = netifs_add( & net_globals.netifs, netif->id, netif );
    522                 if( index < 0 ){
    523                         measured_strings_destroy( & netif->configuration );
    524                         free( netif );
     543                index = netifs_add(&net_globals.netifs, netif->id, netif);
     544                if(index < 0){
     545                        measured_strings_destroy(&netif->configuration);
     546                        free(netif);
    525547                        return index;
    526548                }
    527549                // add to the netif names map
    528                 if( ERROR_OCCURRED( char_map_add( & net_globals.netif_names, netif->name, 0, index ))
     550                if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))
    529551                // start network interfaces and needed modules
    530                 || ERROR_OCCURRED( start_device( netif ))){
    531                         measured_strings_destroy( & netif->configuration );
    532                         netifs_exclude_index( & net_globals.netifs, index );
     552                        || ERROR_OCCURRED(start_device(netif))){
     553                        measured_strings_destroy(&netif->configuration);
     554                        netifs_exclude_index(&net_globals.netifs, index);
    533555                        return ERROR_CODE;
    534556                }
    535557                // increment modules' usage
    536558                ++ netif->driver->usage;
    537                 if( netif->nil ) ++ netif->nil->usage;
     559                if(netif->nil){
     560                        ++ netif->nil->usage;
     561                }
    538562                ++ netif->il->usage;
    539                 printf( "New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name );
     563                printf("New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name);
    540564        }
    541565        return EOK;
Note: See TracChangeset for help on using the changeset viewer.