Changeset 357b5f5 in mainline for uspace/srv/net/net/net.c


Ignore:
Timestamp:
2011-01-23T20:09:13Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fdb9982c
Parents:
cead2aa (diff), 7e36c8d (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

    rcead2aa r357b5f5  
    4545#include <stdio.h>
    4646#include <str.h>
     47#include <str_error.h>
    4748
    4849#include <ipc/ipc.h>
     
    5152#include <ipc/net_net.h>
    5253#include <ipc/il.h>
     54#include <ipc/nil.h>
    5355
    5456#include <net/modules.h>
     
    6264
    6365#include <netif_remote.h>
    64 #include <nil_interface.h>
     66#include <nil_remote.h>
    6567#include <net_interface.h>
    6668#include <ip_interface.h>
     
    9092 *
    9193 */
    92 int add_configuration(measured_strings_t *configuration, const char *name,
    93     const char *value)
     94int add_configuration(measured_strings_t *configuration, const uint8_t *name,
     95    const uint8_t *value)
    9496{
    9597        int rc;
     
    119121}
    120122
    121 static int parse_line(measured_strings_t *configuration, char *line)
     123static int parse_line(measured_strings_t *configuration, uint8_t *line)
    122124{
    123125        int rc;
    124126       
    125127        /* From the beginning */
    126         char *name = line;
     128        uint8_t *name = line;
    127129       
    128130        /* Skip comments and blank lines */
     
    135137       
    136138        /* Remember the name start */
    137         char *value = name;
     139        uint8_t *value = name;
    138140       
    139141        /* Skip the name */
     
    186188       
    187189        /* Construct the full filename */
    188         char line[BUFFER_SIZE];
    189         if (snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
     190        char fname[BUFFER_SIZE];
     191        if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
    190192                return EOVERFLOW;
    191193       
    192194        /* Open the file */
    193         FILE *cfg = fopen(line, "r");
     195        FILE *cfg = fopen(fname, "r");
    194196        if (!cfg)
    195197                return ENOENT;
     
    201203        unsigned int line_number = 0;
    202204        size_t index = 0;
     205        uint8_t line[BUFFER_SIZE];
     206       
    203207        while (!ferror(cfg) && !feof(cfg)) {
    204208                int read = fgetc(cfg);
     
    207211                                line[BUFFER_SIZE - 1] = '\0';
    208212                                fprintf(stderr, "%s: Configuration line %u too "
    209                                     "long: %s\n", NAME, line_number, line);
     213                                    "long: %s\n", NAME, line_number, (char *) line);
    210214                               
    211215                                /* No space left in the line buffer */
     
    213217                        }
    214218                        /* Append the character */
    215                         line[index] = (char) read;
     219                        line[index] = (uint8_t) read;
    216220                        index++;
    217221                } else {
     
    221225                        if (parse_line(configuration, line) != EOK) {
    222226                                fprintf(stderr, "%s: Configuration error on "
    223                                     "line %u: %s\n", NAME, line_number, line);
     227                                    "line %u: %s\n", NAME, line_number, (char *) line);
    224228                        }
    225229                       
     
    282286                return rc;
    283287       
    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);
     288        rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME,
     289            (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service);
     290        if (rc != EOK)
     291                return rc;
     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        rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
     297            (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
     298        if (rc != EOK)
     299                return rc;
     300        rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
     301            (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
    298302        if (rc != EOK)
    299303                return rc;
     
    322326static int net_module_start(async_client_conn_t client_connection)
    323327{
    324         ipcarg_t phonehash;
     328        sysarg_t phonehash;
    325329        int rc;
    326330       
     
    330334                return rc;
    331335       
    332        
    333336        rc = net_initialize(client_connection);
    334337        if (rc != EOK)
    335338                goto out;
    336339       
    337         rc = REGISTER_ME(SERVICE_NETWORKING, &phonehash);
     340        rc = ipc_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, &phonehash);
    338341        if (rc != EOK)
    339342                goto out;
     
    364367 */
    365368static int net_get_conf(measured_strings_t *netif_conf,
    366     measured_string_t *configuration, size_t count, char **data)
     369    measured_string_t *configuration, size_t count, uint8_t **data)
    367370{
    368371        if (data)
     
    390393
    391394int net_get_conf_req(int net_phone, measured_string_t **configuration,
    392     size_t count, char **data)
     395    size_t count, uint8_t **data)
    393396{
    394397        if (!configuration || (count <= 0))
     
    399402
    400403int net_get_device_conf_req(int net_phone, device_id_t device_id,
    401     measured_string_t **configuration, size_t count, char **data)
     404    measured_string_t **configuration, size_t count, uint8_t **data)
    402405{
    403406        if ((!configuration) || (count == 0))
     
    411414}
    412415
    413 void net_free_settings(measured_string_t *settings, char *data)
     416void net_free_settings(measured_string_t *settings, uint8_t *data)
    414417{
    415418}
     
    437440        /* Mandatory netif */
    438441        measured_string_t *setting =
    439             measured_strings_find(&netif->configuration, CONF_NETIF, 0);
     442            measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0);
    440443       
    441444        netif->driver = get_running_module(&net_globals.modules, setting->value);
     
    447450       
    448451        /* Optional network interface layer */
    449         setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
     452        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0);
    450453        if (setting) {
    451454                netif->nil = get_running_module(&net_globals.modules, setting->value);
     
    459462       
    460463        /* Mandatory internet layer */
    461         setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
     464        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0);
    462465        netif->il = get_running_module(&net_globals.modules, setting->value);
    463466        if (!netif->il) {
     
    468471       
    469472        /* 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);
     473        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0);
     474        int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0;
     475       
     476        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0);
     477        uintptr_t io = setting ? strtol((char *) setting->value, NULL, 16) : 0;
     478       
     479        rc = netif_probe_req(netif->driver->phone, netif->id, irq, (void *) io);
    477480        if (rc != EOK)
    478481                return rc;
     
    481484        services_t internet_service;
    482485        if (netif->nil) {
    483                 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
     486                setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0);
    484487                if (!setting)
    485488                        setting = measured_strings_find(&net_globals.configuration,
    486                             CONF_MTU, 0);
    487                
    488                 int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
     489                            (uint8_t *) CONF_MTU, 0);
     490               
     491                int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0;
    489492               
    490493                rc = nil_device_req(netif->nil->phone, netif->id, mtu,
     
    509512        }
    510513       
    511         return netif_start_req_remote(netif->driver->phone, netif->id);
     514        return netif_start_req(netif->driver->phone, netif->id);
    512515}
    513516
     
    558561                /* Mandatory name */
    559562                measured_string_t *setting =
    560                     measured_strings_find(&netif->configuration, CONF_NAME, 0);
     563                    measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0);
    561564                if (!setting) {
    562565                        fprintf(stderr, "%s: Network interface name is missing\n", NAME);
     
    589592                rc = start_device(netif);
    590593                if (rc != EOK) {
     594                        printf("%s: Error starting interface %s (%s)\n", NAME,
     595                            netif->name, str_error(rc));
    591596                        measured_strings_destroy(&netif->configuration);
    592597                        netifs_exclude_index(&net_globals.netifs, index);
     598                       
    593599                        return rc;
    594600                }
     
    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       
    633639        *answer_count = 0;
    634         switch (IPC_GET_METHOD(*call)) {
     640        switch (IPC_GET_IMETHOD(*call)) {
    635641        case IPC_M_PHONE_HUNGUP:
    636642                return EOK;
    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;
     
    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               
     
    697703               
    698704                /* End if told to either by the message or the processing result */
    699                 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     705                if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
    700706                        return;
    701707               
     
    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.