Ignore:
File:
1 edited

Legend:

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

    raadf01e ra64c64d  
    6666#include "net_messages.h"
    6767
     68/** File read buffer size.
     69 */
     70#define BUFFER_SIZE     256
     71
    6872/** Networking module name.
    6973 */
    7074#define NAME    "Networking"
    7175
    72 /** File read buffer size.
    73  */
    74 #define BUFFER_SIZE     256
     76/** Networking module global data.
     77 */
     78net_globals_t   net_globals;
     79
     80/** Generates new system-unique device identifier.
     81 *  @returns The system-unique devic identifier.
     82 */
     83device_id_t generate_new_device_id(void);
    7584
    7685/** Prints the module name.
     
    8897int module_start(async_client_conn_t client_connection);
    8998
    90 /** \todo
    91  */
    92 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
     99/** Returns the configured values.
     100 *  The network interface configuration is searched first.
     101 *  @param[in] netif_conf The network interface configuration setting.
     102 *  @param[out] configuration The found configured values.
     103 *  @param[in] count The desired settings count.
     104 *  @param[out] data The found configuration settings data.
     105 *  @returns EOK.
     106 */
     107int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
     108
     109/** Initializes the networking module.
     110 *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
     111 *  @returns EOK on success.
     112 *  @returns ENOMEM if there is not enough memory left.
     113 */
     114int net_initialize(async_client_conn_t client_connection);
    93115
    94116/** \todo
     
    101123 */
    102124int read_configuration(void);
     125
     126/** \todo
     127 */
     128int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
     129
     130/** Reads the network interface specific configuration.
     131 *  @param[in] name The network interface name.
     132 *  @param[in,out] netif The network interface structure.
     133 *  @returns EOK on success.
     134 *  @returns Other error codes as defined for the add_configuration() function.
     135 */
     136int read_netif_configuration(const char * name, netif_ref netif);
    103137
    104138/** Starts the network interface according to its configuration.
     
    126160int startup(void);
    127161
    128 /** Generates new system-unique device identifier.
    129  *  @returns The system-unique devic identifier.
    130  */
    131 device_id_t generate_new_device_id(void);
    132 
    133 /** Returns the configured values.
    134  *  The network interface configuration is searched first.
    135  *  @param[in] netif_conf The network interface configuration setting.
    136  *  @param[out] configuration The found configured values.
    137  *  @param[in] count The desired settings count.
    138  *  @param[out] data The found configuration settings data.
    139  *  @returns EOK.
    140  */
    141 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
    142 
    143 /** Initializes the networking module.
    144  *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
    145  *  @returns EOK on success.
    146  *  @returns ENOMEM if there is not enough memory left.
    147  */
    148 int net_initialize(async_client_conn_t client_connection);
    149 
    150 /** Reads the network interface specific configuration.
    151  *  @param[in] name The network interface name.
    152  *  @param[in,out] netif The network interface structure.
    153  *  @returns EOK on success.
    154  *  @returns Other error codes as defined for the add_configuration() function.
    155  */
    156 int read_netif_configuration(const char * name, netif_ref netif);
    157 
    158 /** Networking module global data.
    159  */
    160 net_globals_t   net_globals;
     162GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
    161163
    162164DEVICE_MAP_IMPLEMENT(netifs, netif_t)
    163165
    164 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
     166int add_configuration(measured_strings_ref configuration, const char * name, const char * value){
     167        ERROR_DECLARE;
     168
     169        measured_string_ref setting;
     170
     171        setting = measured_string_create_bulk(value, 0);
     172        if(! setting){
     173                return ENOMEM;
     174        }
     175        // add the configuration setting
     176        if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
     177                free(setting);
     178                return ERROR_CODE;
     179        }
     180        return EOK;
     181}
     182
     183device_id_t generate_new_device_id(void){
     184        return device_assign_devno();
     185}
    165186
    166187void module_print_name(void){
     
    187208}
    188209
    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);
    196 
    197         // 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));
    204 
    205         // 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))){
    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);
    218         }else{
    219                 return net_get_conf(NULL, * configuration, count, data);
    220         }
    221 }
    222 
    223 int 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);
     210int net_connect_module(services_t service){
     211        return EOK;
     212}
     213
     214void net_free_settings(measured_string_ref settings, char * data){
    228215}
    229216
     
    235222                *data = NULL;
    236223        }
     224
    237225        for(index = 0; index < count; ++ index){
    238226                setting = measured_strings_find(netif_conf, configuration[index].value, 0);
     
    251239}
    252240
    253 void net_free_settings(measured_string_ref settings, char * data){
    254 }
    255 
    256 int net_connect_module(services_t service){
    257         return EOK;
     241int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
     242        if(!(configuration && (count > 0))){
     243                return EINVAL;
     244        }
     245
     246        return net_get_conf(NULL, * configuration, count, data);
     247}
     248
     249int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
     250        netif_ref netif;
     251
     252        if(!(configuration && (count > 0))){
     253                return EINVAL;
     254        }
     255
     256        netif = netifs_find(&net_globals.netifs, device_id);
     257        if(netif){
     258                return net_get_conf(&netif->configuration, * configuration, count, data);
     259        }else{
     260                return net_get_conf(NULL, * configuration, count, data);
     261        }
     262}
     263
     264int net_initialize(async_client_conn_t client_connection){
     265        ERROR_DECLARE;
     266
     267        netifs_initialize(&net_globals.netifs);
     268        char_map_initialize(&net_globals.netif_names);
     269        modules_initialize(&net_globals.modules);
     270        measured_strings_initialize(&net_globals.configuration);
     271
     272        // TODO dynamic configuration
     273        ERROR_PROPAGATE(read_configuration());
     274
     275        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
     276        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
     277        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service));
     278        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service));
     279
     280        // build specific initialization
     281        return net_initialize_build(client_connection);
    258282}
    259283
     
    288312        }
    289313        return ENOTSUP;
     314}
     315
     316int parse_line(measured_strings_ref configuration, char * line){
     317        ERROR_DECLARE;
     318
     319        measured_string_ref setting;
     320        char * name;
     321        char * value;
     322
     323        // from the beginning
     324        name = line;
     325
     326        // skip comments and blank lines
     327        if((*name == '#') || (*name == '\0')){
     328                return EOK;
     329        }
     330        // skip spaces
     331        while(isspace(*name)){
     332                ++ name;
     333        }
     334
     335        // remember the name start
     336        value = name;
     337        // skip the name
     338        while(isalnum(*value) || (*value == '_')){
     339                // make uppercase
     340//              *value = toupper(*value);
     341                ++ value;
     342        }
     343
     344        if(*value == '='){
     345                // terminate the name
     346                *value = '\0';
     347        }else{
     348                // terminate the name
     349                *value = '\0';
     350                // skip until '='
     351                ++ value;
     352                while((*value) && (*value != '=')){
     353                        ++ value;
     354                }
     355                // not found?
     356                if(*value != '='){
     357                        return EINVAL;
     358                }
     359        }
     360
     361        ++ value;
     362        // skip spaces
     363        while(isspace(*value)){
     364                ++ value;
     365        }
     366        // create a bulk measured string till the end
     367        setting = measured_string_create_bulk(value, 0);
     368        if(! setting){
     369                return ENOMEM;
     370        }
     371
     372        // add the configuration setting
     373        if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
     374                free(setting);
     375                return ERROR_CODE;
     376        }
     377        return EOK;
     378}
     379
     380int read_configuration(void){
     381        // read the general configuration file
     382        return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
    290383}
    291384
     
    341434}
    342435
    343 int parse_line(measured_strings_ref configuration, char * line){
    344         ERROR_DECLARE;
    345 
    346         measured_string_ref setting;
    347         char * name;
    348         char * value;
    349 
    350         // from the beginning
    351         name = line;
    352 
    353         // skip comments and blank lines
    354         if((*name == '#') || (*name == '\0')){
    355                 return EOK;
    356         }
    357         // skip spaces
    358         while(isspace(*name)){
    359                 ++ name;
    360         }
    361 
    362         // remember the name start
    363         value = name;
    364         // skip the name
    365         while(isalnum(*value) || (*value == '_')){
    366                 // make uppercase
    367 //              *value = toupper(*value);
    368                 ++ value;
    369         }
    370 
    371         if(*value == '='){
    372                 // terminate the name
    373                 *value = '\0';
    374         }else{
    375                 // terminate the name
    376                 *value = '\0';
    377                 // skip until '='
    378                 ++ value;
    379                 while((*value) && (*value != '=')){
    380                         ++ value;
    381                 }
    382                 // not found?
    383                 if(*value != '='){
    384                         return EINVAL;
    385                 }
    386         }
    387 
    388         ++ value;
    389         // skip spaces
    390         while(isspace(*value)){
    391                 ++ value;
    392         }
    393         // create a bulk measured string till the end
    394         setting = measured_string_create_bulk(value, 0);
    395         if(! setting){
    396                 return ENOMEM;
    397         }
    398 
    399         // add the configuration setting
    400         if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
    401                 free(setting);
    402                 return ERROR_CODE;
    403         }
    404         return EOK;
    405 }
    406 
    407 int 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         }
    416         // add the configuration setting
    417         if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
    418                 free(setting);
    419                 return ERROR_CODE;
    420         }
    421         return EOK;
    422 }
    423 
    424 device_id_t generate_new_device_id(void){
    425         return device_assign_devno();
    426 }
    427 
    428 int read_configuration(void){
    429         // read the general configuration file
    430         return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
    431 }
    432 
    433436int read_netif_configuration(const char * name, netif_ref netif){
    434437        // read the netif configuration file
     
    452455                return EINVAL;
    453456        }
     457
    454458        // optional network interface layer
    455459        setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
     
    463467                netif->nil = NULL;
    464468        }
     469
    465470        // mandatory internet layer
    466471        setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
     
    470475                return EINVAL;
    471476        }
    472         // end of the static loopback initialization
    473         // startup the loopback interface
     477
     478        // hardware configuration
    474479        setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
    475480        irq = setting ? strtol(setting->value, NULL, 10) : 0;
     
    477482        io = setting ? strtol(setting->value, NULL, 16) : 0;
    478483        ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io));
     484
     485        // network interface layer startup
    479486        if(netif->nil){
    480487                setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
     
    488495                internet_service = netif->driver->service;
    489496        }
     497
     498        // inter-network layer startup
    490499        switch(netif->il->service){
    491500                case SERVICE_IP:
     
    525534                }
    526535                ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
     536
    527537                // read configuration files
    528538                if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){
     
    531541                        return ERROR_CODE;
    532542                }
     543
    533544                // mandatory name
    534545                setting = measured_strings_find(&netif->configuration, CONF_NAME, 0);
     
    540551                }
    541552                netif->name = setting->value;
     553
    542554                // add to the netifs map
    543555                index = netifs_add(&net_globals.netifs, netif->id, netif);
     
    547559                        return index;
    548560                }
     561
    549562                // add to the netif names map
    550563                if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))
     
    555568                        return ERROR_CODE;
    556569                }
     570
    557571                // increment modules' usage
    558572                ++ netif->driver->usage;
Note: See TracChangeset for help on using the changeset viewer.