Changes in uspace/app/nic/nic.c [278fede:aa2f865] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nic/nic.c

    r278fede raa2f865  
    4949        nic_cable_state_t link_state;
    5050        nic_channel_mode_t duplex;
     51        nic_unicast_mode_t unicast_mode;
     52        nic_multicast_mode_t multicast_mode;
     53        nic_broadcast_mode_t broadcast_mode;
    5154        int speed;
    5255} nic_info_t;
     
    6063        printf("\taddr <mac_address> - set MAC address\n");
    6164        printf("\tspeed <10|100|1000> - set NIC speed\n");
    62         printf("\tduplex <half|full> - set duplex mode\n");
     65        printf("\tduplex <half|full|simplex> - set duplex mode\n");
     66        printf("\tauto - enable autonegotiation\n");
     67        printf("\tunicast <block|default|list|promisc> - set unicast receive filtering\n");
     68        printf("\tmulticast <block|list|promisc> - set multicast receive filtering\n");
     69        printf("\tbroadcast <block|allow> - block or allow incoming broadcast frames\n");
    6370}
    6471
     
    144151        }
    145152
     153        rc = nic_unicast_get_mode(sess, &info->unicast_mode, 0, NULL, NULL);
     154        if (rc != EOK) {
     155                printf("Error gettinc NIC unicast receive mode.\n");
     156                rc = EIO;
     157                goto error;
     158        }
     159
     160        rc = nic_multicast_get_mode(sess, &info->multicast_mode, 0, NULL, NULL);
     161        if (rc != EOK) {
     162                printf("Error gettinc NIC multicast receive mode.\n");
     163                rc = EIO;
     164                goto error;
     165        }
     166
     167        rc = nic_broadcast_get_mode(sess, &info->broadcast_mode);
     168        if (rc != EOK) {
     169                printf("Error gettinc NIC broadcast receive mode.\n");
     170                rc = EIO;
     171                goto error;
     172        }
    146173
    147174        return EOK;
     
    166193        case NIC_CM_HALF_DUPLEX: return "half-duplex";
    167194        case NIC_CM_SIMPLEX: return "simplex";
     195        default: assert(false); return NULL;
     196        }
     197}
     198
     199static const char *nic_unicast_mode_str(nic_unicast_mode_t mode)
     200{
     201        switch (mode) {
     202        case NIC_UNICAST_UNKNOWN: return "unknown";
     203        case NIC_UNICAST_BLOCKED: return "blocked";
     204        case NIC_UNICAST_DEFAULT: return "default";
     205        case NIC_UNICAST_LIST: return "list";
     206        case NIC_UNICAST_PROMISC: return "promisc";
     207        default: assert(false); return NULL;
     208        }
     209}
     210
     211static const char *nic_multicast_mode_str(nic_unicast_mode_t mode)
     212{
     213        switch (mode) {
     214        case NIC_MULTICAST_UNKNOWN: return "unknown";
     215        case NIC_MULTICAST_BLOCKED: return "blocked";
     216        case NIC_MULTICAST_LIST: return "list";
     217        case NIC_MULTICAST_PROMISC: return "promisc";
     218        default: assert(false); return NULL;
     219        }
     220}
     221
     222static const char *nic_broadcast_mode_str(nic_unicast_mode_t mode)
     223{
     224        switch (mode) {
     225        case NIC_BROADCAST_UNKNOWN: return "unknown";
     226        case NIC_BROADCAST_BLOCKED: return "blocked";
     227        case NIC_BROADCAST_ACCEPTED: return "accepted";
    168228        default: assert(false); return NULL;
    169229        }
     
    206266        }
    207267
    208         printf("[Service Name]\n");
     268        printf("[Index]: [Service Name]\n");
    209269        for (i = 0; i < count; i++) {
    210270                rc = loc_service_get_name(nics[i], &svc_name);
     
    225285                }
    226286
    227                 printf("%d: %s\n", i, svc_name);
     287                printf("%zu: %s\n", i, svc_name);
    228288                printf("\tMAC address: %s\n", addr_str);
    229289                printf("\tVendor name: %s\n",
     
    233293                printf("\tLink state: %s\n",
    234294                    nic_link_state_str(nic_info.link_state));
     295                printf("\tUnicast receive mode: %s\n",
     296                    nic_unicast_mode_str(nic_info.unicast_mode));
     297                printf("\tMulticast receive mode: %s\n",
     298                    nic_multicast_mode_str(nic_info.multicast_mode));
     299                printf("\tBroadcast receive mode: %s\n",
     300                    nic_broadcast_mode_str(nic_info.broadcast_mode));
    235301
    236302                if (nic_info.link_state == NIC_CS_PLUGGED) {
     
    320386
    321387        return nic_set_operation_mode(sess, oldspeed, duplex, oldrole);
     388}
     389
     390static int nic_set_autoneg(int i)
     391{
     392        async_sess_t *sess;
     393        int rc;
     394
     395        sess = get_nic_by_index(i);
     396        if (sess == NULL) {
     397                printf("Specified NIC doesn't exist or cannot connect to it.\n");
     398                return EINVAL;
     399        }
     400
     401        rc = nic_autoneg_restart(sess);
     402        if (rc != EOK) {
     403                printf("Error restarting NIC autonegotiation.\n");
     404                return EIO;
     405        }
     406
     407        return EOK;
    322408}
    323409
     
    348434
    349435        return nic_set_address(sess, &addr);
     436}
     437
     438static int nic_set_rx_unicast(int i, char *str)
     439{
     440        async_sess_t *sess;
     441
     442        sess = get_nic_by_index(i);
     443        if (sess == NULL) {
     444                printf("Specified NIC doesn't exist or cannot connect to it.\n");
     445                return EINVAL;
     446        }
     447
     448        if (!str_cmp(str, "block")) {
     449                nic_unicast_set_mode(sess, NIC_UNICAST_BLOCKED, NULL, 0);
     450                return EOK;
     451        }
     452
     453        if (!str_cmp(str, "default")) {
     454                nic_unicast_set_mode(sess, NIC_UNICAST_DEFAULT, NULL, 0);
     455                return EOK;
     456        }
     457
     458        if (!str_cmp(str, "list")) {
     459                nic_unicast_set_mode(sess, NIC_UNICAST_LIST, NULL, 0);
     460                return EOK;
     461        }
     462
     463        if (!str_cmp(str, "promisc")) {
     464                nic_unicast_set_mode(sess, NIC_UNICAST_PROMISC, NULL, 0);
     465                return EOK;
     466        }
     467
     468
     469        printf("Invalid pameter - should be one of: block, default, promisc\n");
     470        return EINVAL;
     471}
     472
     473static int nic_set_rx_multicast(int i, char *str)
     474{
     475        async_sess_t *sess;
     476
     477        sess = get_nic_by_index(i);
     478        if (sess == NULL) {
     479                printf("Specified NIC doesn't exist or cannot connect to it.\n");
     480                return EINVAL;
     481        }
     482
     483        if (!str_cmp(str, "block")) {
     484                nic_multicast_set_mode(sess, NIC_MULTICAST_BLOCKED, NULL, 0);
     485                return EOK;
     486        }
     487
     488        if (!str_cmp(str, "list")) {
     489                nic_multicast_set_mode(sess, NIC_MULTICAST_LIST, NULL, 0);
     490                return EOK;
     491        }
     492
     493        if (!str_cmp(str, "promisc")) {
     494                nic_multicast_set_mode(sess, NIC_MULTICAST_PROMISC, NULL, 0);
     495                return EOK;
     496        }
     497
     498        printf("Invalid pameter - should be one of: block, promisc\n");
     499        return EINVAL;
     500}
     501
     502static int nic_set_rx_broadcast(int i, char *str)
     503{
     504        async_sess_t *sess;
     505
     506        sess = get_nic_by_index(i);
     507        if (sess == NULL) {
     508                printf("Specified NIC doesn't exist or cannot connect to it.\n");
     509                return EINVAL;
     510        }
     511
     512        if (!str_cmp(str, "block")) {
     513                nic_broadcast_set_mode(sess, NIC_BROADCAST_BLOCKED);
     514                return EOK;
     515        }
     516
     517        if (!str_cmp(str, "accept")) {
     518                nic_broadcast_set_mode(sess, NIC_BROADCAST_ACCEPTED);
     519                return EOK;
     520        }
     521
     522        printf("Invalid pameter - should be 'block' or 'accept'\n");
     523        return EINVAL;
    350524}
    351525
     
    376550                        return nic_set_duplex(index, argv[3]);
    377551
     552                if (!str_cmp(argv[2], "auto"))
     553                        return nic_set_autoneg(index);
     554
     555                if (!str_cmp(argv[2], "unicast"))
     556                        return nic_set_rx_unicast(index, argv[3]);
     557
     558                if (!str_cmp(argv[2], "multicast"))
     559                        return nic_set_rx_multicast(index, argv[3]);
     560
     561                if (!str_cmp(argv[2], "broadcast"))
     562                        return nic_set_rx_broadcast(index, argv[3]);
     563
    378564        } else {
    379565                printf(NAME ": Invalid argument.\n");
Note: See TracChangeset for help on using the changeset viewer.