From c33c10540a6352e6ab3c9b12ca1305b8734f303a Mon Sep 17 00:00:00 2001 From: Michael Karlsson Date: Tue, 7 Nov 2017 01:43:54 +0100 Subject: [PATCH] Avoid tsch crash when loosing timesource --- os/net/mac/tsch/tsch.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index 2ab2c6a32..56872adb3 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -304,13 +304,17 @@ keepalive_send(void *ptr) { if(tsch_is_associated) { struct tsch_neighbor *n = tsch_queue_get_time_source(); - /* Simply send an empty packet */ - packetbuf_clear(); - packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &n->addr); - NETSTACK_MAC.send(keepalive_packet_sent, NULL); - LOG_INFO("sending KA to "); - LOG_INFO_LLADDR(&n->addr); - LOG_INFO_("\n"); + if(n != NULL) { + /* Simply send an empty packet */ + packetbuf_clear(); + packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &n->addr); + NETSTACK_MAC.send(keepalive_packet_sent, NULL); + LOG_INFO("sending KA to "); + LOG_INFO_LLADDR(&n->addr); + LOG_INFO_("\n"); + } else { + LOG_INFO("no timesource - KA not sent\n"); + } } } /*---------------------------------------------------------------------------*/