Beispiel #1
0
void ng_ipv6_netif_init_by_dev(void)
{
    kernel_pid_t ifs[NG_NETIF_NUMOF];
    size_t ifnum = ng_netif_get(ifs);

    for (size_t i = 0; i < ifnum; i++) {
        ng_ipv6_addr_t addr;
        eui64_t iid;
        ng_ipv6_netif_t *ipv6_if = ng_ipv6_netif_get(ifs[i]);

        if (ipv6_if == NULL) {
            continue;
        }

        mutex_lock(&ipv6_if->mutex);

#ifdef MODULE_NG_SIXLOWPAN
        ng_nettype_t if_type = NG_NETTYPE_UNDEF;

        if ((ng_netapi_get(ifs[i], NETCONF_OPT_PROTO, 0, &if_type,
                           sizeof(if_type)) != -ENOTSUP) &&
            (if_type == NG_NETTYPE_SIXLOWPAN)) {
            uint16_t src_len = 8;
            DEBUG("Set 6LoWPAN flag\n");
            ipv6_ifs[i].flags |= NG_IPV6_NETIF_FLAGS_SIXLOWPAN;
            /* use EUI-64 (8-byte address) for IID generation and for sending
             * packets */
            ng_netapi_set(ifs[i], NETCONF_OPT_SRC_LEN, 0, &src_len,
                          sizeof(src_len)); /* don't care for result */
        }

#endif

        if ((ng_netapi_get(ifs[i], NETCONF_OPT_IPV6_IID, 0, &iid,
                           sizeof(eui64_t)) < 0)) {
            mutex_unlock(&ipv6_if->mutex);
            continue;
        }

        ng_ipv6_addr_set_aiid(&addr, iid.uint8);
        ng_ipv6_addr_set_link_local_prefix(&addr);
        _add_addr_to_entry(ipv6_if, &addr, 64, 0);

        mutex_unlock(&ipv6_if->mutex);
    }
}
Beispiel #2
0
static void test_ipv6_addr_set_aiid(void)
{
    ng_ipv6_addr_t a = { {
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
        }
    };

    ng_ipv6_addr_t b = { {
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
            0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
        }
    };

    ng_ipv6_addr_set_aiid(&a, &(b.u8[8]));

    TEST_ASSERT_EQUAL_INT(true, ng_ipv6_addr_equal(&a, &b));
}