Esempio n. 1
0
static int _set(netdev_t *netdev, netopt_t opt, const 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) {

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

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

        default:
            DEBUG("%s: %s not supported\n", __func__, netopt2str(opt));
            break;
    }
    return res;
}
Esempio n. 2
0
void ItemList::remove(Item* item) {
	CHECK_PARAM_RET(item != NULL);
	CHECK_PARAM_RET(contains(item));

	m_items.remove(item);
	m_map.remove(item->itemId());
	emit itemRemoved(item->itemId());
}
Esempio n. 3
0
void ItemList::add(Item* item) {
	CHECK_PARAM_RET(item != NULL);
	CHECK_PARAM_RET(!contains(item));
	CHECK_PARAM_RET(!contains(item->itemId()));
	//CHECK_PARAM_RET(item->parent() == m_proj);

	m_items.insert(item);
	m_map.insert(item->itemId(), item);
	emit itemAdded(item->itemId());
}
Esempio n. 4
0
void Server::add(const QVariantMap& entry) {
	CHECK_PARAM_RET(entry.contains(KEY));
	const QString& sKey = entry.value(KEY).toString();
	CHECK_PARAM_RET(!sKey.isEmpty());

	m_database.insert(sKey, entry);

	qDebug() << "database:";
	qDebug() << m_database;

	emit entryAdded(entry);
}
Esempio n. 5
0
static inline int _get_mac_from_iid(uint8_t *iid, uint8_t *mac)
{
    CHECK_PARAM_RET (iid != NULL, -EINVAL);
    CHECK_PARAM_RET (mac != NULL, -EINVAL);

    /* interface id according to */
    /* https://tools.ietf.org/html/rfc4291#section-2.5.1 */
    mac[0] = iid[0] ^ 0x02; /* invert bit1 */
    mac[1] = iid[1];
    mac[2] = iid[2];
    mac[3] = iid[5];
    mac[4] = iid[6];
    mac[5] = iid[7];

    return 0;
}
Esempio n. 6
0
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
{
    DEBUG("%s: %p %p %u %p\n", __func__, netdev, buf, len, info);

    CHECK_PARAM_RET (netdev != NULL, -ENODEV);

    esp_now_netdev_t* dev = (esp_now_netdev_t*)netdev;

    mutex_lock(&dev->dev_lock);

    uint8_t size = dev->rx_len;

    if (!buf && !len) {
        /* return the size without dropping received data */
        mutex_unlock(&dev->dev_lock);
        return size;
    }

    if (!buf && len) {
        /* return the size and drop received data */
        mutex_unlock(&dev->dev_lock);
        dev->rx_len = 0;
        return size;
    }

    if (buf && len && dev->rx_len) {
        if (dev->rx_len > len) {
            DEBUG("[esp_now] No space in receive buffers\n");
            mutex_unlock(&dev->dev_lock);
            return -ENOBUFS;
        }

        #if ENABLE_DEBUG
        printf ("%s: received %d byte from %02x:%02x:%02x:%02x:%02x:%02x\n",
                __func__, dev->rx_len,
                dev->rx_mac[0], dev->rx_mac[1], dev->rx_mac[2],
                dev->rx_mac[3], dev->rx_mac[4], dev->rx_mac[5]);
        /* esp_hexdump (dev->rx_buf, dev->rx_len, 'b', 16); */
        #endif

        if (esp_now_is_peer_exist(dev->rx_mac) <= 0) {
            _esp_now_add_peer(dev->rx_mac, esp_now_params.channel, esp_now_params.key);
        }

        memcpy(buf, dev->rx_buf, dev->rx_len);
        dev->rx_len = 0;

        #ifdef MODULE_NETSTATS_L2
        netdev->stats.rx_count++;
        netdev->stats.rx_bytes += size;
        #endif

        mutex_unlock(&dev->dev_lock);
        return size;
    }

    mutex_unlock(&dev->dev_lock);
    return -EINVAL;
}
Esempio n. 7
0
WaveProxy::WaveProxy(Project* proj, WaveData* data, QObject *parent) :
	QObject(parent), proj(proj), data(data)
{
	CHECK_PARAM_RET(proj != NULL)
	CHECK_PARAM_RET(data != NULL)

	#define C(name) connect(data, SIGNAL(name##Changed()), this, SIGNAL(name##Changed()))
	C(id);
	C(recId);
	C(typeId);
	C(name);
	C(comment);
	C(source);
	C(time);
	C(rate);
	C(offset);
	C(sensitivity);
	C(shift);
}
Esempio n. 8
0
SpiFlashOpResult IRAM spi_flash_write (uint32_t faddr, uint32_t *src, size_t size)
{
    /*
     * For simplicity, we use the ROM function. Since we need to disable the
     * IROM cache function for that purpose, we have to be in IRAM.
     * Please note, faddr, src and size have to be aligned to 4 byte
     */

    SpiFlashOpResult ret;

    CHECK_PARAM_RET (src != NULL, SPI_FLASH_RESULT_ERR);
    CHECK_PARAM_RET (faddr + size <= flashchip->chip_size, SPI_FLASH_RESULT_ERR);

    critical_enter ();
    Cache_Read_Disable ();

    ret = SPIWrite (faddr, src, size);

    Cache_Read_Enable(0, 0, 1);
    critical_exit ();

    return ret;
}
Esempio n. 9
0
SpiFlashOpResult IRAM spi_flash_erase_sector(uint16_t sec)
{
    CHECK_PARAM_RET (sec < flashchip->chip_size / flashchip->sector_size, SPI_FLASH_RESULT_ERR);

    critical_enter ();
    Cache_Read_Disable();

    SpiFlashOpResult ret = SPIEraseSector (sec);

    Cache_Read_Enable(0, 0, 1);
    critical_exit ();

    return ret;
}
Esempio n. 10
0
void IdacDriverES::loadCaps(IdacCaps* caps)
{
    CHECK_PARAM_RET(caps != NULL);

    caps->bHighcut = IdacCapabilities(IDAC_HAS_LOWPASS);
    caps->bRangePerChannel = false;

    switch (IdacType()) {
    case IDAC_TYPE_4:
        caps->bRangePerChannel = true;
        break;
    case IDAC_TYPE_2_USB:
        caps->bRangePerChannel = false;
    }
}
Esempio n. 11
0
static inline int _get_iid(esp_now_netdev_t *dev, eui64_t *value, size_t max_len)
{
    CHECK_PARAM_RET (max_len >= sizeof(eui64_t), -EOVERFLOW);

    /* interface id according to */
    /* https://tools.ietf.org/html/rfc4291#section-2.5.1 */
    value->uint8[0] = dev->addr[0] ^ 0x02; /* invert bit1 */
    value->uint8[1] = dev->addr[1];
    value->uint8[2] = dev->addr[2];
    value->uint8[3] = 0xff;
    value->uint8[4] = 0xfe;
    value->uint8[5] = dev->addr[3];
    value->uint8[6] = dev->addr[4];
    value->uint8[7] = dev->addr[5];

    return sizeof(eui64_t);
}
Esempio n. 12
0
bool eos_compileActionTransfer(const EosActionCommon *common,
                               const EosActionTransfer *action) {
    CHECK_COMMON(EOS_Transfer);

    CHECK_PARAM_RET(action->has_quantity, "Required field missing", false);
    CHECK_PARAM_RET(action->has_sender, "Required field missing", false);
    CHECK_PARAM_RET(action->has_receiver, "Required field missing", false);
    CHECK_PARAM_RET(action->has_memo, "Required field missing", false);

    size_t memo_len = strlen(action->memo);

    if (256 < memo_len) {
        fsm_sendFailure(FailureType_Failure_SyntaxError, "Memo too long");
        eos_signingAbort();
        layoutHome();
        return false;
    }

    char asset[EOS_ASSET_STR_SIZE];
    CHECK_PARAM_RET(eos_formatAsset(&action->quantity, asset),
                    "Invalid asset format", false);

    char sender[EOS_NAME_STR_SIZE];
    CHECK_PARAM_RET(eos_formatName(action->sender, sender),
                    "Invalid name", false);

    char receiver[EOS_NAME_STR_SIZE];
    CHECK_PARAM_RET(eos_formatName(action->receiver, receiver),
                    "Invalid name", false);

    if (!confirm(ButtonRequestType_ButtonRequest_ConfirmEosAction,
                 "Transfer", "Do you want to send %s from %s to %s?",
                 asset, sender, receiver)) {
        fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action Cancelled");
        eos_signingAbort();
        layoutHome();
        return false;
    }

    char title[MEDIUM_STR_BUF];
    snprintf(title, sizeof(title), "Confirm Memo (%" PRIu32 " bytes)", (uint32_t)memo_len);
    if (!confirm_data(ButtonRequestType_ButtonRequest_ConfirmMemo,
                      title, (const uint8_t*)action->memo, memo_len)) {
        fsm_sendFailure(FailureType_Failure_ActionCancelled, "Action Cancelled");
        eos_signingAbort();
        layoutHome();
        return false;
    }

    CHECK_PARAM_RET(eos_compileActionCommon(common),
                    "Cannot compile ActionCommon", false);

    uint32_t size = 8 + 8 + 16 + eos_hashUInt(NULL, memo_len) + memo_len;
    eos_hashUInt(&hasher_preimage, size);

    hasher_Update(&hasher_preimage, (const uint8_t*)&action->sender, 8);
    hasher_Update(&hasher_preimage, (const uint8_t*)&action->receiver, 8);

    CHECK_PARAM_RET(eos_compileAsset(&action->quantity),
                    "Cannot compile asset: quantity", false);

    eos_hashUInt(&hasher_preimage, memo_len);
    hasher_Update(&hasher_preimage, (const uint8_t*)action->memo, memo_len);

    return true;
}
Esempio n. 13
0
void Server::remove(const QString& key) {
	CHECK_PARAM_RET(m_database.contains(key));
	m_database.remove(key);
	emit entriesRemoved(QStringList(key));
}
Esempio n. 14
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;
}
Esempio n. 15
0
static int _send(netdev_t *netdev, const iolist_t *iolist)
{
    #if ESP_NOW_UNICAST
    if (!_esp_now_scan_peers_done) {
        return -ENODEV;
    }
    #endif

    DEBUG("%s: %p %p\n", __func__, netdev, iolist);

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

    esp_now_netdev_t* dev = (esp_now_netdev_t*)netdev;

    mutex_lock(&dev->dev_lock);
    dev->tx_len = 0;

    /* load packet data into TX buffer */
    for (const iolist_t *iol = iolist; iol; iol = iol->iol_next) {
        if (dev->tx_len + iol->iol_len > ESP_NOW_MAX_SIZE) {
            mutex_unlock(&dev->dev_lock);
            return -EOVERFLOW;
        }
        memcpy (dev->tx_buf + dev->tx_len, iol->iol_base, iol->iol_len);
        dev->tx_len += iol->iol_len;
    }

    #if ENABLE_DEBUG
    printf ("%s: send %d byte\n", __func__, dev->tx_len);
    /* esp_hexdump (dev->tx_buf, dev->tx_len, 'b', 16); */
    #endif

    _esp_now_sending = 1;

    uint8_t* _esp_now_dst = 0;

    #if ESP_NOW_UNICAST
    ipv6_hdr_t* ipv6_hdr = (ipv6_hdr_t*)dev->tx_buf;
    uint8_t  _esp_now_dst_from_iid[6];

    if (ipv6_hdr->dst.u8[0] == 0xff) {
        /* packets to multicast prefix ff::/8 are sent to all peers */
        DEBUG("multicast to all peers\n");
        _esp_now_dst = 0;
        _esp_now_sending = dev->peers_all;

        #ifdef MODULE_NETSTATS_L2
        netdev->stats.tx_mcast_count++;
        #endif
    }

    else if ((byteorder_ntohs(ipv6_hdr->dst.u16[0]) & 0xffc0) == 0xfe80) {
        /* for link local addresses fe80::/10, the MAC address is derived from dst address */
        _get_mac_from_iid(&ipv6_hdr->dst.u8[8], _esp_now_dst_from_iid);
        DEBUG("link local to %02x:%02x:%02x:%02x:%02x:%02x\n",
              _esp_now_dst_from_iid[0], _esp_now_dst_from_iid[1],
              _esp_now_dst_from_iid[2], _esp_now_dst_from_iid[3],
              _esp_now_dst_from_iid[4], _esp_now_dst_from_iid[5]);
        _esp_now_dst = _esp_now_dst_from_iid;
        _esp_now_sending = 1;
    }

    else {
        #ifdef MODULE_GNRC_IPV6_NIB
        /* for other addresses, try to find an entry in NIB cache */
        gnrc_ipv6_nib_nc_t nce;
        int ret = gnrc_ipv6_nib_get_next_hop_l2addr (&ipv6_hdr->dst, dev->netif,
                                                     NULL, &nce);
        if (ret == 0) {
            /* entry was found in NIB, use MAC adress from the NIB cache entry */
            DEBUG("global, next hop to neighbor %02x:%02x:%02x:%02x:%02x:%02x\n",
                  nce.l2addr[0], nce.l2addr[1], nce.l2addr[2],
                  nce.l2addr[3], nce.l2addr[4], nce.l2addr[5]);
            _esp_now_dst = nce.l2addr;
            _esp_now_sending = 1;
        }
        else {
        #endif
            /* entry was not found in NIB, send to all peers */
            DEBUG("global, no neibhbor found, multicast to all peers\n");
            _esp_now_dst = 0;
            _esp_now_sending = dev->peers_all;

            #ifdef MODULE_NETSTATS_L2
            netdev->stats.tx_mcast_count++;
            #endif

        #ifdef MODULE_GNRC_IPV6_NIB
        }
        #endif
    }

    #else /* ESP_NOW_UNICAST */

    ipv6_hdr_t* ipv6_hdr = (ipv6_hdr_t*)dev->tx_buf;
    uint8_t  _esp_now_dst_from_iid[6];

    _esp_now_dst = (uint8_t*)_esp_now_mac;
    _esp_now_sending = 1;

    if (ipv6_hdr->dst.u8[0] == 0xff) {
        /* packets to multicast prefix ff::/8 are sent to all peers */
        DEBUG("multicast to all peers\n");

        #ifdef MODULE_NETSTATS_L2
        netdev->stats.tx_mcast_count++;
        #endif
    }

    else if ((byteorder_ntohs(ipv6_hdr->dst.u16[0]) & 0xffc0) == 0xfe80) {
        /* for link local addresses fe80::/10, the MAC address is derived from dst address */
        _get_mac_from_iid(&ipv6_hdr->dst.u8[8], _esp_now_dst_from_iid);
        DEBUG("link local to %02x:%02x:%02x:%02x:%02x:%02x\n",
              _esp_now_dst_from_iid[0], _esp_now_dst_from_iid[1],
              _esp_now_dst_from_iid[2], _esp_now_dst_from_iid[3],
              _esp_now_dst_from_iid[4], _esp_now_dst_from_iid[5]);
        if (esp_now_is_peer_exist(_esp_now_dst_from_iid) > 0) {
            _esp_now_dst = _esp_now_dst_from_iid;
        }
    }

    else
    {
        /* for other addresses, try to find an entry in NIB cache */
          gnrc_ipv6_nib_nc_t nce;
        int ret = gnrc_ipv6_nib_get_next_hop_l2addr (&ipv6_hdr->dst, dev->netif,
                                                     NULL, &nce);
        if (ret == 0 && esp_now_is_peer_exist(nce.l2addr) > 0) {
            /* entry was found in NIB, use MAC adress from the NIB cache entry */
            DEBUG("global, next hop to neighbor %02x:%02x:%02x:%02x:%02x:%02x\n",
                  nce.l2addr[0], nce.l2addr[1], nce.l2addr[2],
                  nce.l2addr[3], nce.l2addr[4], nce.l2addr[5]);
            _esp_now_dst = nce.l2addr;
        }
        else {
            /* entry was not found in NIB, send to all peers */
            DEBUG("global, no neibhbor found, multicast to all peers\n");

            #ifdef MODULE_NETSTATS_L2
            netdev->stats.tx_mcast_count++;
            #endif
        }
    }

    #endif /* ESP_NOW_UNICAST */
    if (_esp_now_dst) {
        DEBUG("%s: send to esp_now addr %02x:%02x:%02x:%02x:%02x:%02x\n", __func__,
              _esp_now_dst[0], _esp_now_dst[1], _esp_now_dst[2],
              _esp_now_dst[3], _esp_now_dst[4], _esp_now_dst[5]);
    }

    /* send the the packet to the peer(s) mac address */
    if (esp_now_send (_esp_now_dst, dev->tx_buf, dev->tx_len) == 0) {
        while (_esp_now_sending > 0) {
            thread_yield_higher();
        }

        #ifdef MODULE_NETSTATS_L2
        netdev->stats.tx_bytes += dev->tx_len;
        netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
        #endif

        mutex_unlock(&dev->dev_lock);
        return dev->tx_len;
    }
    else {
        #ifdef MODULE_NETSTATS_L2
        netdev->stats.tx_failed++;
        #endif
    }

    mutex_unlock(&dev->dev_lock);
    return -EIO;
}