Exemplo n.º 1
0
static int _get(netdev2_t *dev, netopt_t opt, void *value, size_t value_len)
{
    cc110x_t *cc110x = &((netdev2_cc110x_t*) dev)->cc110x;

    switch (opt) {
        case NETOPT_DEVICE_TYPE:
            assert(value_len == 2);
            *((uint16_t *) value) = NETDEV2_TYPE_CC110X;
            return 2;
        case NETOPT_PROTO:
            assert(value_len == sizeof(gnrc_nettype_t));
            *((gnrc_nettype_t *)value) = cc110x->proto;
            return sizeof(gnrc_nettype_t);
        case NETOPT_CHANNEL:
            assert(value_len > 1);
            *((uint16_t *)value) = (uint16_t)cc110x->radio_channel;
            return 2;
        case NETOPT_ADDRESS:
            assert(value_len > 0);
            *((uint8_t *)value) = cc110x->radio_address;
            return 1;
        case NETOPT_MAX_PACKET_SIZE:
            assert(value_len > 0);
            *((uint8_t *)value) = CC110X_PACKET_LENGTH;
            return 1;
        case NETOPT_IPV6_IID:
            return _get_iid(dev, value, value_len);
        default:
            break;
    }

    return -ENOTSUP;
}
Exemplo n.º 2
0
static int _get(ng_netdev_t *dev, netopt_t opt, void *value, size_t max_len)
{
    DEBUG("ng_netdev_eth: get ");

    if ((dev == NULL) || (dev->driver != &ng_netdev_eth_driver)) {
        DEBUG("[wrong device descriptor]\n");
        return -ENODEV;
    }

    switch (opt) {
        case NETOPT_ADDRESS:
            DEBUG("address\n");
            return _get_addr((ng_netdev_eth_t *)dev, value, max_len);

        case NETOPT_ADDR_LEN:
            DEBUG("address length\n");
            return _get_addr_len(value, max_len);

        case NETOPT_IPV6_IID:
            DEBUG("IPv6 IID\n");
            return _get_iid((ng_netdev_eth_t *)dev, value, max_len);

        case NETOPT_MAX_PACKET_SIZE:
            DEBUG("maximum packet size\n");
            return _get_max_pkt_sz(value, max_len);

        case NETOPT_PROMISCUOUSMODE:
            DEBUG("promiscous mode\n");
            return _get_promiscousmode((ng_netdev_eth_t *)dev, value, max_len);

        default:
            DEBUG("[not supported: %d]\n", opt);
            return -ENOTSUP;
    }
}
Exemplo n.º 3
0
static int _get_ipv6_iid(netdev_t *dev, void *value, size_t max_len)
{
    (void)dev;
    if (max_len != sizeof(uint64_t)) {
        return -EOVERFLOW;
    }
    _get_iid(value);
    return sizeof(uint64_t);
}
Exemplo n.º 4
0
int _get(netdev2_t *dev, netopt_t opt, void *value, size_t max_len)
{
    if (dev != (netdev2_t *)&netdev2_tap) {
        return -ENODEV;
    }

    int res = 0;

    switch (opt) {
        case NETOPT_DEVICE_TYPE:
            {
               uint16_t *tgt = (uint16_t *)value;
                *tgt = NETDEV2_TYPE_ETHERNET;
                res = 2;
                break;
            }
        case NETOPT_ADDRESS:
            if (max_len < ETHERNET_ADDR_LEN) {
                res = -EINVAL;
            }
            else {
                _get_mac_addr(dev, (uint8_t*)value);
                res = ETHERNET_ADDR_LEN;
            }
            break;
        case NETOPT_ADDR_LEN:
        case NETOPT_SRC_LEN:
            assert(max_len == 2);
            uint16_t *tgt = (uint16_t*)value;
            *tgt=6;
            res = sizeof(uint16_t);
            break;
        case NETOPT_PROMISCUOUSMODE:
            *((bool*)value) = (bool)_get_promiscous(dev);
            res = sizeof(bool);
            break;
        case NETOPT_IPV6_IID:
            return _get_iid(dev, value, max_len);
        case NETOPT_IS_WIRED:
            res = 1;
            break;
        default:
            res = -ENOTSUP;
            break;
    }

    return res;
}
Exemplo n.º 5
0
int netdev2_eth_get(netdev2_t *dev, netopt_t opt, void *value, size_t max_len)
{
    int res = 0;

    switch (opt) {
        case NETOPT_DEVICE_TYPE:
            {
                uint16_t *tgt = (uint16_t *)value;
                *tgt = NETDEV2_TYPE_ETHERNET;
                res = 2;
                break;
            }
        case NETOPT_ADDR_LEN:
        case NETOPT_SRC_LEN:
            {
                assert(max_len == 2);
                uint16_t *tgt = (uint16_t*)value;
                *tgt=6;
                res = sizeof(uint16_t);
                break;
            }
        case NETOPT_MAX_PACKET_SIZE:
            {
                assert(max_len >= 2);
                uint16_t *val = (uint16_t*) value;
                *val = ETHERNET_DATA_LEN;
                res = sizeof(uint16_t);
                break;
            }
        case NETOPT_IS_WIRED:
            {
                res = 1;
                break;
            }
        case NETOPT_IPV6_IID:
            {
                return _get_iid(dev, value, max_len);
            }
        default:
            {
                res = -ENOTSUP;
                break;
            }
    }

    return res;
}
Exemplo n.º 6
0
static int _get_addr(netdev_t *dev, void *value, size_t max_len)
{
    uint8_t iid[ETHERNET_ADDR_LEN + 2];
    uint8_t *addr = value;

    (void)dev;
    if (max_len < ETHERNET_ADDR_LEN) {
        return -EOVERFLOW;
    }

    _get_iid(iid);

    addr[0] = iid[0];
    addr[1] = iid[1];
    addr[2] = iid[2];
    addr[3] = iid[5];
    addr[4] = iid[6];
    addr[5] = iid[7];

    return ETHERNET_ADDR_LEN;
}
Exemplo n.º 7
0
int netdev2_ieee802154_get(netdev2_ieee802154_t *dev, netopt_t opt, void *value,
                           size_t max_len)
{
    int res = -ENOTSUP;

    switch (opt) {
        case NETOPT_ADDRESS:
            assert(max_len >= sizeof(dev->short_addr));
            memcpy(value, dev->short_addr, sizeof(dev->short_addr));
            res = sizeof(dev->short_addr);
            break;
        case NETOPT_ADDRESS_LONG:
            assert(max_len >= sizeof(dev->long_addr));
            memcpy(value, dev->long_addr, sizeof(dev->long_addr));
            res = sizeof(dev->long_addr);
            break;
        case NETOPT_ADDR_LEN:
        case NETOPT_SRC_LEN:
            assert(max_len == sizeof(uint16_t));
            if (dev->flags & NETDEV2_IEEE802154_SRC_MODE_LONG) {
                *((uint16_t *)value) = IEEE802154_LONG_ADDRESS_LEN;
            }
            else {
                *((uint16_t *)value) = IEEE802154_SHORT_ADDRESS_LEN;
            }
            res = sizeof(uint16_t);
            break;
        case NETOPT_NID:
            assert(max_len == sizeof(dev->pan));
            *((uint16_t *)value) = dev->pan;
            res = sizeof(dev->pan);
            break;
        case NETOPT_CHANNEL:
            assert(max_len == sizeof(uint16_t));
            *((uint16_t *)value) = (uint16_t)dev->chan;
            res = sizeof(dev->chan);
            break;
        case NETOPT_AUTOACK:
            assert(max_len == sizeof(netopt_enable_t));
            if (dev->flags & NETDEV2_IEEE802154_ACK_REQ) {
                *((netopt_enable_t *)value) = NETOPT_ENABLE;
            }
            else {
                *((netopt_enable_t *)value) = NETOPT_DISABLE;
            }
            res = sizeof(netopt_enable_t);
            break;
        case NETOPT_RAWMODE:
            assert(max_len == sizeof(netopt_enable_t));
            if (dev->flags & NETDEV2_IEEE802154_RAW) {
                *((netopt_enable_t *)value) = NETOPT_ENABLE;
            }
            else {
                *((netopt_enable_t *)value) = NETOPT_DISABLE;
            }
            res = sizeof(netopt_enable_t);
            break;
#ifdef MODULE_GNRC
        case NETOPT_PROTO:
            assert(max_len == sizeof(gnrc_nettype_t));
            *((gnrc_nettype_t *)value) = dev->proto;
            res = sizeof(gnrc_nettype_t);
            break;
#endif
        case NETOPT_DEVICE_TYPE:
            assert(max_len == sizeof(uint16_t));
            *((uint16_t *)value) = NETDEV2_TYPE_IEEE802154;
            res = sizeof(uint16_t);
            break;
        case NETOPT_IPV6_IID:
            res = _get_iid(dev, value, max_len);
            break;
#ifdef MODULE_NETSTATS_L2
        case NETOPT_STATS:
            assert(max_len == sizeof(uintptr_t));
            *((netstats_t **)value) = &dev->netdev.stats;
            res = sizeof(uintptr_t);
            break;
#endif
        default:
            break;
    }
    return res;
}
Exemplo n.º 8
0
static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
{
    DEBUG("%s: %s %p %p %u\n", __func__, netopt2str(opt), netdev, val, max_len);

    CHECK_PARAM_RET (netdev != NULL, -ENODEV);
    CHECK_PARAM_RET (val != NULL, -EINVAL);

    esp_now_netdev_t *dev = (esp_now_netdev_t *)netdev;
    int res = -ENOTSUP;

    switch (opt) {

        case NETOPT_DEVICE_TYPE:
            CHECK_PARAM_RET (max_len >= sizeof(uint16_t), -EOVERFLOW);
            *((uint16_t *)val) = NETDEV_TYPE_ESP_NOW;
            res = sizeof(uint16_t);
            break;

        #ifdef MODULE_GNRC
        case NETOPT_PROTO:
            CHECK_PARAM_RET(max_len == sizeof(gnrc_nettype_t), -EOVERFLOW);
            *((gnrc_nettype_t *)val) = dev->proto;
            res = sizeof(gnrc_nettype_t);
            break;
        #endif

        case NETOPT_MAX_PACKET_SIZE:
            CHECK_PARAM_RET (max_len >= sizeof(uint16_t), -EOVERFLOW);
            *((uint16_t *)val) = ESP_NOW_MAX_SIZE;
            res = sizeof(uint16_t);
            break;

        case NETOPT_ADDR_LEN:
        case NETOPT_SRC_LEN:
            CHECK_PARAM_RET (max_len >= sizeof(uint16_t), -EOVERFLOW);
            *((uint16_t *)val) = sizeof(dev->addr);
            res = sizeof(uint16_t);
            break;

        case NETOPT_ADDRESS:
            CHECK_PARAM_RET (max_len >= sizeof(dev->addr), -EOVERFLOW);
            memcpy(val, dev->addr, sizeof(dev->addr));
            res = sizeof(dev->addr);
            break;

        case NETOPT_IPV6_IID:
            res = _get_iid(dev, val, max_len);
            break;

        #ifdef MODULE_NETSTATS_L2
        case NETOPT_STATS:
            CHECK_PARAM_RET (max_len == sizeof(uintptr_t), -EOVERFLOW);
            *((netstats_t **)val) = &netdev->stats;
            res = sizeof(uintptr_t);
            break;
        #endif

        default:
            DEBUG("%s: %s not supported\n", __func__, netopt2str(opt));
            break;
    }
    return res;
}
Exemplo n.º 9
0
int netdev_eth_get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
{
    int res = 0;

    switch (opt) {
        case NETOPT_DEVICE_TYPE:
            {
                uint16_t *tgt = (uint16_t *)value;
                *tgt = NETDEV_TYPE_ETHERNET;
                res = 2;
                break;
            }
        case NETOPT_ADDR_LEN:
        case NETOPT_SRC_LEN:
            {
                assert(max_len == 2);
                uint16_t *tgt = (uint16_t*)value;
                *tgt=6;
                res = sizeof(uint16_t);
                break;
            }
        case NETOPT_MAX_PACKET_SIZE:
            {
                assert(max_len >= 2);
                uint16_t *val = (uint16_t*) value;
                *val = ETHERNET_DATA_LEN;
                res = sizeof(uint16_t);
                break;
            }
        case NETOPT_IS_WIRED:
            {
                res = 1;
                break;
            }
        case NETOPT_IPV6_IID:
            {
                return _get_iid(dev, value, max_len);
            }
#ifdef MODULE_NETSTATS_L2
        case NETOPT_STATS:
            {
                assert(max_len >= sizeof(uintptr_t));
                *((netstats_t**)value) = &dev->stats;
                res = sizeof(uintptr_t);
                break;
            }
#endif
#ifdef MODULE_L2FILTER
        case NETOPT_L2FILTER:
            {
                assert(max_len >= sizeof(l2filter_t **));
                *((l2filter_t **)value) = dev->filter;
                res = sizeof(l2filter_t **);
                break;
            }
#endif
        default:
            {
                res = -ENOTSUP;
                break;
            }
    }

    return res;
}