Beispiel #1
0
/* obligatory for each mode. normally not modified */
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header)
{
    uint8_t *p_ptr;
    ipv6_send_buf = get_rpl_send_ipv6_buf();
    p_ptr = get_rpl_send_payload_buf(ipv6_ext_hdr_len);

    DEBUGF("Trying to send to destination: %s\n", ipv6_addr_to_str(addr_str_mode,
            IPV6_MAX_ADDR_STR_LEN, destination));

    ipv6_send_buf->version_trafficclass = IPV6_VER;
    ipv6_send_buf->trafficclass_flowlabel = 0;
    ipv6_send_buf->flowlabel = 0;
    ipv6_send_buf->nextheader = next_header;
    ipv6_send_buf->hoplimit = MULTIHOP_HOPLIMIT;
    ipv6_send_buf->length = HTONS(p_len);
    memcpy(&(ipv6_send_buf->destaddr), destination, 16);
    ipv6_net_if_get_best_src_addr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr));

    icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
    icmp_send_buf->checksum = icmpv6_csum(ipv6_send_buf, icmp_send_buf);

    /* The packet was "assembled" in rpl_%mode%.c. Therefore rpl_send_buf was used.
     * Therefore memcpy is not needed because the payload is at the
     * right memory location already. */

    if (p_ptr != payload) {
        memcpy(p_ptr, payload, p_len);
    }

    if (ipv6_addr_is_multicast(&ipv6_send_buf->destaddr)) {
        ipv6_send_packet(ipv6_send_buf, NULL);
    }
    else {
        /* find appropriate next hop before sending */
        ipv6_addr_t *next_hop = rpl_get_next_hop(&ipv6_send_buf->destaddr);
        DEBUGF("Trying to send to destination: %s\n", ipv6_addr_to_str(addr_str_mode,
                IPV6_MAX_ADDR_STR_LEN, next_hop));

        if (next_hop == NULL) {
            if (i_am_root) {
                DEBUGF("[Error] destination unknown: %s\n", ipv6_addr_to_str(addr_str_mode,
                        IPV6_MAX_ADDR_STR_LEN, &ipv6_send_buf->destaddr));
                return;
            }
            else {
                next_hop = rpl_get_my_preferred_parent();

                if (next_hop == NULL) {
                    DEBUGF("[Error] no preferred parent, dropping package\n");
                    return;
                }
            }
        }

        DEBUGF("Sending done (for RPL)\n");
        ipv6_send_packet(ipv6_send_buf, NULL);
    }

}
Beispiel #2
0
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header)
{
    uint8_t *p_ptr;
    ipv6_send_buf = get_rpl_send_ipv6_buf();
    p_ptr = get_rpl_send_payload_buf(ipv6_ext_hdr_len);
    uint16_t packet_length = 0;

    ipv6_send_buf->version_trafficclass = IPV6_VER;
    ipv6_send_buf->trafficclass_flowlabel = 0;
    ipv6_send_buf->flowlabel = 0;
    ipv6_send_buf->nextheader = next_header;
    ipv6_send_buf->hoplimit = MULTIHOP_HOPLIMIT;
    ipv6_send_buf->length = HTONS(p_len);

    memcpy(&(ipv6_send_buf->destaddr), destination, 16);
    ipv6_net_if_get_best_src_addr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr));

    icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
    icmp_send_buf->checksum = icmpv6_csum(ipv6_send_buf, icmp_send_buf);

    /* The packet was "assembled" in rpl.c. Therefore rpl_send_buf was used.
     * Therefore memcpy is not needed because the payload is at the
     * right memory location already. */

    if (p_ptr != payload) {
        memcpy(p_ptr, payload, p_len);
    }

    packet_length = IPV6_HDR_LEN + p_len;

    if (ipv6_addr_is_multicast(&ipv6_send_buf->destaddr)) {
        ipv6_send_packet(ipv6_send_buf);
    }
    else {
        /* find appropriate next hop before sending */
        ipv6_addr_t *next_hop = rpl_get_next_hop(&ipv6_send_buf->destaddr);

        if (next_hop == NULL) {
            if (i_am_root) {
                DEBUG("%s, %d: [Error] destination unknown\n", __FILE__, __LINE__);
                return;
            }
            else {
                next_hop = rpl_get_my_preferred_parent();

                if (next_hop == NULL) {
                    DEBUG("%s, %d: [Error] no preferred parent, dropping package\n", __FILE__, __LINE__);
                    return;
                }
            }
        }

        ipv6_send_packet(ipv6_send_buf);
    }

}
Beispiel #3
0
/* obligatory for each mode. normally not modified */
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header)
{
    uint8_t *p_ptr;
    ipv6_send_buf = get_rpl_send_ipv6_buf();
    p_ptr = get_rpl_send_payload_buf(ipv6_ext_hdr_len);

    ipv6_send_buf->version_trafficclass = IPV6_VER;
    ipv6_send_buf->trafficclass_flowlabel = 0;
    ipv6_send_buf->flowlabel = 0;
    ipv6_send_buf->nextheader = next_header;
    ipv6_send_buf->hoplimit = MULTIHOP_HOPLIMIT;
    ipv6_send_buf->length = HTONS(p_len);

    memcpy(&(ipv6_send_buf->destaddr), destination, 16);
    ipv6_net_if_get_best_src_addr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr));

    icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
    icmp_send_buf->checksum = icmpv6_csum(ipv6_send_buf, icmp_send_buf);

    /* The packet was "assembled" in rpl_%mode%.c. Therefore rpl_send_buf was used.
     * Therefore memcpy is not needed because the payload is at the
     * right memory location already. */

    if (p_ptr != payload) {
        memcpy(p_ptr, payload, p_len);
    }

    ipv6_send_packet(ipv6_send_buf, NULL);
}
Beispiel #4
0
Datei: ip.c Projekt: A-L-E-X/RIOT
int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
                const uint8_t *payload, uint16_t payload_length)
{
    uint8_t *p_ptr;

    if (next_header == IPV6_PROTO_NUM_TCP) {
        p_ptr = get_payload_buf_send(ipv6_ext_hdr_len);
        ipv6_buf = ipv6_get_buf_send();
    }
    else {
        ipv6_buf = ipv6_get_buf();
        p_ptr = get_payload_buf(ipv6_ext_hdr_len);
    }

    ipv6_buf->version_trafficclass = IPV6_VER;
    ipv6_buf->trafficclass_flowlabel = 0;
    ipv6_buf->flowlabel = 0;
    ipv6_buf->nextheader = next_header;
    ipv6_buf->hoplimit = MULTIHOP_HOPLIMIT;
    ipv6_buf->length = HTONS(payload_length);

    memcpy(&(ipv6_buf->destaddr), dest, 16);

    memcpy(p_ptr, payload, payload_length);

    return ipv6_send_packet(ipv6_buf);
}
Beispiel #5
0
void demultiplex(border_packet_t *packet)
{
    switch (packet->type) {
        case (BORDER_PACKET_RAW_TYPE): {
            fputs(((char *)packet) + sizeof(border_packet_t), stdin);
            break;
        }

        case (BORDER_PACKET_L3_TYPE): {
            border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet;

            switch (l3_header_buf->ethertype) {
                case (BORDER_ETHERTYPE_IPV6): {
                    ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t));
                    ipv6_send_packet(ipv6_buf);
                    break;
                }

                default:
                    printf("ERROR: Unknown ethertype 0x%04x\n", l3_header_buf->ethertype);
                    break;
            }

            break;
        }

        case (BORDER_PACKET_CONF_TYPE): {
            border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet;

            switch (conf_header_buf->conftype) {
                case (BORDER_CONF_CONTEXT): {
                    border_context_packet_t *context = (border_context_packet_t *)packet;
                    ipv6_addr_t target_addr;
                    ipv6_addr_set_all_nodes_addr(&target_addr);
                    mutex_lock(&lowpan_context_mutex);
                    lowpan_context_update(
                        context->context.cid,
                        &context->context.prefix,
                        context->context.length,
                        context->context.comp,
                        context->context.lifetime
                    );
                    mutex_unlock(&lowpan_context_mutex);
                    abr_add_context(context->context.version, abr_addr, context->context.cid);
                    /* Send router advertisement */
                    break;
                }

                case (BORDER_CONF_IPADDR): {
                    //border_addr_packet_t *addr_packet = (border_addr_packet_t *)packet;
                    /* add address */
                    break;
                }

                default:
                    printf("ERROR: Unknown conftype %02x\n", conf_header_buf->conftype);
                    break;
            }

            break;
        }

        default:
            printf("ERROR: Unknown border packet type %02x\n", packet->type);
            break;
    }
}