Contiki-NG
tsch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, SICS Swedish ICT.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34 * \ingroup link-layer
35 * \defgroup tsch 802.15.4 TSCH
36 The IEEE 802.15.4-2015 TimeSlotted Channel Hopping (TSCH) protocol. Provides
37 scheduled communication on top of a globally-synchronized network. Performs
38 frequency hopping for enhanced reliability.
39 * @{
40 * \file
41 * Main API declarations for TSCH.
42 */
43 
44 #ifndef __TSCH_H__
45 #define __TSCH_H__
46 
47 /********** Includes **********/
48 
49 #include "contiki.h"
50 #include "net/mac/mac.h"
51 #include "net/linkaddr.h"
52 
53 #include "net/mac/tsch/tsch-conf.h"
59 #include "net/mac/tsch/tsch-log.h"
64 #if UIP_CONF_IPV6_RPL
65 #include "net/mac/tsch/tsch-rpl.h"
66 #endif /* UIP_CONF_IPV6_RPL */
67 
68 
69 /* Include Arch-Specific conf */
70 #ifdef TSCH_CONF_ARCH_HDR_PATH
71 #include TSCH_CONF_ARCH_HDR_PATH
72 #endif /* TSCH_CONF_ARCH_HDR_PATH */
73 
74 /*********** Callbacks *********/
75 
76 /* Link callbacks to RPL in case RPL is enabled */
77 #if UIP_CONF_IPV6_RPL
78 
79 #ifndef TSCH_CALLBACK_JOINING_NETWORK
80 #define TSCH_CALLBACK_JOINING_NETWORK tsch_rpl_callback_joining_network
81 #endif /* TSCH_CALLBACK_JOINING_NETWORK */
82 
83 #ifndef TSCH_CALLBACK_LEAVING_NETWORK
84 #define TSCH_CALLBACK_LEAVING_NETWORK tsch_rpl_callback_leaving_network
85 #endif /* TSCH_CALLBACK_LEAVING_NETWORK */
86 
87 #ifndef TSCH_CALLBACK_KA_SENT
88 #define TSCH_CALLBACK_KA_SENT tsch_rpl_callback_ka_sent
89 #endif /* TSCH_CALLBACK_KA_SENT */
90 
91 #endif /* UIP_CONF_IPV6_RPL */
92 
93 #if BUILD_WITH_ORCHESTRA
94 
95 #ifndef TSCH_CALLBACK_NEW_TIME_SOURCE
96 #define TSCH_CALLBACK_NEW_TIME_SOURCE orchestra_callback_new_time_source
97 #endif /* TSCH_CALLBACK_NEW_TIME_SOURCE */
98 
99 #ifndef TSCH_CALLBACK_PACKET_READY
100 #define TSCH_CALLBACK_PACKET_READY orchestra_callback_packet_ready
101 #endif /* TSCH_CALLBACK_PACKET_READY */
102 
103 #endif /* BUILD_WITH_ORCHESTRA */
104 
105 /* Called by TSCH when joining a network */
106 #ifdef TSCH_CALLBACK_JOINING_NETWORK
107 void TSCH_CALLBACK_JOINING_NETWORK();
108 #endif
109 
110 /* Called by TSCH when leaving a network */
111 #ifdef TSCH_CALLBACK_LEAVING_NETWORK
112 void TSCH_CALLBACK_LEAVING_NETWORK();
113 #endif
114 
115 /* Called by TSCH after sending a keep-alive */
116 #ifdef TSCH_CALLBACK_KA_SENT
117 void TSCH_CALLBACK_KA_SENT();
118 #endif
119 
120 /* Called by TSCH form interrupt after receiving a frame, enabled upper-layer to decide
121  * whether to ACK or NACK */
122 #ifdef TSCH_CALLBACK_DO_NACK
123 int TSCH_CALLBACK_DO_NACK(struct tsch_link *link, linkaddr_t *src, linkaddr_t *dst);
124 #endif
125 
126 /* Called by TSCH when switching time source */
127 #ifdef TSCH_CALLBACK_NEW_TIME_SOURCE
128 struct tsch_neighbor;
129 void TSCH_CALLBACK_NEW_TIME_SOURCE(const struct tsch_neighbor *old, const struct tsch_neighbor *new);
130 #endif
131 
132 /* Called by TSCH every time a packet is ready to be added to the send queue */
133 #ifdef TSCH_CALLBACK_PACKET_READY
134 void TSCH_CALLBACK_PACKET_READY(void);
135 #endif
136 
137 /***** External Variables *****/
138 
139 /* Are we coordinator of the TSCH network? */
140 extern int tsch_is_coordinator;
141 /* Are we associated to a TSCH network? */
142 extern int tsch_is_associated;
143 /* Is the PAN running link-layer security? */
144 extern int tsch_is_pan_secured;
145 /* The TSCH MAC driver */
146 extern const struct mac_driver tschmac_driver;
147 /* 802.15.4 broadcast MAC address */
148 extern const linkaddr_t tsch_broadcast_address;
149 /* The address we use to identify EB queue */
150 extern const linkaddr_t tsch_eb_address;
151 /* The current Absolute Slot Number (ASN) */
152 extern struct tsch_asn_t tsch_current_asn;
153 extern uint8_t tsch_join_priority;
154 extern struct tsch_link *current_link;
155 /* If we are inside a slot, this tells the current channel */
156 extern uint8_t tsch_current_channel;
157 /* TSCH channel hopping sequence */
158 extern uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN];
159 extern struct tsch_asn_divisor_t tsch_hopping_sequence_length;
160 /* TSCH timeslot timing (in micro-second) */
161 extern uint16_t tsch_timing_us[tsch_ts_elements_count];
162 /* TSCH timeslot timing (in rtimer ticks) */
163 extern rtimer_clock_t tsch_timing[tsch_ts_elements_count];
164 /* Statistics on the current session */
165 extern unsigned long tx_count;
166 extern unsigned long rx_count;
167 extern unsigned long sync_count;
168 extern int32_t min_drift_seen;
169 extern int32_t max_drift_seen;
170 /* The TSCH standard 10ms timeslot timing */
171 extern const uint16_t tsch_timeslot_timing_us_10000[tsch_ts_elements_count];
172 
173 /* TSCH processes */
174 PROCESS_NAME(tsch_process);
175 PROCESS_NAME(tsch_send_eb_process);
176 PROCESS_NAME(tsch_pending_events_process);
177 
178 
179 /********** Functions *********/
180 
181 /**
182  * Set the TSCH join priority (JP)
183  *
184  * \param jp the new join priority
185  */
186 void tsch_set_join_priority(uint8_t jp);
187 /**
188  * Set the period at wich TSCH enhanced beacons (EBs) are sent. The period can
189  * not be set to exceed TSCH_MAX_EB_PERIOD. Set to 0 to stop sending EBs.
190  * Actual transmissions are jittered, spaced by a random number within
191  * [period*0.75, period[
192  *
193  * \param period The period in Clock ticks.
194  */
195 void tsch_set_eb_period(uint32_t period);
196 /**
197  * Set the desynchronization timeout after which a node sends a unicasst
198  * keep-alive (KA) to its time source. Set to 0 to stop sending KAs. The
199  * actual timeout is a random number within
200  * [timeout*0.9, timeout[
201  *
202  * \param timeout The timeout in Clock ticks.
203  */
204 void tsch_set_ka_timeout(uint32_t timeout);
205 /**
206  * Set the node as PAN coordinator
207  *
208  * \param enable 1 to be coordinator, 0 to be a node
209  */
210 void tsch_set_coordinator(int enable);
211 /**
212  * Enable/disable security. If done at the coordinator, the Information
213  * will be included in EBs, and all nodes will adopt the same security level.
214  * Enabling requires compilation with LLSEC802154_ENABLED set.
215  * Note: when LLSEC802154_ENABLED is set, nodes boot with security enabled.
216  *
217  * \param enable 1 to enable security, 0 to disable it
218  */
219 void tsch_set_pan_secured(int enable);
220 /**
221  * Schedule a keep-alive transmission within [timeout*0.9, timeout[
222  * @see tsch_set_ka_timeout
223  */
224 void tsch_schedule_keepalive(void);
225 /**
226  * Schedule a keep-alive immediately
227  */
229 /**
230  * Leave the TSCH network we are currently in
231  */
232 void tsch_disassociate(void);
233 
234 #endif /* __TSCH_H__ */
235 /** @} */
TSCH constants.
TSCH configuration.
TSCH queues.
TSCH types.
TSCH-RPL interaction.
The structure of a MAC protocol driver in Contiki.
Definition: mac.h:62
void tsch_set_join_priority(uint8_t jp)
Set the TSCH join priority (JP)
Definition: tsch.c:184
Header file for the link-layer address representation
TSCH neighbor information.
Definition: tsch-types.h:109
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...
Definition: tsch.c:190
void tsch_schedule_keepalive_immediately(void)
Schedule a keep-alive immediately.
Definition: tsch.c:319
TSCH runtime operation within timeslots.
void tsch_schedule_keepalive(void)
Schedule a keep-alive transmission within [timeout*0.9, timeout[.
Definition: tsch.c:307
For quick modulo operation on ASN.
Definition: tsch-asn.h:54
void tsch_set_eb_period(uint32_t period)
Set the period at wich TSCH enhanced beacons (EBs) are sent.
Definition: tsch.c:201
#define PROCESS_NAME(name)
Declare the name of a process.
Definition: process.h:286
TSCH adaptive time synchronization.
TSCH security.
Header file for TSCH statistics
const uint16_t tsch_timeslot_timing_us_10000[tsch_ts_elements_count]
The default timeslot timing in the standard is a guard time of 2200 us, a Tx offset of 2120 us and a ...
void tsch_disassociate(void)
Leave the TSCH network we are currently in.
Definition: tsch.c:510
void tsch_set_pan_secured(int enable)
Enable/disable security.
Definition: tsch.c:178
TSCH packet parsing and creation.
TSCH scheduling engine.
The ASN is an absolute slot number over 5 bytes.
Definition: tsch-asn.h:48
MAC driver header file
void tsch_set_coordinator(int enable)
Set the node as PAN coordinator.
Definition: tsch.c:168
TSCH per-slot logging.