Ignore:
File:
1 edited

Legend:

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

    r00d7e1b r77a69ea  
    4141#include <stdio.h>
    4242#include <str.h>
    43 #include <devman.h>
    4443#include <str_error.h>
    4544#include <ns.h>
     
    5655#include <adt/measured_strings.h>
    5756#include <adt/module_map.h>
     57#include <loc.h>
     58#include <nic.h>
    5859#include <nil_remote.h>
    5960#include <net_interface.h>
     
    7374GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
    7475DEVICE_MAP_IMPLEMENT(netifs, netif_t);
     76LIST_INITIALIZE(netif_list);
    7577
    7678/** Add the configured setting to the configuration map.
     
    287289 *
    288290 */
    289 static int init_device(netif_t *netif, devman_handle_t handle)
     291static int init_device(netif_t *netif, service_id_t sid)
    290292{
    291293        printf("%s: Initializing device '%s'\n", NAME, netif->name);
    292294       
    293         netif->handle = handle;
    294         netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle,
     295        link_initialize(&netif->netif_list);
     296       
     297        netif->sid = sid;
     298        netif->sess = loc_service_connect(EXCHANGE_SERIALIZE, netif->sid,
    295299            IPC_FLAG_BLOCKING);
    296300        if (netif->sess == NULL) {
     
    337341                    strtol((const char *) setting->value, NULL, 10) : 0;
    338342                rc = nil_device_req(netif->nil->sess, netif->id,
    339                     netif->handle, mtu);
     343                    netif->sid, mtu);
    340344                if (rc != EOK) {
    341345                        printf("%s: Unable to start network interface layer\n",
     
    363367       
    364368        printf("%s: Activating device '%s'\n", NAME, netif->name);
     369        list_append(&netif->netif_list, &netif_list);
    365370        return nic_set_state(netif->sess, NIC_STATE_ACTIVE);
    366371}
    367372
    368 static int net_port_ready(devman_handle_t handle)
    369 {
    370         char hwpath[MAX_PATH_LENGTH];
    371         int rc = devman_fun_get_path(handle, hwpath, MAX_PATH_LENGTH);
    372         if (rc != EOK)
     373static int net_nic_ready(service_id_t sid)
     374{
     375        int rc;
     376        char *hwpath;
     377       
     378        rc = loc_service_get_name(sid, &hwpath);
     379        if (rc != EOK) {
     380                printf("%s: Failed getting name of service '%u'\n",
     381                    NAME, (unsigned) sid);
    373382                return EINVAL;
     383        }
    374384       
    375385        int index = char_map_find(&net_globals.netif_hwpaths,
    376386            (uint8_t *) hwpath, 0);
    377         if (index == CHAR_MAP_NULL)
     387       
     388        if (index == CHAR_MAP_NULL) {
     389                printf("%s: Service '%s' not found in map.\n", NAME, hwpath);
     390                free(hwpath);
    378391                return ENOENT;
     392        }
     393       
     394        free(hwpath);
    379395       
    380396        netif_t *netif = netifs_get_index(&net_globals.netifs, index);
     
    382398                return ENOENT;
    383399       
    384         rc = init_device(netif, handle);
     400        rc = init_device(netif, sid);
    385401        if (rc != EOK)
    386402                return rc;
     
    391407       
    392408        netif->il->usage++;
    393        
    394         return EOK;
    395 }
    396 
    397 static int net_driver_ready_local(devman_handle_t handle)
    398 {
    399         devman_handle_t *funs;
    400         size_t count;
    401         int rc = devman_dev_get_functions(handle, &funs, &count);
    402         if (rc != EOK)
    403                 return rc;
    404        
    405         for (size_t i = 0; i < count; i++) {
    406                 rc = net_port_ready(funs[i]);
    407                 if (rc != EOK)
    408                         return rc;
    409         }
    410409       
    411410        return EOK;
     
    479478                net_free_devices(strings, count);
    480479                return rc;
    481         case NET_NET_DRIVER_READY:
    482                 rc = net_driver_ready_local(IPC_GET_ARG1(*call));
    483                 *answer_count = 0;
    484                 return rc;
    485480        default:
    486481                return ENOTSUP;
     
    528523                answer_call(callid, res, &answer, count);
    529524        }
     525}
     526
     527static int nic_check_new(void)
     528{
     529        category_id_t nic_cat;
     530        service_id_t *svcs;
     531        size_t count, i;
     532        bool already_known;
     533        int rc;
     534
     535        rc = loc_category_get_id(DEVICE_CATEGORY_NIC, &nic_cat, IPC_FLAG_BLOCKING);
     536        if (rc != EOK) {
     537                printf("%s: Failed resolving category '%s'.\n", NAME,
     538                    DEVICE_CATEGORY_NIC);
     539                return ENOENT;
     540        }
     541
     542        rc = loc_category_get_svcs(nic_cat, &svcs, &count);
     543        if (rc != EOK) {
     544                printf("%s: Failed getting list of NIC devices.\n", NAME);
     545                return EIO;
     546        }
     547
     548        for (i = 0; i < count; i++) {
     549                already_known = false;
     550
     551                list_foreach(netif_list, link) {
     552                        netif_t *netif = list_get_instance(link, netif_t, netif_list);
     553                        if (netif->sid == svcs[i]) {
     554                                already_known = true;
     555                                break;
     556                        }
     557                }
     558
     559                if (!already_known) {
     560                        rc = net_nic_ready(svcs[i]);
     561                        if (rc != EOK) {
     562                                printf("%s: Failed adding NIC device #%u.\n",
     563                                    NAME, (unsigned) svcs[i]);
     564                        }
     565                }
     566        }
     567
     568        free(svcs);
     569        return EOK;
     570}
     571
     572static void cat_change_cb(void)
     573{
     574        (void) nic_check_new();
     575}
     576
     577static int net_start_nic_discovery(void)
     578{
     579        int rc;
     580
     581        rc = loc_register_cat_change_cb(cat_change_cb);
     582        if (rc != EOK) {
     583                printf("%s: Failed registering callback for device discovery (%d).\n",
     584                    NAME, rc);
     585                return rc;
     586        }
     587
     588        return nic_check_new();
    530589}
    531590
     
    573632                                continue;
    574633                       
    575                         netif->handle = -1;
     634                        netif->sid = -1;
    576635                        netif->sess = NULL;
    577636                       
     
    697756        }
    698757       
     758        rc = net_start_nic_discovery();
     759        if (rc != EOK) {
     760                printf("%s: Error starting NIC discovery\n", NAME);
     761                pm_destroy();
     762                return rc;
     763        }
     764       
    699765        task_retval(0);
    700766        async_manager();
Note: See TracChangeset for help on using the changeset viewer.