Contiki-NG
tsch-types.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 * \addtogroup tsch
35 * @{
36  * \file
37  * TSCH types
38  * \author
39  * Simon Duquennoy <simonduq@sics.se>
40  */
41 
42 #ifndef __TSCH_TYPES_H__
43 #define __TSCH_TYPES_H__
44 
45 /********** Includes **********/
46 
47 #include "net/mac/tsch/tsch-asn.h"
48 #include "lib/list.h"
49 #include "lib/ringbufindex.h"
50 
51 /********** Data types **********/
52 
53 /** \brief 802.15.4e link types. LINK_TYPE_ADVERTISING_ONLY is an extra one: for EB-only links. */
54 enum link_type { LINK_TYPE_NORMAL, LINK_TYPE_ADVERTISING, LINK_TYPE_ADVERTISING_ONLY };
55 
56 /** \brief An IEEE 802.15.4-2015 TSCH link (also called cell or slot) */
57 struct tsch_link {
58  /* Links are stored as a list: "next" must be the first field */
59  struct tsch_link *next;
60  /* Unique identifier */
61  uint16_t handle;
62  /* MAC address of neighbor */
63  linkaddr_t addr;
64  /* Slotframe identifier */
65  uint16_t slotframe_handle;
66  /* Identifier of Slotframe to which this link belongs
67  * Unused. */
68  /* uint8_t handle; */
69  /* Timeslot for this link */
70  uint16_t timeslot;
71  /* Channel offset for this link */
72  uint16_t channel_offset;
73  /* A bit string that defines
74  * b0 = Transmit, b1 = Receive, b2 = Shared, b3 = Timekeeping, b4 = reserved */
75  uint8_t link_options;
76  /* Type of link. NORMAL = 0. ADVERTISING = 1, and indicates
77  the link may be used to send an Enhanced beacon. */
78  enum link_type link_type;
79  /* Any other data for upper layers */
80  void *data;
81 };
82 
83 /** \brief 802.15.4e slotframe (contains links) */
85  /* Slotframes are stored as a list: "next" must be the first field */
86  struct tsch_slotframe *next;
87  /* Unique identifier */
88  uint16_t handle;
89  /* Number of timeslots in the slotframe.
90  * Stored as struct asn_divisor_t because we often need ASN%size */
91  struct tsch_asn_divisor_t size;
92  /* List of links belonging to this slotframe */
93  LIST_STRUCT(links_list);
94 };
95 
96 /** \brief TSCH packet information */
97 struct tsch_packet {
98  struct queuebuf *qb; /* pointer to the queuebuf to be sent */
99  mac_callback_t sent; /* callback for this packet */
100  void *ptr; /* MAC callback parameter */
101  uint8_t transmissions; /* #transmissions performed for this packet */
102  uint8_t max_transmissions; /* maximal number of Tx before dropping the packet */
103  uint8_t ret; /* status -- MAC return code */
104  uint8_t header_len; /* length of header and header IEs (needed for link-layer security) */
105  uint8_t tsch_sync_ie_offset; /* Offset within the frame used for quick update of EB ASN and join priority */
106 };
107 
108 /** \brief TSCH neighbor information */
110  /* Neighbors are stored as a list: "next" must be the first field */
111  struct tsch_neighbor *next;
112  linkaddr_t addr; /* MAC address of the neighbor */
113  uint8_t is_broadcast; /* is this neighbor a virtual neighbor used for broadcast (of data packets or EBs) */
114  uint8_t is_time_source; /* is this neighbor a time source? */
115  uint8_t backoff_exponent; /* CSMA backoff exponent */
116  uint8_t backoff_window; /* CSMA backoff window (number of slots to skip) */
117  uint8_t last_backoff_window; /* Last CSMA backoff window */
118  uint8_t tx_links_count; /* How many links do we have to this neighbor? */
119  uint8_t dedicated_tx_links_count; /* How many dedicated links do we have to this neighbor? */
120  /* Array for the ringbuf. Contains pointers to packets.
121  * Its size must be a power of two to allow for atomic put */
122  struct tsch_packet *tx_array[TSCH_QUEUE_NUM_PER_NEIGHBOR];
123  /* Circular buffer of pointers to packet. */
124  struct ringbufindex tx_ringbuf;
125 };
126 
127 /** \brief TSCH timeslot timing elements. Used to index timeslot timing
128  * of different units, such as rtimer tick or micro-second */
130  tsch_ts_cca_offset,
131  tsch_ts_cca,
132  tsch_ts_tx_offset,
133  tsch_ts_rx_offset,
134  tsch_ts_rx_ack_delay,
135  tsch_ts_tx_ack_delay,
136  tsch_ts_rx_wait,
137  tsch_ts_ack_wait,
138  tsch_ts_rx_tx,
139  tsch_ts_max_ack,
140  tsch_ts_max_tx,
141  tsch_ts_timeslot_length,
142  tsch_ts_elements_count, /* Not a timing element */
143 };
144 
145 /** \brief TSCH timeslot timing elements in rtimer ticks */
146 typedef rtimer_clock_t tsch_timeslot_timing_ticks[tsch_ts_elements_count];
147 
148 /** \brief TSCH timeslot timing elements in micro-seconds */
149 typedef uint16_t tsch_timeslot_timing_usec[tsch_ts_elements_count];
150 
151 /** \brief Stores data about an incoming packet */
152 struct input_packet {
153  uint8_t payload[TSCH_PACKET_MAX_LEN]; /* Packet payload */
154  struct tsch_asn_t rx_asn; /* ASN when the packet was received */
155  int len; /* Packet len */
156  int16_t rssi; /* RSSI for this packet */
157  uint8_t channel; /* Channel we received the packet on */
158 };
159 
160 #endif /* __TSCH_CONF_H__ */
161 /** @} */
TSCH packet information.
Definition: tsch-types.h:97
Header file for the ringbufindex library
TSCH neighbor information.
Definition: tsch-types.h:109
802.15.4e slotframe (contains links)
Definition: tsch-types.h:84
tsch_timeslot_timing_elements
TSCH timeslot timing elements.
Definition: tsch-types.h:129
rtimer_clock_t tsch_timeslot_timing_ticks[tsch_ts_elements_count]
TSCH timeslot timing elements in rtimer ticks.
Definition: tsch-types.h:146
For quick modulo operation on ASN.
Definition: tsch-asn.h:54
Linked list manipulation routines.
link_type
802.15.4e link types.
Definition: tsch-types.h:54
#define LIST_STRUCT(name)
Declare a linked list inside a structure declaraction.
Definition: list.h:111
uint16_t tsch_timeslot_timing_usec[tsch_ts_elements_count]
TSCH timeslot timing elements in micro-seconds.
Definition: tsch-types.h:149
Stores data about an incoming packet.
Definition: tsch-types.h:152
The ASN is an absolute slot number over 5 bytes.
Definition: tsch-asn.h:48
TSCH 5-Byte Absolute Slot Number (ASN) management.