From 1acb69e280b826fc338ac242cd16ef65ddc4373d Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 23 Jun 2016 18:35:16 +0200 Subject: [PATCH 1/4] TSCH: keep track of Rx channel as packetbuf attribute --- core/net/mac/tsch/tsch-slot-operation.c | 5 ++++- core/net/mac/tsch/tsch-slot-operation.h | 3 ++- core/net/mac/tsch/tsch.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/net/mac/tsch/tsch-slot-operation.c b/core/net/mac/tsch/tsch-slot-operation.c index be83da4ab..721a5c3db 100644 --- a/core/net/mac/tsch/tsch-slot-operation.c +++ b/core/net/mac/tsch/tsch-slot-operation.c @@ -154,6 +154,9 @@ static rtimer_clock_t volatile current_slot_start; /* Are we currently inside a slot? */ static volatile int tsch_in_slot_operation = 0; +/* If we are inside a slot, this tells the current channel */ +static uint8_t current_channel; + /* Info about the link, packet and neighbor of * the current (or next) slot */ struct tsch_link *current_link = NULL; @@ -780,6 +783,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_RSSI, &radio_last_rssi); current_input->rx_asn = current_asn; current_input->rssi = (signed)radio_last_rssi; + current_input->channel = current_channel; header_len = frame802154_parse((uint8_t *)current_input->payload, current_input->len, &frame); frame_valid = header_len > 0 && frame802154_check_dest_panid(&frame) && @@ -937,7 +941,6 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) ); } else { - uint8_t current_channel; int is_active_slot; TSCH_DEBUG_SLOT_START(); tsch_in_slot_operation = 1; diff --git a/core/net/mac/tsch/tsch-slot-operation.h b/core/net/mac/tsch/tsch-slot-operation.h index f74778c00..ec05d8736 100644 --- a/core/net/mac/tsch/tsch-slot-operation.h +++ b/core/net/mac/tsch/tsch-slot-operation.h @@ -89,7 +89,8 @@ struct input_packet { uint8_t payload[TSCH_PACKET_MAX_LEN]; /* Packet payload */ struct asn_t rx_asn; /* ASN when the packet was received */ int len; /* Packet len */ - uint16_t rssi; /* RSSI for this packet */ + int16_t rssi; /* RSSI for this packet */ + uint8_t channel; /* Channel we received the packet on */ }; /***** External Variables *****/ diff --git a/core/net/mac/tsch/tsch.c b/core/net/mac/tsch/tsch.c index 292744ecc..41aa56125 100644 --- a/core/net/mac/tsch/tsch.c +++ b/core/net/mac/tsch/tsch.c @@ -361,6 +361,7 @@ tsch_rx_process_pending() /* Copy to packetbuf for processing */ packetbuf_copyfrom(current_input->payload, current_input->len); packetbuf_set_attr(PACKETBUF_ATTR_RSSI, current_input->rssi); + packetbuf_set_attr(PACKETBUF_ATTR_CHANNEL, current_input->channel); } /* Remove input from ringbuf */ From 5a1a8e84d8738928f1b50614073f6126da38f8ad Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 23 Jun 2016 18:36:04 +0200 Subject: [PATCH 2/4] TSCH: start scheduling keep-alives only after tsch_is_associated is set --- core/net/mac/tsch/tsch.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/net/mac/tsch/tsch.c b/core/net/mac/tsch/tsch.c index 41aa56125..b97e1d634 100644 --- a/core/net/mac/tsch/tsch.c +++ b/core/net/mac/tsch/tsch.c @@ -562,10 +562,6 @@ tsch_associate(const struct input_packet *input_eb, rtimer_clock_t timestamp) if(n != NULL) { tsch_queue_update_time_source((linkaddr_t *)&frame.src_addr); -#ifdef TSCH_CALLBACK_JOINING_NETWORK - TSCH_CALLBACK_JOINING_NETWORK(); -#endif - /* Set PANID */ frame802154_set_pan_id(frame.src_pid); @@ -576,9 +572,13 @@ tsch_associate(const struct input_packet *input_eb, rtimer_clock_t timestamp) tsch_is_associated = 1; tsch_is_pan_secured = frame.fcf.security_enabled; - /* Association done, schedule keepalive messages */ + /* Start sending keep-alives now that tsch_is_associated is set */ tsch_schedule_keepalive(); +#ifdef TSCH_CALLBACK_JOINING_NETWORK + TSCH_CALLBACK_JOINING_NETWORK(); +#endif + PRINTF("TSCH: association done, sec %u, PAN ID %x, asn-%x.%lx, jp %u, timeslot id %u, hopping id %u, slotframe len %u with %u links, from ", tsch_is_pan_secured, frame.src_pid, From b1dc8205f0f9a57ef28903a1ad130fecd2add3d2 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 23 Jun 2016 18:37:42 +0200 Subject: [PATCH 3/4] TSCH: minor logging enhancement --- core/net/mac/tsch/tsch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/net/mac/tsch/tsch.c b/core/net/mac/tsch/tsch.c index b97e1d634..e03d34a50 100644 --- a/core/net/mac/tsch/tsch.c +++ b/core/net/mac/tsch/tsch.c @@ -928,7 +928,10 @@ send_packet(mac_callback_t sent, void *ptr) /* Enqueue packet */ p = tsch_queue_add_packet(addr, sent, ptr); if(p == NULL) { - PRINTF("TSCH:! can't send packet !tsch_queue_add_packet\n"); + PRINTF("TSCH:! can't send packet to %u with seqno %u, queue %u %u\n", + TSCH_LOG_ID_FROM_LINKADDR(addr), tsch_packet_seqno, + packet_count_before, + tsch_queue_packet_count(addr)); ret = MAC_TX_ERR; } else { p->header_len = hdr_len; From ee60355c9c8ded25142c5793ccd1b0ce21a3ebd3 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 23 Jun 2016 18:38:12 +0200 Subject: [PATCH 4/4] TSCH: implement off() --- core/net/mac/tsch/tsch.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/net/mac/tsch/tsch.c b/core/net/mac/tsch/tsch.c index e03d34a50..15a75fe80 100644 --- a/core/net/mac/tsch/tsch.c +++ b/core/net/mac/tsch/tsch.c @@ -1017,6 +1017,11 @@ turn_on(void) static int turn_off(int keep_radio_on) { + if(keep_radio_on) { + NETSTACK_RADIO.on(); + } else { + NETSTACK_RADIO.off(); + } return 1; } /*---------------------------------------------------------------------------*/