Exemple #1
0
int test_net_if_get_set_hardware_address(int iface, uint16_t addr)
{
    uint16_t tmp;

    if (net_if_set_hardware_address(iface + 1, addr)) {
        printf("FAILED: expected net_if_set_hardware_address(%d, %d) to fail.\n",
               iface + 1, addr);
        return 0;
    }

    if (net_if_set_hardware_address(iface, 0)) {
        printf("FAILED: expected net_if_set_hardware_address(%d, 0) to fail.\n",
               iface);
        return 0;
    }

    tmp = net_if_set_hardware_address(iface, addr);

    if (addr != tmp) {
        printf("FAILED: Expected '%d' as result of net_if_set_hardware_addr() "
               "(was '%d')\n", addr, tmp);
        return 0;
    }

    tmp = net_if_get_hardware_address(iface);

    if (addr != tmp) {
        printf("FAILED: Expected '%d' as result of net_if_get_hardware_addr() "
               "(was '%d')\n", addr, tmp);
        return 0;
    }

    return 1;
}
Exemple #2
0
int net_if_get_eui64(net_if_eui64_t *eui64, int if_id, int force_generation)
{
    uint64_t tmp;

    if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) {
        DEBUG("Get EUI-64: No interface initialized with ID %d.\n", if_id);
        return 0;
    }

    if (eui64 == NULL) {
        DEBUG("Get EUI-64: parameter eui64 is a NULL pointer.\n");
        return 0;
    }

    net_if_transceiver_get_set_handler(if_id, GET_LONG_ADDR, &tmp);

    eui64->uint64 = HTONLL(tmp);

    if (eui64->uint64 == 0 || force_generation) {
        uint16_t hwaddr = net_if_get_hardware_address(if_id);

        if (hwaddr == 0) {
            return 0;
        }

        /* RFC 6282 Section 3.2.2 / RFC 2464 Section 4 */
        /* Since this is a short address, which is never globally unique, we set
         * the local/universal bit to 1. */
        eui64->uint32[0] = HTONL(0x020000ff);
        eui64->uint16[2] = HTONS(0xfe00);
        eui64->uint16[3] = HTONS(hwaddr);
    }

    return 1;
}
Exemple #3
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;
}