53 #include "net/nbr-table.h" 54 #include "net/link-stats.h" 58 #include "lib/random.h" 65 #if FRAME802154_VERSION < FRAME802154_IEEE802154_2015 66 #error TSCH: FRAME802154_VERSION must be at least FRAME802154_IEEE802154_2015 71 #define LOG_MODULE "TSCH" 72 #define LOG_LEVEL LOG_LEVEL_MAC 76 #ifndef TSCH_LINK_NEIGHBOR_CALLBACK 77 #if NETSTACK_CONF_WITH_IPV6 78 void uip_ds6_link_neighbor_callback(
int status,
int numtx);
79 #define TSCH_LINK_NEIGHBOR_CALLBACK(dest, status, num) uip_ds6_link_neighbor_callback(status, num) 85 static linkaddr_t last_eb_nbr_addr;
87 static uint8_t last_eb_nbr_jp;
91 #if TSCH_AUTOSELECT_TIME_SOURCE 92 int best_neighbor_eb_count;
97 NBR_TABLE(
struct eb_stat, eb_stats);
101 uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN];
105 static const uint16_t *tsch_default_timing_us;
107 uint16_t tsch_timing_us[tsch_ts_elements_count];
109 rtimer_clock_t tsch_timing[tsch_ts_elements_count];
111 #if LINKADDR_SIZE == 8 113 const linkaddr_t tsch_broadcast_address = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
115 const linkaddr_t tsch_eb_address = { { 0, 0, 0, 0, 0, 0, 0, 0 } };
117 const linkaddr_t tsch_broadcast_address = { { 0xff, 0xff } };
118 const linkaddr_t tsch_eb_address = { { 0, 0 } };
122 int tsch_is_started = 0;
124 int tsch_is_initialized = 0;
126 int tsch_is_coordinator = 0;
128 int tsch_is_associated = 0;
130 int tsch_association_count = 0;
132 int tsch_is_pan_secured = LLSEC802154_ENABLED;
137 uint8_t tsch_join_priority;
139 static uint8_t tsch_packet_seqno;
141 static clock_time_t tsch_current_eb_period;
143 static clock_time_t tsch_current_ka_timeout;
146 static struct ctimer keepalive_timer;
149 unsigned long tx_count;
150 unsigned long rx_count;
151 unsigned long sync_count;
152 int32_t min_drift_seen;
153 int32_t max_drift_seen;
157 PROCESS(tsch_process,
"main process");
158 PROCESS(tsch_send_eb_process,
"send EB process");
159 PROCESS(tsch_pending_events_process,
"pending events process");
162 static void packet_input(
void);
170 if(tsch_is_coordinator != enable) {
171 tsch_is_associated = 0;
173 tsch_is_coordinator = enable;
180 tsch_is_pan_secured = LLSEC802154_ENABLED && enable;
186 tsch_join_priority = jp;
192 tsch_current_ka_timeout = timeout;
203 tsch_current_eb_period = MIN(period, TSCH_MAX_EB_PERIOD);
210 frame802154_set_pan_id(0xffff);
219 tsch_join_priority = 0xff;
223 tsch_default_timing_us = TSCH_DEFAULT_TIMESLOT_TIMING;
224 for(i = 0; i < tsch_ts_elements_count; i++) {
225 tsch_timing_us[i] = tsch_default_timing_us[i];
226 tsch_timing[i] = US_TO_RTIMERTICKS(tsch_timing_us[i]);
228 #ifdef TSCH_CALLBACK_LEAVING_NETWORK 229 TSCH_CALLBACK_LEAVING_NETWORK();
232 #if TSCH_AUTOSELECT_TIME_SOURCE 233 struct nbr_sync_stat *stat;
234 best_neighbor_eb_count = 0;
236 stat = nbr_table_head(sync_stats);
237 while(stat != NULL) {
238 nbr_table_remove(sync_stats, stat);
239 stat = nbr_table_next(sync_stats, stat);
249 keepalive_packet_sent(
void *ptr,
int status,
int transmissions)
252 link_stats_packet_sent(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions);
254 #ifdef TSCH_CALLBACK_KA_SENT 255 TSCH_CALLBACK_KA_SENT(status, transmissions);
257 LOG_INFO(
"KA sent to ");
258 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
259 LOG_INFO_(
", st %d-%d\n", status, transmissions);
264 LOG_WARN(
"not able to re-synchronize, received no EB from other neighbors\n");
265 if(sync_count == 0) {
270 LOG_WARN(
"re-synchronizing on ");
271 LOG_WARN_LLADDR(&last_eb_nbr_addr);
275 tsch_join_priority = last_eb_nbr_jp + 1;
287 keepalive_send(
void *ptr)
289 if(tsch_is_associated) {
294 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &n->addr);
295 NETSTACK_MAC.
send(keepalive_packet_sent, NULL);
296 LOG_INFO(
"sending KA to ");
297 LOG_INFO_LLADDR(&n->addr);
300 LOG_ERR(
"no timesource - KA not sent\n");
310 if(!tsch_is_coordinator && tsch_is_associated && tsch_current_ka_timeout > 0) {
311 unsigned long delay = (tsch_current_ka_timeout - tsch_current_ka_timeout / 10)
313 ctimer_set(&keepalive_timer, delay, keepalive_send, NULL);
322 if(!tsch_is_coordinator && tsch_is_associated) {
323 ctimer_set(&keepalive_timer, 0, keepalive_send, NULL);
334 struct ieee802154_ies eb_ies;
337 &frame, &eb_ies, NULL, 1)) {
343 if(ts == NULL || !
linkaddr_cmp(&last_eb_nbr_addr, &ts->addr)) {
345 last_eb_nbr_jp = eb_ies.ie_join_priority;
348 #if TSCH_AUTOSELECT_TIME_SOURCE 349 if(!tsch_is_coordinator) {
351 struct eb_stat *stat = (
struct eb_stat *)nbr_table_get_from_lladdr(eb_stats, (linkaddr_t *)&frame.
src_addr);
353 stat = (
struct eb_stat *)nbr_table_add_lladdr(eb_stats, (linkaddr_t *)&frame.
src_addr, NBR_TABLE_REASON_MAC, NULL);
357 stat->jp = eb_ies.ie_join_priority;
358 best_neighbor_eb_count = MAX(best_neighbor_eb_count, stat->rx_count);
361 struct eb_stat *best_stat = NULL;
362 stat = nbr_table_head(eb_stats);
363 while(stat != NULL) {
365 if(stat->rx_count > best_neighbor_eb_count / 2) {
366 if(best_stat == NULL ||
367 stat->jp < best_stat->jp) {
371 stat = nbr_table_next(eb_stats, stat);
374 if(best_stat != NULL) {
376 tsch_join_priority = best_stat->jp + 1;
384 int32_t asn_diff =
TSCH_ASN_DIFF(current_input->rx_asn, eb_ies.ie_asn);
387 LOG_WARN(
"! ASN drifted by %ld, leaving the network\n", asn_diff);
391 if(eb_ies.ie_join_priority >= TSCH_MAX_JOIN_PRIORITY) {
393 LOG_WARN(
"! EB JP too high %u, leaving the network\n",
394 eb_ies.ie_join_priority);
397 #if TSCH_AUTOSELECT_TIME_SOURCE 399 if(tsch_join_priority != eb_ies.ie_join_priority + 1) {
400 LOG_INFO(
"update JP from EB %u -> %u\n",
401 tsch_join_priority, eb_ies.ie_join_priority + 1);
402 tsch_join_priority = eb_ies.ie_join_priority + 1;
408 if(eb_ies.ie_channel_hopping_sequence_id != 0) {
409 if(eb_ies.ie_hopping_sequence_len != tsch_hopping_sequence_length.val
410 || memcmp((uint8_t *)tsch_hopping_sequence, eb_ies.ie_hopping_sequence_list, tsch_hopping_sequence_length.val)) {
411 if(eb_ies.ie_hopping_sequence_len <=
sizeof(tsch_hopping_sequence)) {
412 memcpy((uint8_t *)tsch_hopping_sequence, eb_ies.ie_hopping_sequence_list,
413 eb_ies.ie_hopping_sequence_len);
416 LOG_WARN(
"Updating TSCH hopping sequence from EB\n");
418 LOG_WARN(
"TSCH:! parse_eb: hopping sequence too long (%u)\n", eb_ies.ie_hopping_sequence_len);
428 tsch_rx_process_pending()
433 struct input_packet *current_input = &input_array[input_index];
435 uint8_t ret =
frame802154_parse(current_input->payload, current_input->len, &frame);
436 int is_data = ret && frame.
fcf.
frame_type == FRAME802154_DATAFRAME;
445 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, current_input->rssi);
446 packetbuf_set_attr(PACKETBUF_ATTR_CHANNEL, current_input->channel);
453 eb_input(current_input);
463 tsch_tx_process_pending(
void)
465 int16_t dequeued_index;
468 struct tsch_packet *p = dequeued_array[dequeued_index];
470 queuebuf_to_packetbuf(p->qb);
471 LOG_INFO(
"packet sent to ");
472 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
473 LOG_INFO_(
", seqno %u, status %d, tx %d\n",
474 packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO), p->ret, p->transmissions);
476 mac_call_sent_callback(p->sent, p->ptr, p->ret, p->transmissions);
488 tsch_start_coordinator(
void)
490 frame802154_set_pan_id(IEEE802154_PANID);
492 memcpy(tsch_hopping_sequence, TSCH_DEFAULT_HOPPING_SEQUENCE,
sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
494 #if TSCH_SCHEDULE_WITH_6TISCH_MINIMAL 498 tsch_is_associated = 1;
499 tsch_join_priority = 0;
501 LOG_INFO(
"starting as coordinator, PAN ID %x, asn-%x.%lx\n",
502 frame802154_get_pan_id(), tsch_current_asn.ms1b, tsch_current_asn.ls4b);
512 if(tsch_is_associated == 1) {
513 tsch_is_associated = 0;
520 tsch_associate(
const struct input_packet *input_eb, rtimer_clock_t timestamp)
523 struct ieee802154_ies ies;
528 &frame, &ies, &hdrlen, 0) == 0) {
529 LOG_ERR(
"! failed to parse EB (len %u)\n", input_eb->len);
533 tsch_current_asn = ies.ie_asn;
534 tsch_join_priority = ies.ie_join_priority + 1;
536 #if TSCH_JOIN_SECURED_ONLY 538 LOG_ERR(
"! parse_eb: EB is not secured\n");
542 #if LLSEC802154_ENABLED 545 &frame, (linkaddr_t*)&frame.
src_addr, &tsch_current_asn)) {
546 LOG_ERR(
"! parse_eb: failed to authenticate\n");
551 #if !LLSEC802154_ENABLED 553 LOG_ERR(
"! parse_eb: we do not support security, but EB is secured\n");
558 #if TSCH_JOIN_MY_PANID_ONLY 560 if(frame.
src_pid != IEEE802154_PANID) {
561 LOG_ERR(
"! parse_eb: PAN ID %x != %x\n", frame.
src_pid, IEEE802154_PANID);
567 if(ies.ie_join_priority == 0xff) {
568 LOG_ERR(
"! parse_eb: no join priority\n");
573 for(i = 0; i < tsch_ts_elements_count; i++) {
574 if(ies.ie_tsch_timeslot_id == 0) {
575 tsch_timing_us[i] = tsch_default_timing_us[i];
577 tsch_timing_us[i] = ies.ie_tsch_timeslot[i];
579 tsch_timing[i] = US_TO_RTIMERTICKS(tsch_timing_us[i]);
583 if(ies.ie_channel_hopping_sequence_id == 0) {
584 memcpy(tsch_hopping_sequence, TSCH_DEFAULT_HOPPING_SEQUENCE,
sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
587 if(ies.ie_hopping_sequence_len <=
sizeof(tsch_hopping_sequence)) {
588 memcpy(tsch_hopping_sequence, ies.ie_hopping_sequence_list, ies.ie_hopping_sequence_len);
591 LOG_ERR(
"! parse_eb: hopping sequence too long (%u)\n", ies.ie_hopping_sequence_len);
596 #if TSCH_CHECK_TIME_AT_ASSOCIATION > 0 598 uint32_t expected_asn = 4096 * TSCH_CLOCK_TO_SLOTS(
clock_time() / 4096, tsch_timing_timeslot_length);
599 int32_t asn_threshold = TSCH_CHECK_TIME_AT_ASSOCIATION * 60ul * TSCH_CLOCK_TO_SLOTS(
CLOCK_SECOND, tsch_timing_timeslot_length);
600 int32_t asn_diff = (int32_t)tsch_current_asn.ls4b - expected_asn;
601 if(asn_diff > asn_threshold) {
602 LOG_ERR(
"! EB ASN rejected %lx %lx %ld\n",
603 tsch_current_asn.ls4b, expected_asn, asn_diff);
608 #if TSCH_INIT_SCHEDULE_FROM_EB 610 if(ies.ie_tsch_slotframe_and_link.num_slotframes == 0) {
611 #if TSCH_SCHEDULE_WITH_6TISCH_MINIMAL 612 LOG_INFO(
"parse_eb: no schedule, setting up minimal schedule\n");
615 LOG_INFO(
"parse_eb: no schedule\n");
621 int num_links = ies.ie_tsch_slotframe_and_link.num_links;
622 if(num_links <= FRAME802154E_IE_MAX_LINKS) {
625 ies.ie_tsch_slotframe_and_link.slotframe_handle,
626 ies.ie_tsch_slotframe_and_link.slotframe_size);
627 for(i = 0; i < num_links; i++) {
629 ies.ie_tsch_slotframe_and_link.links[i].link_options,
630 LINK_TYPE_ADVERTISING, &tsch_broadcast_address,
631 ies.ie_tsch_slotframe_and_link.links[i].timeslot, ies.ie_tsch_slotframe_and_link.links[i].channel_offset);
634 LOG_ERR(
"! parse_eb: too many links in schedule (%u)\n", num_links);
640 if(tsch_join_priority < TSCH_MAX_JOIN_PRIORITY) {
650 frame802154_set_pan_id(frame.
src_pid);
656 tsch_is_associated = 1;
667 #ifdef TSCH_CALLBACK_JOINING_NETWORK 668 TSCH_CALLBACK_JOINING_NETWORK();
671 tsch_association_count++;
672 LOG_INFO(
"association done (%u), sec %u, PAN ID %x, asn-%x.%lx, jp %u, timeslot id %u, hopping id %u, slotframe len %u with %u links, from ",
673 tsch_association_count,
676 tsch_current_asn.ms1b, tsch_current_asn.ls4b, tsch_join_priority,
677 ies.ie_tsch_timeslot_id,
678 ies.ie_channel_hopping_sequence_id,
679 ies.ie_tsch_slotframe_and_link.slotframe_size,
680 ies.ie_tsch_slotframe_and_link.num_links);
681 LOG_INFO_LLADDR((
const linkaddr_t *)&frame.
src_addr);
687 LOG_ERR(
"! did not associate.\n");
702 static struct etimer scan_timer;
704 static clock_time_t current_channel_since;
711 while(!tsch_is_associated && !tsch_is_coordinator) {
713 static uint8_t current_channel = 0;
717 int is_packet_pending = 0;
721 if(current_channel == 0 || now_time - current_channel_since > TSCH_CHANNEL_SCAN_DURATION) {
723 uint8_t scan_channel = TSCH_JOIN_HOPPING_SEQUENCE[
724 random_rand() %
sizeof(TSCH_JOIN_HOPPING_SEQUENCE)];
726 NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, scan_channel);
727 current_channel = scan_channel;
728 LOG_INFO(
"scanning on channel %u\n", scan_channel);
730 current_channel_since = now_time;
736 is_packet_pending = NETSTACK_RADIO.pending_packet();
737 if(!is_packet_pending && NETSTACK_RADIO.receiving_packet()) {
743 if(is_packet_pending) {
746 input_eb.len = NETSTACK_RADIO.read(input_eb.payload, TSCH_PACKET_MAX_LEN);
749 NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &t0,
sizeof(rtimer_clock_t));
753 LOG_INFO(
"scan: received packet (%u bytes) on channel %u\n", input_eb.len, current_channel);
756 if(ABS(RTIMER_CLOCK_DIFF(t0, t1)) < tsch_timing[tsch_ts_timeslot_length]) {
757 tsch_associate(&input_eb, t0);
759 LOG_WARN(
"scan: dropping packet, timestamp too far from current time %u %u\n",
766 if(tsch_is_associated) {
768 NETSTACK_RADIO.off();
769 }
else if(!tsch_is_coordinator) {
783 static struct pt scan_pt;
789 while(!tsch_is_associated) {
790 if(tsch_is_coordinator) {
792 tsch_start_coordinator();
806 LOG_WARN(
"leaving the network, stats: tx %lu, rx %lu, sync %lu\n",
807 tx_count, rx_count, sync_count);
820 static struct etimer eb_timer;
826 while(!tsch_is_associated) {
832 if(!tsch_is_coordinator) {
840 if(tsch_is_associated && tsch_current_eb_period > 0) {
844 uint8_t tsch_sync_ie_offset;
850 LOG_ERR(
"! could not enqueue EB packet\n");
852 LOG_INFO(
"TSCH: enqueue EB packet %u %u\n",
854 p->tsch_sync_ie_offset = tsch_sync_ie_offset;
855 p->header_len = hdr_len;
860 if(tsch_current_eb_period > 0) {
863 delay = (tsch_current_eb_period - tsch_current_eb_period / 4)
866 delay = TSCH_EB_PERIOD;
882 tsch_rx_process_pending();
883 tsch_tx_process_pending();
885 #ifdef TSCH_CALLBACK_SELECT_CHANNELS 886 TSCH_CALLBACK_SELECT_CHANNELS();
903 if(TSCH_DEFAULT_TIMESLOT_TIMING == NULL) {
904 LOG_ERR(
"! platform does not provide a timeslot timing template.\n");
909 if(NETSTACK_RADIO.get_value(RADIO_PARAM_RX_MODE, &radio_rx_mode) != RADIO_RESULT_OK) {
910 LOG_ERR(
"! radio does not support getting RADIO_PARAM_RX_MODE. Abort init.\n");
916 radio_rx_mode &= ~RADIO_RX_MODE_AUTOACK;
918 radio_rx_mode |= RADIO_RX_MODE_POLL_MODE;
919 if(NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE, radio_rx_mode) != RADIO_RESULT_OK) {
920 LOG_ERR(
"! radio does not support setting required RADIO_PARAM_RX_MODE. Abort init.\n");
925 if(NETSTACK_RADIO.get_value(RADIO_PARAM_TX_MODE, &radio_tx_mode) != RADIO_RESULT_OK) {
926 LOG_ERR(
"! radio does not support getting RADIO_PARAM_TX_MODE. Abort init.\n");
931 if(NETSTACK_RADIO.set_value(RADIO_PARAM_TX_MODE, radio_tx_mode) != RADIO_RESULT_OK) {
932 LOG_ERR(
"! radio does not support setting required RADIO_PARAM_TX_MODE. Abort init.\n");
936 if(NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, TSCH_DEFAULT_HOPPING_SEQUENCE[0]) != RADIO_RESULT_OK) {
937 LOG_ERR(
"! radio does not support setting channel. Abort init.\n");
941 if(NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &t,
sizeof(rtimer_clock_t)) != RADIO_RESULT_OK) {
942 LOG_ERR(
"! radio does not support getting last packet timestamp. Abort init.\n");
946 if(TSCH_HOPPING_SEQUENCE_MAX_LEN <
sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE)) {
947 LOG_ERR(
"! TSCH_HOPPING_SEQUENCE_MAX_LEN < sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE). Abort init.\n");
959 #if TSCH_AUTOSELECT_TIME_SOURCE 960 nbr_table_register(sync_stats, NULL);
964 tsch_is_initialized = 1;
985 const linkaddr_t *
addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
986 uint8_t max_transmissions = 0;
988 if(!tsch_is_associated) {
989 if(!tsch_is_initialized) {
990 LOG_WARN(
"! not initialized (see earlier logs), drop outgoing packet\n");
992 LOG_WARN(
"! not associated, drop outgoing packet\n");
995 mac_call_sent_callback(sent, ptr, ret, 1);
1003 if(++tsch_packet_seqno == 0) {
1004 tsch_packet_seqno++;
1006 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, tsch_packet_seqno);
1007 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
1012 addr = &tsch_broadcast_address;
1015 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
1017 #if LLSEC802154_ENABLED 1018 if(tsch_is_pan_secured) {
1020 packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, TSCH_SECURITY_KEY_SEC_LEVEL_OTHER);
1021 packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, FRAME802154_1_BYTE_KEY_ID_MODE);
1022 packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, TSCH_SECURITY_KEY_INDEX_OTHER);
1026 #if !NETSTACK_CONF_BRIDGE_MODE 1035 max_transmissions = packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
1036 if(max_transmissions == 0) {
1038 max_transmissions = TSCH_MAC_MAX_FRAME_RETRIES + 1;
1041 if((hdr_len = NETSTACK_FRAMER.create()) < 0) {
1042 LOG_ERR(
"! can't send packet due to framer error\n");
1049 LOG_ERR(
"! can't send packet to ");
1050 LOG_ERR_LLADDR(addr);
1051 LOG_ERR_(
" with seqno %u, queue %u %u\n",
1055 p->header_len = hdr_len;
1056 LOG_INFO(
"send packet to ");
1057 LOG_INFO_LLADDR(addr);
1058 LOG_INFO_(
" with seqno %u, queue %u %u, len %u %u\n",
1061 p->header_len, queuebuf_datalen(p->qb));
1065 mac_call_sent_callback(sent, ptr, ret, 1);
1072 int frame_parsed = 1;
1074 frame_parsed = NETSTACK_FRAMER.parse();
1076 if(frame_parsed < 0) {
1082 if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO) != 0xffff) {
1087 LOG_WARN(
"! drop dup ll from ");
1088 LOG_WARN_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
1089 LOG_WARN_(
" seqno %u\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
1096 LOG_INFO(
"received from ");
1097 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
1098 LOG_INFO_(
" with seqno %u\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
1099 #if TSCH_WITH_SIXTOP 1102 NETSTACK_NETWORK.input();
1110 if(tsch_is_initialized == 1 && tsch_is_started == 0) {
1111 tsch_is_started = 1;
1118 LOG_INFO(
"starting as %s\n", tsch_is_coordinator ?
"coordinator":
"node");
1127 NETSTACK_RADIO.off();
uint16_t src_pid
Source PAN ID.
#define TSCH_ASN_DIVISOR_INIT(div, val_)
Initialize a struct asn_divisor_t.
int tsch_queue_global_packet_count(void)
Returns the number of packets currently in all TSCH queues.
void process_post_synch(struct process *p, process_event_t ev, process_data_t data)
Post a synchronous event to a process.
#define PROCESS(name, strname)
Declare a process.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
void ringbufindex_init(struct ringbufindex *r, uint8_t size)
Initialize a ring buffer.
void tsch_log_process_pending(void)
Process pending log messages.
int tsch_packet_create_eb(uint8_t *hdr_len, uint8_t *tsch_sync_ie_offset)
Create an EB packet directly in packetbuf.
int(* on)(void)
Turn the MAC layer on.
frame802154_fcf_t fcf
Frame control field.
The MAC layer transmission could not be performed because of a fatal error.
void packetbuf_clear(void)
Clear and reset the packetbuf.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
int ringbufindex_peek_get(const struct ringbufindex *r)
Return the index of the first element which will be removed if calling ringbufindex_get.
int tsch_schedule_init(void)
Module initialization, call only once at init.
The structure of a MAC protocol driver in Contiki.
void tsch_set_join_priority(uint8_t jp)
Set the TSCH join priority (JP)
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
Header file for the radio API
#define PROCESS_BEGIN()
Define the beginning of a process.
uint8_t security_enabled
1 bit.
void tsch_log_init(void)
Initialize log module.
#define PROCESS_END()
Define the end of a process.
static void send_packet(linkaddr_t *dest)
This function is called by the 6lowpan code to send out a packet.
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
int mac_sequence_is_duplicate(void)
Tell whether the packetbuf is a duplicate packet.
TSCH neighbor information.
802.15.4e slotframe (contains links)
void tsch_queue_init(void)
Initialize TSCH queue module.
#define PT_BEGIN(pt)
Declare the start of a protothread inside the C function implementing the protothread.
unsigned int tsch_security_parse_frame(const uint8_t *hdr, int hdrlen, int datalen, const frame802154_t *frame, const linkaddr_t *sender, struct tsch_asn_t *asn)
Parse and check a frame protected with encryption and/or MIC.
struct tsch_neighbor * tsch_queue_get_time_source(void)
Get the TSCH time source (we currently assume there is only one)
#define PT_WAIT_UNTIL(pt, condition)
Block and wait until condition is true.
void tsch_set_ka_timeout(uint32_t timeout)
Set the desynchronization timeout after which a node sends a unicasst keep-alive (KA) to its time sou...
void tsch_schedule_keepalive_immediately(void)
Schedule a keep-alive immediately.
uint8_t packetbuf_hdrlen(void)
Get the length of the header in the packetbuf.
struct tsch_slotframe * tsch_schedule_add_slotframe(uint16_t handle, uint16_t size)
Creates and adds a new slotframe.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
uint8_t src_addr[8]
Source address.
void tsch_schedule_keepalive(void)
Schedule a keep-alive transmission within [timeout*0.9, timeout[.
A MAC framer for IEEE 802.15.4
const linkaddr_t linkaddr_null
The null link-layer address.
Header file for MAC sequence numbers management
void tsch_queue_free_unused_neighbors(void)
Deallocate all neighbors with empty queue.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
void sixtop_init(void)
Initialize 6top module This initialization function removes all the SFs which has been installed into...
#define RTIMER_NOW()
Get the current clock time.
void sixtop_input(void)
Input a packet stored in packetbuf.
unsigned int tsch_security_mic_len(const frame802154_t *frame)
Return MIC length.
#define CLOCK_SECOND
A second, measured in system clock time.
For quick modulo operation on ASN.
#define PT_END(pt)
Declare the end of a protothread.
struct tsch_neighbor * tsch_queue_add_nbr(const linkaddr_t *addr)
Add a TSCH neighbor queue.
Header file for the Packet queue buffer management
void tsch_set_eb_period(uint32_t period)
Set the period at wich TSCH enhanced beacons (EBs) are sent.
uint8_t frame_version
2 bit.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
int tsch_queue_update_time_source(const linkaddr_t *new_addr)
Update TSCH time source.
The MAC layer transmission could not be performed because of an error.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Routing driver header file
Main API declarations for TSCH.
int packetbuf_copyfrom(const void *from, uint16_t len)
Copy from external data into the packetbuf.
clock_time_t clock_time(void)
Get the current clock time.
#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time)
Busy-wait until a condition.
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
struct tsch_link * tsch_schedule_add_link(struct tsch_slotframe *slotframe, uint8_t link_options, enum link_type link_type, const linkaddr_t *address, uint16_t timeslot, uint16_t channel_offset)
Adds a link to a slotframe.
#define TSCH_ASN_INIT(asn, ms1b_, ls4b_)
Initialize ASN.
#define RADIO_RX_MODE_ADDRESS_FILTER
The radio reception mode controls address filtering and automatic transmission of acknowledgements in...
void tsch_slot_operation_sync(rtimer_clock_t next_slot_start, struct tsch_asn_t *next_slot_asn)
Set global time before starting slot operation, with a rtimer time and an ASN.
The MAC layer deferred the transmission for a later time.
Parameters used by the frame802154_create() function.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a link-layer address.
#define PT_THREAD(name_args)
Declaration of a protothread.
6TiSCH Operation Sublayer (6top) APIs
#define RADIO_TX_MODE_SEND_ON_CCA
The radio transmission mode controls whether transmissions should be done using clear channel assessm...
#define TSCH_ASN_DIFF(asn1, asn2)
Returns the 32-bit diff between asn1 and asn2.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
void tsch_queue_reset(void)
Reset neighbor queues module.
void(* send)(mac_callback_t sent_callback, void *ptr)
Send a packet from the packetbuf.
int tsch_schedule_remove_all_slotframes(void)
Removes all slotframes, resulting in an empty schedule.
int tsch_queue_packet_count(const linkaddr_t *addr)
Returns the number of packets currently a given neighbor queue.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
int ringbufindex_get(struct ringbufindex *r)
Remove the first element and return its index.
void tsch_disassociate(void)
Leave the TSCH network we are currently in.
void tsch_set_pan_secured(int enable)
Enable/disable security.
Header file for the Packet buffer (packetbuf) management
Include file for the Contiki low-layer network stack (NETSTACK)
void mac_sequence_register_seqno(void)
Register the sequence number of the packetbuf.
#define PROCESS_PT_SPAWN(pt, thread)
Spawn a protothread from the process.
void tsch_queue_free_packet(struct tsch_packet *p)
Free a packet.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
struct tsch_packet * tsch_queue_add_packet(const linkaddr_t *addr, uint8_t max_transmissions, mac_callback_t sent, void *ptr)
Add packet to neighbor queue.
void etimer_reset(struct etimer *et)
Reset an event timer with the same interval as was previously set.
Header file for the logging system
void tsch_slot_operation_start(void)
Start actual slot operation.
int tsch_packet_parse_eb(const uint8_t *buf, int buf_size, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len, int frame_without_mic)
Parse EB.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
The ASN is an absolute slot number over 5 bytes.
void tsch_schedule_create_minimal(void)
Create a 6tisch minimal schedule with length TSCH_SCHEDULE_DEFAULT_LENGTH.
#define PROCESS_WAIT_UNTIL(c)
Wait for a condition to occur.
void tsch_set_coordinator(int enable)
Set the node as PAN coordinator.
void process_start(struct process *p, process_data_t data)
Start a process.