Contiki 3.x
tsch.h
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 #ifndef __TSCH_H__
34 #define __TSCH_H__
35 
36 /********** Includes **********/
37 
38 #include "contiki.h"
39 #include "net/mac/mac.h"
40 #include "net/mac/tsch/tsch-security.h"
41 
42 /******** Configuration *******/
43 
44 /* Max time before sending a unicast keep-alive message to the time source */
45 #ifdef TSCH_CONF_KEEPALIVE_TIMEOUT
46 #define TSCH_KEEPALIVE_TIMEOUT TSCH_CONF_KEEPALIVE_TIMEOUT
47 #else
48 /* Time to desynch assuming a drift of 40 PPM (80 PPM between two nodes) and guard time of +/-1ms: 12.5s. */
49 #define TSCH_KEEPALIVE_TIMEOUT (12 * CLOCK_SECOND)
50 #endif
51 
52 /* Max time without synchronization before leaving the PAN */
53 #ifdef TSCH_CONF_DESYNC_THRESHOLD
54 #define TSCH_DESYNC_THRESHOLD TSCH_CONF_DESYNC_THRESHOLD
55 #else
56 #define TSCH_DESYNC_THRESHOLD (4 * TSCH_KEEPALIVE_TIMEOUT)
57 #endif
58 
59 /* Period between two consecutive EBs */
60 #ifdef TSCH_CONF_EB_PERIOD
61 #define TSCH_EB_PERIOD TSCH_CONF_EB_PERIOD
62 #else
63 #define TSCH_EB_PERIOD (4 * CLOCK_SECOND)
64 #endif
65 
66 /* Max acceptable join priority */
67 #ifdef TSCH_CONF_MAX_JOIN_PRIORITY
68 #define TSCH_MAX_JOIN_PRIORITY TSCH_CONF_MAX_JOIN_PRIORITY
69 #else
70 #define TSCH_MAX_JOIN_PRIORITY 32
71 #endif
72 
73 /* Start TSCH automatically after init? If not, the upper layers
74  * must call NETSTACK_MAC.on() to start it. Useful when the
75  * application needs to control when the nodes are to start
76  * scanning or advertising.*/
77 #ifdef TSCH_CONF_AUTOSTART
78 #define TSCH_AUTOSTART TSCH_CONF_AUTOSTART
79 #else
80 #define TSCH_AUTOSTART 1
81 #endif
82 
83 /* Join only secured networks? (discard EBs with security disabled) */
84 #ifdef TSCH_CONF_JOIN_SECURED_ONLY
85 #define TSCH_JOIN_SECURED_ONLY TSCH_CONF_JOIN_SECURED_ONLY
86 #else
87 /* By default, set if LLSEC802154_ENABLED is also non-zero */
88 #define TSCH_JOIN_SECURED_ONLY LLSEC802154_ENABLED
89 #endif
90 
91 /* By default, join any PAN ID. Otherwise, wait for an EB from IEEE802154_PANID */
92 #ifdef TSCH_CONF_JOIN_MY_PANID_ONLY
93 #define TSCH_JOIN_MY_PANID_ONLY TSCH_CONF_JOIN_MY_PANID_ONLY
94 #else
95 #define TSCH_JOIN_MY_PANID_ONLY 0
96 #endif
97 
98 /* The radio polling frequency (in Hz) during association process */
99 #ifdef TSCH_CONF_ASSOCIATION_POLL_FREQUENCY
100 #define TSCH_ASSOCIATION_POLL_FREQUENCY TSCH_CONF_ASSOCIATION_POLL_FREQUENCY
101 #else
102 #define TSCH_ASSOCIATION_POLL_FREQUENCY 100
103 #endif
104 
105 /* When associating, check ASN against our own uptime (time in minutes)..
106  * Useful to force joining only with nodes started roughly at the same time.
107  * Set to the max number of minutes acceptable. */
108 #ifdef TSCH_CONF_CHECK_TIME_AT_ASSOCIATION
109 #define TSCH_CHECK_TIME_AT_ASSOCIATION TSCH_CONF_CHECK_TIME_AT_ASSOCIATION
110 #else
111 #define TSCH_CHECK_TIME_AT_ASSOCIATION 0
112 #endif
113 
114 /* By default: initialize schedule from EB when associating, using the
115  * slotframe and links Information Element */
116 #ifdef TSCH_CONF_INIT_SCHEDULE_FROM_EB
117 #define TSCH_INIT_SCHEDULE_FROM_EB TSCH_CONF_INIT_SCHEDULE_FROM_EB
118 #else
119 #define TSCH_INIT_SCHEDULE_FROM_EB 1
120 #endif
121 
122 /* An ad-hoc mechanism to have TSCH select its time source without the
123  * help of an upper-layer, simply by collecting statistics on received
124  * EBs and their join priority. Disabled by default as we recomment
125  * mapping the time source on the RPL preferred parent
126  * (via tsch_rpl_callback_parent_switch) */
127 #ifdef TSCH_CONF_AUTOSELECT_TIME_SOURCE
128 #define TSCH_AUTOSELECT_TIME_SOURCE TSCH_CONF_AUTOSELECT_TIME_SOURCE
129 #else
130 #define TSCH_AUTOSELECT_TIME_SOURCE 0
131 #endif /* TSCH_CONF_EB_AUTOSELECT */
132 
133 /*********** Callbacks *********/
134 
135 /* Called by TSCH when joining a network */
136 #ifdef TSCH_CALLBACK_JOINING_NETWORK
137 void TSCH_CALLBACK_JOINING_NETWORK();
138 #endif
139 
140 /* Called by TSCH when leaving a network */
141 #ifdef TSCH_CALLBACK_LEAVING_NETWORK
142 void TSCH_CALLBACK_LEAVING_NETWORK();
143 #endif
144 
145 /***** External Variables *****/
146 
147 /* Are we coordinator of the TSCH network? */
148 extern int tsch_is_coordinator;
149 /* Are we associated to a TSCH network? */
150 extern int tsch_is_associated;
151 /* Is the PAN running link-layer security? */
152 extern int tsch_is_pan_secured;
153 /* The TSCH MAC driver */
154 extern const struct mac_driver tschmac_driver;
155 
156 /********** Functions *********/
157 
158 /* The the TSCH join priority */
159 void tsch_set_join_priority(uint8_t jp);
160 /* The the period at which EBs are sent */
161 void tsch_set_eb_period(uint32_t period);
162 /* Set the node as PAN coordinator */
163 void tsch_set_coordinator(int enable);
164 /* Set the pan as secured or not */
165 void tsch_set_pan_secured(int enable);
166 
167 #endif /* __TSCH_H__ */
MAC driver header file
The structure of a MAC protocol driver in Contiki.
Definition: mac.h:54