Ignore:
File:
1 edited

Legend:

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

    ra64c64d raadf01e  
    6666#include "net_messages.h"
    6767
     68/** Networking module name.
     69 */
     70#define NAME    "Networking"
     71
    6872/** File read buffer size.
    6973 */
    7074#define BUFFER_SIZE     256
    71 
    72 /** Networking module name.
    73  */
    74 #define NAME    "Networking"
    75 
    76 /** Networking module global data.
    77  */
    78 net_globals_t   net_globals;
    79 
    80 /** Generates new system-unique device identifier.
    81  *  @returns The system-unique devic identifier.
    82  */
    83 device_id_t generate_new_device_id(void);
    8475
    8576/** Prints the module name.
     
    9788int module_start(async_client_conn_t client_connection);
    9889
    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  */
    107 int 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  */
    114 int net_initialize(async_client_conn_t client_connection);
     90/** \todo
     91 */
     92int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
    11593
    11694/** \todo
     
    123101 */
    124102int read_configuration(void);
    125 
    126 /** \todo
    127  */
    128 int 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  */
    136 int read_netif_configuration(const char * name, netif_ref netif);
    137103
    138104/** Starts the network interface according to its configuration.
     
    160126int startup(void);
    161127
     128/** Generates new system-unique device identifier.
     129 *  @returns The system-unique devic identifier.
     130 */
     131device_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 */
     141int 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 */
     148int 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 */
     156int read_netif_configuration(const char * name, netif_ref netif);
     157
     158/** Networking module global data.
     159 */
     160net_globals_t   net_globals;
     161
     162DEVICE_MAP_IMPLEMENT(netifs, netif_t)
     163
    162164GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
    163 
    164 DEVICE_MAP_IMPLEMENT(netifs, netif_t)
    165 
    166 int 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 
    183 device_id_t generate_new_device_id(void){
    184         return device_assign_devno();
    185 }
    186165
    187166void module_print_name(void){
     
    208187}
    209188
    210 int net_connect_module(services_t service){
    211         return EOK;
    212 }
    213 
    214 void net_free_settings(measured_string_ref settings, char * data){
     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);
     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
     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);
     218        }else{
     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);
    215228}
    216229
     
    222235                *data = NULL;
    223236        }
    224 
    225237        for(index = 0; index < count; ++ index){
    226238                setting = measured_strings_find(netif_conf, configuration[index].value, 0);
     
    239251}
    240252
    241 int 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 
    249 int 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 
    264 int 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);
     253void net_free_settings(measured_string_ref settings, char * data){
     254}
     255
     256int net_connect_module(services_t service){
     257        return EOK;
    282258}
    283259
     
    312288        }
    313289        return ENOTSUP;
    314 }
    315 
    316 int 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 
    380 int read_configuration(void){
    381         // read the general configuration file
    382         return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
    383290}
    384291
     
    434341}
    435342
     343int 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
     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        }
     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
     424device_id_t generate_new_device_id(void){
     425        return device_assign_devno();
     426}
     427
     428int read_configuration(void){
     429        // read the general configuration file
     430        return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
     431}
     432
    436433int read_netif_configuration(const char * name, netif_ref netif){
    437434        // read the netif configuration file
     
    455452                return EINVAL;
    456453        }
    457 
    458454        // optional network interface layer
    459455        setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
     
    467463                netif->nil = NULL;
    468464        }
    469 
    470465        // mandatory internet layer
    471466        setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
     
    475470                return EINVAL;
    476471        }
    477 
    478         // hardware configuration
     472        // end of the static loopback initialization
     473        // startup the loopback interface
    479474        setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
    480475        irq = setting ? strtol(setting->value, NULL, 10) : 0;
     
    482477        io = setting ? strtol(setting->value, NULL, 16) : 0;
    483478        ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io));
    484 
    485         // network interface layer startup
    486479        if(netif->nil){
    487480                setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
     
    495488                internet_service = netif->driver->service;
    496489        }
    497 
    498         // inter-network layer startup
    499490        switch(netif->il->service){
    500491                case SERVICE_IP:
     
    534525                }
    535526                ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
    536 
    537527                // read configuration files
    538528                if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){
     
    541531                        return ERROR_CODE;
    542532                }
    543 
    544533                // mandatory name
    545534                setting = measured_strings_find(&netif->configuration, CONF_NAME, 0);
     
    551540                }
    552541                netif->name = setting->value;
    553 
    554542                // add to the netifs map
    555543                index = netifs_add(&net_globals.netifs, netif->id, netif);
     
    559547                        return index;
    560548                }
    561 
    562549                // add to the netif names map
    563550                if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))
     
    568555                        return ERROR_CODE;
    569556                }
    570 
    571557                // increment modules' usage
    572558                ++ netif->driver->usage;
Note: See TracChangeset for help on using the changeset viewer.