Changeset ad7a6c9 in mainline for uspace/srv/net/net/net.c


Ignore:
Timestamp:
2011-03-30T13:10:24Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ae90f9
Parents:
6e50466 (diff), d6b81941 (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 mainline changes

File:
1 edited

Legend:

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

    r6e50466 rad7a6c9  
    4545#include <stdio.h>
    4646#include <str.h>
    47 
    48 #include <ipc/ipc.h>
     47#include <str_error.h>
     48
    4949#include <ipc/services.h>
    5050#include <ipc/net.h>
    5151#include <ipc/net_net.h>
    5252#include <ipc/il.h>
     53#include <ipc/nil.h>
    5354
    5455#include <net/modules.h>
     
    6263
    6364#include <netif_remote.h>
    64 #include <nil_interface.h>
     65#include <nil_remote.h>
    6566#include <net_interface.h>
    6667#include <ip_interface.h>
     
    9091 *
    9192 */
    92 int add_configuration(measured_strings_t *configuration, const char *name,
    93     const char *value)
     93int add_configuration(measured_strings_t *configuration, const uint8_t *name,
     94    const uint8_t *value)
    9495{
    9596        int rc;
     
    119120}
    120121
    121 static int parse_line(measured_strings_t *configuration, char *line)
     122static int parse_line(measured_strings_t *configuration, uint8_t *line)
    122123{
    123124        int rc;
    124125       
    125126        /* From the beginning */
    126         char *name = line;
     127        uint8_t *name = line;
    127128       
    128129        /* Skip comments and blank lines */
     
    135136       
    136137        /* Remember the name start */
    137         char *value = name;
     138        uint8_t *value = name;
    138139       
    139140        /* Skip the name */
     
    186187       
    187188        /* Construct the full filename */
    188         char line[BUFFER_SIZE];
    189         if (snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
     189        char fname[BUFFER_SIZE];
     190        if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
    190191                return EOVERFLOW;
    191192       
    192193        /* Open the file */
    193         FILE *cfg = fopen(line, "r");
     194        FILE *cfg = fopen(fname, "r");
    194195        if (!cfg)
    195196                return ENOENT;
     
    201202        unsigned int line_number = 0;
    202203        size_t index = 0;
     204        uint8_t line[BUFFER_SIZE];
     205       
    203206        while (!ferror(cfg) && !feof(cfg)) {
    204207                int read = fgetc(cfg);
     
    207210                                line[BUFFER_SIZE - 1] = '\0';
    208211                                fprintf(stderr, "%s: Configuration line %u too "
    209                                     "long: %s\n", NAME, line_number, line);
     212                                    "long: %s\n", NAME, line_number, (char *) line);
    210213                               
    211214                                /* No space left in the line buffer */
     
    213216                        }
    214217                        /* Append the character */
    215                         line[index] = (char) read;
     218                        line[index] = (uint8_t) read;
    216219                        index++;
    217220                } else {
     
    221224                        if (parse_line(configuration, line) != EOK) {
    222225                                fprintf(stderr, "%s: Configuration error on "
    223                                     "line %u: %s\n", NAME, line_number, line);
     226                                    "line %u: %s\n", NAME, line_number, (char *) line);
    224227                        }
    225228                       
     
    282285                return rc;
    283286       
    284         rc = add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME,
    285             SERVICE_LO, 0, connect_to_service);
    286         if (rc != EOK)
    287                 return rc;
    288         rc = add_module(NULL, &net_globals.modules, DP8390_NAME,
    289             DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service);
    290         if (rc != EOK)
    291                 return rc;
    292         rc = add_module(NULL, &net_globals.modules, ETHERNET_NAME,
    293             ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
    294         if (rc != EOK)
    295                 return rc;
    296         rc = add_module(NULL, &net_globals.modules, NILDUMMY_NAME,
    297             NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
     287        rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME,
     288            (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service);
     289        if (rc != EOK)
     290                return rc;
     291       
     292        rc = add_module(NULL, &net_globals.modules, (uint8_t *) NE2000_NAME,
     293            (uint8_t *) NE2000_FILENAME, SERVICE_NE2000, 0, connect_to_service);
     294        if (rc != EOK)
     295                return rc;
     296       
     297        rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
     298            (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
     299        if (rc != EOK)
     300                return rc;
     301       
     302        rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
     303            (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
    298304        if (rc != EOK)
    299305                return rc;
     
    322328static int net_module_start(async_client_conn_t client_connection)
    323329{
    324         sysarg_t phonehash;
    325330        int rc;
    326331       
     
    330335                return rc;
    331336       
    332        
    333337        rc = net_initialize(client_connection);
    334338        if (rc != EOK)
    335339                goto out;
    336340       
    337         rc = ipc_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, &phonehash);
     341        rc = async_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, NULL);
    338342        if (rc != EOK)
    339343                goto out;
     
    364368 */
    365369static int net_get_conf(measured_strings_t *netif_conf,
    366     measured_string_t *configuration, size_t count, char **data)
     370    measured_string_t *configuration, size_t count, uint8_t **data)
    367371{
    368372        if (data)
     
    390394
    391395int net_get_conf_req(int net_phone, measured_string_t **configuration,
    392     size_t count, char **data)
     396    size_t count, uint8_t **data)
    393397{
    394398        if (!configuration || (count <= 0))
     
    399403
    400404int net_get_device_conf_req(int net_phone, device_id_t device_id,
    401     measured_string_t **configuration, size_t count, char **data)
     405    measured_string_t **configuration, size_t count, uint8_t **data)
    402406{
    403407        if ((!configuration) || (count == 0))
     
    411415}
    412416
    413 void net_free_settings(measured_string_t *settings, char *data)
     417void net_free_settings(measured_string_t *settings, uint8_t *data)
    414418{
    415419}
     
    437441        /* Mandatory netif */
    438442        measured_string_t *setting =
    439             measured_strings_find(&netif->configuration, CONF_NETIF, 0);
     443            measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0);
    440444       
    441445        netif->driver = get_running_module(&net_globals.modules, setting->value);
     
    447451       
    448452        /* Optional network interface layer */
    449         setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
     453        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0);
    450454        if (setting) {
    451455                netif->nil = get_running_module(&net_globals.modules, setting->value);
     
    459463       
    460464        /* Mandatory internet layer */
    461         setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
     465        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0);
    462466        netif->il = get_running_module(&net_globals.modules, setting->value);
    463467        if (!netif->il) {
     
    468472       
    469473        /* Hardware configuration */
    470         setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
    471         int irq = setting ? strtol(setting->value, NULL, 10) : 0;
    472        
    473         setting = measured_strings_find(&netif->configuration, CONF_IO, 0);
    474         int io = setting ? strtol(setting->value, NULL, 16) : 0;
    475        
    476         rc = netif_probe_req_remote(netif->driver->phone, netif->id, irq, io);
     474        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0);
     475        int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0;
     476       
     477        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0);
     478        uintptr_t io = setting ? strtol((char *) setting->value, NULL, 16) : 0;
     479       
     480        rc = netif_probe_req(netif->driver->phone, netif->id, irq, (void *) io);
    477481        if (rc != EOK)
    478482                return rc;
     
    481485        services_t internet_service;
    482486        if (netif->nil) {
    483                 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
     487                setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0);
    484488                if (!setting)
    485489                        setting = measured_strings_find(&net_globals.configuration,
    486                             CONF_MTU, 0);
    487                
    488                 int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
     490                            (uint8_t *) CONF_MTU, 0);
     491               
     492                int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0;
    489493               
    490494                rc = nil_device_req(netif->nil->phone, netif->id, mtu,
     
    509513        }
    510514       
    511         return netif_start_req_remote(netif->driver->phone, netif->id);
     515        return netif_start_req(netif->driver->phone, netif->id);
    512516}
    513517
     
    551555                rc = read_netif_configuration(conf_files[i], netif);
    552556                if (rc != EOK) {
    553                         measured_strings_destroy(&netif->configuration);
     557                        measured_strings_destroy(&netif->configuration, free);
    554558                        free(netif);
    555559                        return rc;
     
    558562                /* Mandatory name */
    559563                measured_string_t *setting =
    560                     measured_strings_find(&netif->configuration, CONF_NAME, 0);
     564                    measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0);
    561565                if (!setting) {
    562566                        fprintf(stderr, "%s: Network interface name is missing\n", NAME);
    563                         measured_strings_destroy(&netif->configuration);
     567                        measured_strings_destroy(&netif->configuration, free);
    564568                        free(netif);
    565569                        return EINVAL;
     
    570574                int index = netifs_add(&net_globals.netifs, netif->id, netif);
    571575                if (index < 0) {
    572                         measured_strings_destroy(&netif->configuration);
     576                        measured_strings_destroy(&netif->configuration, free);
    573577                        free(netif);
    574578                        return index;
     
    582586                    index);
    583587                if (rc != EOK) {
    584                         measured_strings_destroy(&netif->configuration);
    585                         netifs_exclude_index(&net_globals.netifs, index);
     588                        measured_strings_destroy(&netif->configuration, free);
     589                        netifs_exclude_index(&net_globals.netifs, index, free);
    586590                        return rc;
    587591                }
     
    589593                rc = start_device(netif);
    590594                if (rc != EOK) {
    591                         measured_strings_destroy(&netif->configuration);
    592                         netifs_exclude_index(&net_globals.netifs, index);
    593                         return rc;
     595                        printf("%s: Ignoring failed interface %s (%s)\n", NAME,
     596                            netif->name, str_error(rc));
     597                        measured_strings_destroy(&netif->configuration, free);
     598                        netifs_exclude_index(&net_globals.netifs, index, free);
     599                        continue;
    594600                }
    595601               
     
    602608                printf("%s: Network interface started (name: %s, id: %d, driver: %s, "
    603609                    "nil: %s, il: %s)\n", NAME, netif->name, netif->id,
    604                     netif->driver->name,  netif->nil ? netif->nil->name : "[none]",
     610                    netif->driver->name, netif->nil ? (char *) netif->nil->name : "[none]",
    605611                    netif->il->name);
    606612        }
     
    611617/** Process the networking message.
    612618 *
    613  * @param[in] callid        The message identifier.
    614  * @param[in] call          The message parameters.
     619 * @param[in]  callid       The message identifier.
     620 * @param[in]  call         The message parameters.
    615621 * @param[out] answer       The message answer parameters.
    616622 * @param[out] answer_count The last parameter for the actual answer
     
    625631 */
    626632int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
    627     int *answer_count)
     633    size_t *answer_count)
    628634{
    629635        measured_string_t *strings;
    630         char *data;
     636        uint8_t *data;
    631637        int rc;
    632638       
     
    637643        case NET_NET_GET_DEVICE_CONF:
    638644                rc = measured_strings_receive(&strings, &data,
    639                     IPC_GET_COUNT(call));
     645                    IPC_GET_COUNT(*call));
    640646                if (rc != EOK)
    641647                        return rc;
    642                 net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings,
    643                     IPC_GET_COUNT(call), NULL);
     648                net_get_device_conf_req(0, IPC_GET_DEVICE(*call), &strings,
     649                    IPC_GET_COUNT(*call), NULL);
    644650               
    645651                /* Strings should not contain received data anymore */
    646652                free(data);
    647653               
    648                 rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
     654                rc = measured_strings_reply(strings, IPC_GET_COUNT(*call));
    649655                free(strings);
    650656                return rc;
    651657        case NET_NET_GET_CONF:
    652658                rc = measured_strings_receive(&strings, &data,
    653                     IPC_GET_COUNT(call));
     659                    IPC_GET_COUNT(*call));
    654660                if (rc != EOK)
    655661                        return rc;
    656                 net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
     662                net_get_conf_req(0, &strings, IPC_GET_COUNT(*call), NULL);
    657663               
    658664                /* Strings should not contain received data anymore */
    659665                free(data);
    660666               
    661                 rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
     667                rc = measured_strings_reply(strings, IPC_GET_COUNT(*call));
    662668                free(strings);
    663669                return rc;
     
    681687         *  - Answer the first IPC_M_CONNECT_ME_TO call.
    682688         */
    683         ipc_answer_0(iid, EOK);
     689        async_answer_0(iid, EOK);
    684690       
    685691        while (true) {
    686692                /* Clear the answer structure */
    687693                ipc_call_t answer;
    688                 int answer_count;
     694                size_t answer_count;
    689695                refresh_answer(&answer, &answer_count);
    690696               
     
    707713int main(int argc, char *argv[])
    708714{
    709         int rc;
    710        
    711         rc = net_module_start(net_client_connection);
    712         if (rc != EOK) {
    713                 fprintf(stderr, "%s: net_module_start error %i\n", NAME, rc);
    714                 return rc;
    715         }
    716        
    717         return EOK;
     715        return net_module_start(net_client_connection);
    718716}
    719717
Note: See TracChangeset for help on using the changeset viewer.