From adb00ed9326b590e1bee5e217b89c914e530d750 Mon Sep 17 00:00:00 2001 From: joxe Date: Sun, 9 May 2010 17:52:37 +0000 Subject: [PATCH] factored out function for getting link local address in ds6 and made use of it in rpl for checking state of lladdress as DIOs should not be sent when tentative --- core/net/rpl/rpl-timers.c | 15 ++++++++++++++- core/net/uip-ds6.c | 28 +++++++++++++++++++--------- core/net/uip-ds6.h | 1 + 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/core/net/rpl/rpl-timers.c b/core/net/rpl/rpl-timers.c index 9dbfbc9f5..2de00a7e1 100644 --- a/core/net/rpl/rpl-timers.c +++ b/core/net/rpl/rpl-timers.c @@ -32,7 +32,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rpl-timers.c,v 1.2 2010/05/04 22:55:32 nvt-se Exp $ + * $Id: rpl-timers.c,v 1.3 2010/05/09 17:52:37 joxe Exp $ */ /** * \file @@ -57,6 +57,10 @@ static void new_dio_interval(rpl_dag_t *dag); static void handle_dio_timer(void *ptr); static uint16_t next_dis; + +/* dio_send_ok is true if the node is ready to send DIOs */ +static uint8_t dio_send_ok; + /************************************************************************/ static void handle_periodic_timer(void *ptr) @@ -118,6 +122,15 @@ handle_dio_timer(void *ptr) dag = (rpl_dag_t *)ptr; PRINTF("RPL: DIO Timer triggered\n"); + if(!dio_send_ok) { + if(uip_ds6_get_link_local(ADDR_PREFERRED) != NULL) { + dio_send_ok = 1; + } else { + PRINTF("RPL: Postponing DIO transmission since link local addres is not ok\n"); + ctimer_set(&dag->dio_timer, CLOCK_SECOND, &handle_dio_timer, dag); + return; + } + } if(dag->dio_send) { /* send DIO if counter is less than desired redundancy */ diff --git a/core/net/uip-ds6.c b/core/net/uip-ds6.c index 830fb5264..61bed787f 100755 --- a/core/net/uip-ds6.c +++ b/core/net/uip-ds6.c @@ -586,6 +586,24 @@ uip_ds6_addr_lookup(uip_ipaddr_t * ipaddr) return NULL; } +/*---------------------------------------------------------------------------*/ +/* + * get a link local address - + * state = -1 => any address is ok. Otherwise state = desired state of addr. + * (TENTATIVE, PREFERRED, DEPRECATED) + */ +uip_ds6_addr_t * +uip_ds6_get_link_local(int8_t state) { + for(locaddr = uip_ds6_if.addr_list; + locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { + if((locaddr->isused) && (state == - 1 || locaddr->state == state) + && (uip_is_addr_link_local(&locaddr->ipaddr))) { + return locaddr; + } + } + return NULL; +} + /*---------------------------------------------------------------------------*/ uip_ds6_maddr_t * uip_ds6_maddr_add(uip_ipaddr_t * ipaddr) @@ -763,15 +781,7 @@ uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst) } } } else { - // use link local - for(locaddr = uip_ds6_if.addr_list; - locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { - if((locaddr->isused) && (locaddr->state == ADDR_PREFERRED) - && (uip_is_addr_link_local(&locaddr->ipaddr))) { - matchaddr = locaddr; - break; - } - } + matchaddr = uip_ds6_get_link_local(ADDR_PREFERRED); } uip_ipaddr_copy(src, &matchaddr->ipaddr); diff --git a/core/net/uip-ds6.h b/core/net/uip-ds6.h index 817542d69..c251e1dbb 100755 --- a/core/net/uip-ds6.h +++ b/core/net/uip-ds6.h @@ -340,6 +340,7 @@ uip_ds6_addr_t *uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type); void uip_ds6_addr_rm(uip_ds6_addr_t *addr); uip_ds6_addr_t *uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr); +uip_ds6_addr_t *uip_ds6_get_link_local(int8_t state); /** @} */