Esempio n. 1
0
File: ip.c Progetto: A-L-E-X/RIOT
ipv6_addr_t *ipv6_addr_set_by_eui64(ipv6_addr_t *out, int if_id,
                                    const ipv6_addr_t *prefix)
{
    uint8_t force_generation = 0;
    out->uint16[0] = prefix->uint16[0];
    out->uint16[1] = prefix->uint16[1];
    out->uint16[2] = prefix->uint16[2];
    out->uint16[3] = prefix->uint16[3];

    if (net_if_get_src_address_mode(if_id) == NET_IF_TRANS_ADDR_M_SHORT) {
        force_generation = 1;
    }

    if (net_if_get_eui64((net_if_eui64_t *) &out->uint8[8], if_id,
                         force_generation)) {
#ifdef MODULE_SIXLOWPAN

        if (!sixlowpan_lowpan_eui64_to_short_addr((net_if_eui64_t *)&out->uint8[8])) {
            out->uint8[8] ^= 0x02;
        }

#else
        out->uint8[8] ^= 0x02;
#endif
        return out;
    }
    else {
        return NULL;
    }
}
Esempio n. 2
0
int sixlowpan_mac_prepare_ieee802144_frame(
    ieee802154_frame_t *frame, int if_id, uint16_t dest_pan, const void *dest,
    uint8_t dest_len, const void *payload, uint8_t length, uint8_t mcast)
{
    uint8_t src_mode = net_if_get_src_address_mode(if_id);
    uint8_t dest_mode;
    uint16_t *fcs;
    set_ieee802154_frame_values(if_id, dest_pan, frame);

    if (dest_len == 8) {
        dest_mode = IEEE_802154_LONG_ADDR_M;
    }
    else if (dest_len == 2) {
        dest_mode = IEEE_802154_SHORT_ADDR_M;
    }
    else {
        DEBUG("Illegal IEEE 802.15.4 address for address length %d\n", dest_len);
        return -1;
    }

    set_ieee802154_fcf_values(frame, dest_mode, src_mode);


    if (src_mode == IEEE_802154_LONG_ADDR_M) {
        net_if_get_eui64((net_if_eui64_t *)&frame->src_addr[0], if_id, 0);
    }
    else if (src_mode == IEEE_802154_SHORT_ADDR_M) {
        uint16_t src = HTONS(net_if_get_hardware_address(if_id));
        memcpy(&frame->src_addr[0], &src, 2);
    }
    else {
        DEBUG("Illegal IEEE 802.15.4 address mode: %d\n", src_mode);
        return -1;
    }

    if (mcast) {
        memset(&frame->dest_addr[0], 0xff, dest_len);
    }
    else {
        memcpy(&frame->dest_addr[0], dest, dest_len);
    }

    frame->payload = (uint8_t *)payload; // payload won't be changed so cast is legal.
    frame->payload_len = length;
    uint8_t hdrlen = ieee802154_frame_get_hdr_len(frame);

    memset(&lowpan_mac_buf, 0, PAYLOAD_SIZE);
    ieee802154_frame_init(frame, (uint8_t *)&lowpan_mac_buf);
    memcpy(&lowpan_mac_buf[hdrlen], frame->payload, frame->payload_len);
    /* set FCS */
    fcs = (uint16_t *)&lowpan_mac_buf[frame->payload_len + hdrlen];
    *fcs = ieee802154_frame_get_fcs(lowpan_mac_buf, frame->payload_len + hdrlen);
    DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n",
          lowpan_mac_buf[0], lowpan_mac_buf[1], frame->dest_pan_id,
          frame->src_pan_id, frame->seq_nr);

    return hdrlen;
}
Esempio n. 3
0
File: main.c Progetto: Rossano/RIOT
int test_net_if_get_set_eui64(int iface, net_if_eui64_t *eui64,
                              uint16_t addr)
{
    if (net_if_get_eui64(NULL, iface, 1)) {
        printf("FAILED: expected net_if_get_eui64(NULL, %d, 1) to fail\n",
               iface);
        return 0;
    }

    if (!net_if_get_eui64(eui64, iface, 1)) {
        printf("FAILED: Error getting EUI-64 on interface %d\n", iface);
        return 0;
    }

    if (eui64->uint16[0] != 0 || eui64->uint8[2] != 0 ||
        eui64->uint8[3] != 0xff || eui64->uint8[4] != 0xfe ||
        eui64->uint8[5] != 0 || (uint16_t)eui64->uint16[3] != HTONS(addr)) {
        printf("FAILED: Expected last 16 bit of EUI-64 to be 0x%04x (is 0x%04x)\n",
               addr, NTOHS(eui64->uint16[3]));
        return 0;
    }

    eui64->uint64 = 0;

    if (net_if_set_eui64(iface, NULL)) {
        printf("FAILED: expected error on net_if_set_eui64(%d, NULL)\n", iface);
        return 0;
    }

    if (net_if_set_eui64(iface, eui64)) {
        printf("FAILED: expected error trying to set EUI-64 to broadcast\n");
        return 0;
    }

#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
    eui64->uint8[0] = 0x11;
    eui64->uint8[1] = 0x22;
    eui64->uint8[2] = 0x33;
    eui64->uint8[3] = 0x44;
    eui64->uint8[4] = 0x55;
    eui64->uint8[5] = 0x66;
    eui64->uint8[6] = 0x77;
    eui64->uint8[7] = 0x88;

    if (!net_if_set_eui64(iface, eui64)) {
        printf("FAILED: Error setting EUI-64 on interface %d\n", iface);
        return 0;
    }

    eui64->uint64 = 0;

    if (!net_if_get_eui64(eui64, iface, 0)) {
        printf("FAILED: Error getting EUI-64 on interface %d\n", iface);
        return 0;
    }

    /* transceivers that do not support EUI-64 addresses convert automatically
     * so we have to test both cases */
    if (eui64->uint8[0] != 0x11 || eui64->uint8[1] != 0x22 ||
        eui64->uint8[2] != 0x33 || eui64->uint8[3] != 0x44 ||
        eui64->uint8[4] != 0x55 || eui64->uint8[5] != 0x66 ||
        eui64->uint8[6] != 0x77 || eui64->uint8[7] != 0x88) {
        printf("FAILED: EUI-64 to be 11-22-33-44-55-66-77-88 but is "
               "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
               eui64->uint8[0], eui64->uint8[1], eui64->uint8[2],
               eui64->uint8[3], eui64->uint8[4], eui64->uint8[5],
               eui64->uint8[6], eui64->uint8[7]);
        return 0;
    }

#endif

    return 1;
}