Changeset aa2f865 in mainline for uspace/app/nic/nic.c


Ignore:
Timestamp:
2014-08-18T14:08:40Z (10 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
320bd52
Parents:
2ff9876
Message:

Add switches allowing to get or modify unicast, multicast or broadcast
receive filters.

File:
1 edited

Legend:

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

    r2ff9876 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;
     
    6265        printf("\tduplex <half|full|simplex> - set duplex mode\n");
    6366        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");
    6470}
    6571
     
    145151        }
    146152
     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        }
    147173
    148174        return EOK;
     
    167193        case NIC_CM_HALF_DUPLEX: return "half-duplex";
    168194        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";
    169228        default: assert(false); return NULL;
    170229        }
     
    234293                printf("\tLink state: %s\n",
    235294                    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));
    236301
    237302                if (nic_info.link_state == NIC_CS_PLUGGED) {
     
    369434
    370435        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;
    371524}
    372525
     
    400553                        return nic_set_autoneg(index);
    401554
     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
    402564        } else {
    403565                printf(NAME ": Invalid argument.\n");
Note: See TracChangeset for help on using the changeset viewer.