void _dao_handle_send(rpl_dodag_t *dodag) { if ((dodag->ack_received == false) && (dodag->dao_counter < DAO_SEND_RETRIES)) { dodag->dao_counter++; rpl_send_DAO(dodag, NULL, 0, true, 0); dodag->dao_time = timex_set(DEFAULT_WAIT_FOR_DAO_ACK, 0); vtimer_remove(&dodag->dao_timer); vtimer_set_msg(&dodag->dao_timer, dodag->dao_time, rpl_process_pid, RPL_MSG_TYPE_DAO_HANDLE, dodag); } else if (dodag->ack_received == false) { long_delay_dao(dodag); } }
void rpl_send_DAO(rpl_dodag_t *my_dodag, ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index) { #if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE (void) start_index; #endif #if ENABLE_DEBUG if (destination) { DEBUGF("Send DAO to %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, destination)); } #endif if (i_am_root) { return; } if (my_dodag == NULL) { DEBUGF("send_DAO: I have no my_dodag\n"); return; } if (destination == NULL) { #if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE destination = &my_dodag->dodag_id; #else if (my_dodag->my_preferred_parent == NULL) { DEBUGF("send_DAO: my_dodag has no my_preferred_parent\n"); return; } destination = &my_dodag->my_preferred_parent->addr; #endif } if (default_lifetime) { lifetime = my_dodag->default_lifetime; } icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; icmp_send_buf->code = ICMP_CODE_DAO; rpl_send_dao_buf = get_rpl_send_dao_buf(); memset(rpl_send_dao_buf, 0, sizeof(*rpl_send_dao_buf)); rpl_send_dao_buf->rpl_instanceid = my_dodag->instance->id; rpl_send_dao_buf->k_d_flags = 0x00; rpl_send_dao_buf->dao_sequence = my_dodag->dao_seq; uint16_t opt_len = 0; rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN); #if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE /* add all targets from routing table as targets */ uint8_t entries = 0; uint8_t continue_index = 0; for (uint8_t i = start_index; i < rpl_max_routing_entries; i++) { if (rpl_get_routing_table()[i].used) { rpl_send_opt_target_buf->type = RPL_OPT_TARGET; rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; rpl_send_opt_target_buf->flags = 0x00; rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; memcpy(&rpl_send_opt_target_buf->target, &rpl_get_routing_table()[i].address, sizeof(ipv6_addr_t)); opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN; rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT; rpl_send_opt_transit_buf->length = (RPL_OPT_TRANSIT_LEN - sizeof(ipv6_addr_t)); rpl_send_opt_transit_buf->e_flags = 0x00; rpl_send_opt_transit_buf->path_control = 0x00; /* not used */ rpl_send_opt_transit_buf->path_sequence = 0x00; /* not used */ rpl_send_opt_transit_buf->path_lifetime = lifetime; opt_len += (RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN - sizeof(ipv6_addr_t)); rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN + opt_len); entries++; } /* Split DAO, so packages don't get too big. * The value 5 is based on experience. */ if (entries >= 5) { continue_index = i + 1; break; } } #endif /* add own address */ rpl_send_opt_target_buf->type = RPL_OPT_TARGET; rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; rpl_send_opt_target_buf->flags = 0x00; rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; if (!ipv6_addr_is_unspecified(&my_dodag->prefix)) { ipv6_addr_t tmp; ipv6_addr_set_by_eui64(&tmp, rpl_if_id, &my_dodag->prefix); memcpy(&rpl_send_opt_target_buf->target, &tmp, sizeof(ipv6_addr_t)); } else { memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t)); } opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN; rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT; rpl_send_opt_transit_buf->e_flags = 0x00; rpl_send_opt_transit_buf->path_control = 0x00; rpl_send_opt_transit_buf->path_sequence = 0x00; rpl_send_opt_transit_buf->path_lifetime = lifetime; #if RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE rpl_send_opt_transit_buf->length = RPL_OPT_TRANSIT_LEN; memcpy(&rpl_send_opt_transit_buf->parent, &my_dodag->my_preferred_parent->addr, sizeof(ipv6_addr_t)); opt_len += RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN; #else rpl_send_opt_transit_buf->length = (RPL_OPT_TRANSIT_LEN - sizeof(ipv6_addr_t)); opt_len += (RPL_OPT_TRANSIT_LEN_WITH_OPT_LEN - sizeof(ipv6_addr_t)); #endif uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len; rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); #if RPL_DEFAULT_MOP != RPL_MOP_NON_STORING_MODE if (continue_index > 1) { rpl_send_DAO(my_dodag, destination, lifetime, default_lifetime, continue_index); } #endif }
void rpl_send_DAO_mode(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index) { if (i_am_root) { return; } rpl_dodag_t *my_dodag; if ((my_dodag = rpl_get_my_dodag()) == NULL) { DEBUGF("send_DAO: I have no my_dodag\n"); return; } if (destination == NULL) { if (my_dodag->my_preferred_parent == NULL) { DEBUGF("send_DAO: my_dodag has no my_preferred_parent\n"); return; } destination = &my_dodag->my_preferred_parent->addr; } if (default_lifetime) { lifetime = my_dodag->default_lifetime; } icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); icmp_send_buf->type = ICMPV6_TYPE_RPL_CONTROL; icmp_send_buf->code = ICMP_CODE_DAO; rpl_send_dao_buf = get_rpl_send_dao_buf(); memset(rpl_send_dao_buf, 0, sizeof(*rpl_send_dao_buf)); rpl_send_dao_buf->rpl_instanceid = my_dodag->instance->id; rpl_send_dao_buf->k_d_flags = 0x00; rpl_send_dao_buf->dao_sequence = my_dodag->dao_seq; uint16_t opt_len = 0; rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN); /* add all targets from routing table as targets */ uint8_t entries = 0; uint8_t continue_index = 0; for (uint8_t i = start_index; i < rpl_max_routing_entries; i++) { if (rpl_get_routing_table()[i].used) { rpl_send_opt_target_buf->type = RPL_OPT_TARGET; rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; rpl_send_opt_target_buf->flags = 0x00; rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; memcpy(&rpl_send_opt_target_buf->target, &rpl_get_routing_table()[i].address, sizeof(ipv6_addr_t)); opt_len += RPL_OPT_TARGET_LEN; rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT; rpl_send_opt_transit_buf->length = RPL_OPT_TRANSIT_LEN; rpl_send_opt_transit_buf->e_flags = 0x00; rpl_send_opt_transit_buf->path_control = 0x00; /* not used */ rpl_send_opt_transit_buf->path_sequence = 0x00; /* not used */ rpl_send_opt_transit_buf->path_lifetime = lifetime; opt_len += RPL_OPT_TRANSIT_LEN; rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN + opt_len); entries++; } /* Split DAO, so packages don't get too big. * The value 5 is based on experience. */ if (entries >= 5) { continue_index = i + 1; break; } } /* add own address */ rpl_send_opt_target_buf->type = RPL_OPT_TARGET; rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; rpl_send_opt_target_buf->flags = 0x00; rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t)); opt_len += RPL_OPT_TARGET_LEN; rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); rpl_send_opt_transit_buf->type = RPL_OPT_TRANSIT; rpl_send_opt_transit_buf->length = RPL_OPT_TRANSIT_LEN; rpl_send_opt_transit_buf->e_flags = 0x00; rpl_send_opt_transit_buf->path_control = 0x00; rpl_send_opt_transit_buf->path_sequence = 0x00; rpl_send_opt_transit_buf->path_lifetime = lifetime; opt_len += RPL_OPT_TRANSIT_LEN; uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len; rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6); if (continue_index > 1) { rpl_send_DAO(destination, lifetime, default_lifetime, continue_index); } }