Add support for IEEE 802.15.4e Information Elements (IEs). All IEs used by TSCH are currently included.
This commit is contained in:
parent
5cf9871d5b
commit
ecba49c282
5 changed files with 1088 additions and 0 deletions
97
core/net/mac/tsch/tsch-asn.h
Normal file
97
core/net/mac/tsch/tsch-asn.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2015, SICS Swedish ICT.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* TSCH 5-Byte Absolute Slot Number (ASN) management
|
||||
* \author
|
||||
* Simon Duquennoy <simonduq@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __TSCH_ASN_H__
|
||||
#define __TSCH_ASN_H__
|
||||
|
||||
/************ Types ***********/
|
||||
|
||||
/* The ASN is an absolute slot number over 5 bytes. */
|
||||
struct asn_t {
|
||||
uint32_t ls4b; /* least significant 4 bytes */
|
||||
uint8_t ms1b; /* most significant 1 byte */
|
||||
};
|
||||
|
||||
/* For quick modulo operation on ASN */
|
||||
struct asn_divisor_t {
|
||||
uint16_t val; /* Divisor value */
|
||||
uint16_t asn_ms1b_remainder; /* Remainder of the operation 0x100000000 / val */
|
||||
};
|
||||
|
||||
/************ Macros **********/
|
||||
|
||||
/* Initialize ASN */
|
||||
#define ASN_INIT(asn, ms1b_, ls4b_) do { \
|
||||
(asn).ms1b = (ms1b_); \
|
||||
(asn).ls4b = (ls4b_); \
|
||||
} while(0);
|
||||
|
||||
/* Increment an ASN by inc (32 bits) */
|
||||
#define ASN_INC(asn, inc) do { \
|
||||
uint32_t new_ls4b = (asn).ls4b + (inc); \
|
||||
if(new_ls4b < (asn).ls4b) { (asn).ms1b++; } \
|
||||
(asn).ls4b = new_ls4b; \
|
||||
} while(0);
|
||||
|
||||
/* Decrement an ASN by inc (32 bits) */
|
||||
#define ASN_DEC(asn, dec) do { \
|
||||
uint32_t new_ls4b = (asn).ls4b - (dec); \
|
||||
if(new_ls4b > (asn).ls4b) { (asn).ms1b--; } \
|
||||
(asn).ls4b = new_ls4b; \
|
||||
} while(0);
|
||||
|
||||
/* Returns the 32-bit diff between asn1 and asn2 */
|
||||
#define ASN_DIFF(asn1, asn2) \
|
||||
((asn1).ls4b - (asn2).ls4b)
|
||||
|
||||
/* Initialize a struct asn_divisor_t */
|
||||
#define ASN_DIVISOR_INIT(div, val_) do { \
|
||||
(div).val = (val_); \
|
||||
(div).asn_ms1b_remainder = ((0xffffffff % (val_)) + 1) % (val_); \
|
||||
} while(0);
|
||||
|
||||
/* Returns the result (16 bits) of a modulo operation on ASN,
|
||||
* with divisor being a struct asn_divisor_t */
|
||||
#define ASN_MOD(asn, div) \
|
||||
((uint16_t)((asn).ls4b % (div).val) \
|
||||
+ (uint16_t)((asn).ms1b * (div).asn_ms1b_remainder % (div).val)) \
|
||||
% (div).val
|
||||
|
||||
#endif /* __TSCH_ASN_H__ */
|
171
core/net/mac/tsch/tsch-conf.h
Normal file
171
core/net/mac/tsch/tsch-conf.h
Normal file
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* Copyright (c) 2015, SICS Swedish ICT.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* TSCH configuration
|
||||
* \author
|
||||
* Simon Duquennoy <simonduq@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __TSCH_CONF_H__
|
||||
#define __TSCH_CONF_H__
|
||||
|
||||
/********** Includes **********/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
/******** Configuration *******/
|
||||
|
||||
/* Default IEEE 802.15.4e hopping sequences, obtained from https://gist.github.com/twatteyne/2e22ee3c1a802b685695 */
|
||||
/* 16 channels, sequence length 16 */
|
||||
#define TSCH_HOPPING_SEQUENCE_16_16 (uint8_t[]){ 16, 17, 23, 18, 26, 15, 25, 22, 19, 11, 12, 13, 24, 14, 20, 21 }
|
||||
/* 4 channels, sequence length 16 */
|
||||
#define TSCH_HOPPING_SEQUENCE_4_16 (uint8_t[]){ 20, 26, 25, 26, 15, 15, 25, 20, 26, 15, 26, 25, 20, 15, 20, 25 }
|
||||
/* 4 channels, sequence length 4 */
|
||||
#define TSCH_HOPPING_SEQUENCE_4_4 (uint8_t[]){ 15, 25, 26, 20 }
|
||||
/* 1 channel, sequence length 1 */
|
||||
#define TSCH_HOPPING_SEQUENCE_1_1 (uint8_t[]){ 20 }
|
||||
|
||||
/* Default hopping sequence, used in case hopping sequence ID == 0 */
|
||||
#ifdef TSCH_CONF_DEFAULT_HOPPING_SEQUENCE
|
||||
#define TSCH_DEFAULT_HOPPING_SEQUENCE TSCH_CONF_DEFAULT_HOPPING_SEQUENCE
|
||||
#else
|
||||
#define TSCH_DEFAULT_HOPPING_SEQUENCE TSCH_HOPPING_SEQUENCE_4_4
|
||||
#endif
|
||||
|
||||
/* Hopping sequence used for joining (scan channels) */
|
||||
#ifdef TSCH_CONF_JOIN_HOPPING_SEQUENCE
|
||||
#define TSCH_JOIN_HOPPING_SEQUENCE TSCH_CONF_JOIN_HOPPING_SEQUENCE
|
||||
#else
|
||||
#define TSCH_JOIN_HOPPING_SEQUENCE TSCH_DEFAULT_HOPPING_SEQUENCE
|
||||
#endif
|
||||
|
||||
/* Maximum length of the TSCH channel hopping sequence. Must be greater or
|
||||
* equal to the length of TSCH_DEFAULT_HOPPING_SEQUENCE. */
|
||||
#ifdef TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN
|
||||
#define TSCH_HOPPING_SEQUENCE_MAX_LEN TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN
|
||||
#else
|
||||
#define TSCH_HOPPING_SEQUENCE_MAX_LEN 16
|
||||
#endif
|
||||
|
||||
/* Timeslot timing */
|
||||
|
||||
#ifndef TSCH_CONF_DEFAULT_TIMESLOT_LENGTH
|
||||
#define TSCH_CONF_DEFAULT_TIMESLOT_LENGTH 10000
|
||||
#endif /* TSCH_CONF_DEFAULT_TIMESLOT_LENGTH */
|
||||
|
||||
/* Configurable Rx guard time is micro-seconds */
|
||||
#ifndef TSCH_CONF_RX_WAIT
|
||||
#define TSCH_CONF_RX_WAIT 2200
|
||||
#endif /* TSCH_CONF_RX_WAIT */
|
||||
|
||||
/* The default timeslot timing in the standard is a guard time of
|
||||
* 2200 us, a Tx offset of 2120 us and a Rx offset of 1120 us.
|
||||
* As a result, the listening device has a guard time not centered
|
||||
* on the expected Tx time. This is to be fixed in the next iteration
|
||||
* of the standard. This can be enabled with:
|
||||
* #define TSCH_DEFAULT_TS_TX_OFFSET 2120
|
||||
* #define TSCH_DEFAULT_TS_RX_OFFSET 1120
|
||||
* #define TSCH_DEFAULT_TS_RX_WAIT 2200
|
||||
*
|
||||
* Instead, we align the Rx guard time on expected Tx time. The Rx
|
||||
* guard time is user-configurable with TSCH_CONF_RX_WAIT.
|
||||
|
||||
* (TS_TX_OFFSET - (TS_RX_WAIT / 2)) instead */
|
||||
|
||||
#if TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 10000
|
||||
/* Default timeslot timing as per IEEE 802.15.4e */
|
||||
|
||||
#define TSCH_DEFAULT_TS_CCA_OFFSET 1800
|
||||
#define TSCH_DEFAULT_TS_CCA 128
|
||||
#define TSCH_DEFAULT_TS_TX_OFFSET 2120
|
||||
#define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2))
|
||||
#define TSCH_DEFAULT_TS_RX_ACK_DELAY 800
|
||||
#define TSCH_DEFAULT_TS_TX_ACK_DELAY 1000
|
||||
#define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT
|
||||
#define TSCH_DEFAULT_TS_ACK_WAIT 400
|
||||
#define TSCH_DEFAULT_TS_RX_TX 192
|
||||
#define TSCH_DEFAULT_TS_MAX_ACK 2400
|
||||
#define TSCH_DEFAULT_TS_MAX_TX 4256
|
||||
#define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 10000
|
||||
|
||||
#elif TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 15000
|
||||
/* Default timeslot timing for platfroms requiring 15ms slots */
|
||||
|
||||
#define TSCH_DEFAULT_TS_CCA_OFFSET 1800
|
||||
#define TSCH_DEFAULT_TS_CCA 128
|
||||
#define TSCH_DEFAULT_TS_TX_OFFSET 4000
|
||||
#define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2))
|
||||
#define TSCH_DEFAULT_TS_RX_ACK_DELAY 3600
|
||||
#define TSCH_DEFAULT_TS_TX_ACK_DELAY 4000
|
||||
#define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT
|
||||
#define TSCH_DEFAULT_TS_ACK_WAIT 800
|
||||
#define TSCH_DEFAULT_TS_RX_TX 2072
|
||||
#define TSCH_DEFAULT_TS_MAX_ACK 2400
|
||||
#define TSCH_DEFAULT_TS_MAX_TX 4256
|
||||
#define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 15000
|
||||
|
||||
#elif TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 65000
|
||||
/* 65ms timeslot, i.e. nearly the max length allowed by standard (16-bit unsigned in micro-seconds).
|
||||
* Useful for running link-layer security on sky or z1 in Cooja, where only S/W security is supported.
|
||||
* Note: this slot timing would require a total of 120ms. If a slot overlaps with the next active slot,
|
||||
* the latter will be skipped.
|
||||
* This configuration is mostly a work-around to test link-layer security in Cooja, it is recommended
|
||||
* to use it with a 6TiSCH minimal schedule of length >= 2. */
|
||||
|
||||
#define TSCH_DEFAULT_TS_CCA_OFFSET 1800
|
||||
#define TSCH_DEFAULT_TS_CCA 128
|
||||
#define TSCH_DEFAULT_TS_TX_OFFSET 52000
|
||||
#define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2))
|
||||
#define TSCH_DEFAULT_TS_RX_ACK_DELAY 58600
|
||||
#define TSCH_DEFAULT_TS_TX_ACK_DELAY 59000
|
||||
#define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT
|
||||
#define TSCH_DEFAULT_TS_ACK_WAIT 800
|
||||
#define TSCH_DEFAULT_TS_RX_TX 2072
|
||||
#define TSCH_DEFAULT_TS_MAX_ACK 2400
|
||||
#define TSCH_DEFAULT_TS_MAX_TX 4256
|
||||
#define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 65000
|
||||
|
||||
#else
|
||||
#error "TSCH: Unsupported default timeslot length"
|
||||
#endif
|
||||
|
||||
/* A custom feature allowing upper layers to assign packets to
|
||||
* a specific slotframe and link */
|
||||
#ifdef TSCH_CONF_WITH_LINK_SELECTOR
|
||||
#define TSCH_WITH_LINK_SELECTOR TSCH_CONF_WITH_LINK_SELECTOR
|
||||
#else /* TSCH_CONF_WITH_LINK_SELECTOR */
|
||||
#define TSCH_WITH_LINK_SELECTOR 0
|
||||
#endif /* TSCH_CONF_WITH_LINK_SELECTOR */
|
||||
|
||||
#endif /* __TSCH_CONF_H__ */
|
115
core/net/mac/tsch/tsch-private.h
Normal file
115
core/net/mac/tsch/tsch-private.h
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2014, SICS Swedish ICT.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Private TSCH definitions
|
||||
* (meant for use by TSCH implementation files only)
|
||||
* \author
|
||||
* Simon Duquennoy <simonduq@sics.se>
|
||||
* Beshr Al Nahas <beshr@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __TSCH_PRIVATE_H__
|
||||
#define __TSCH_PRIVATE_H__
|
||||
|
||||
/********** Includes **********/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/linkaddr.h"
|
||||
#include "net/mac/tsch/tsch-asn.h"
|
||||
#include "net/mac/tsch/tsch-conf.h"
|
||||
|
||||
/************ Types ***********/
|
||||
|
||||
/* TSCH timeslot timing elements. Used to index timeslot timing
|
||||
* of different units, such as rtimer tick or micro-second */
|
||||
enum tsch_timeslot_timing_elements {
|
||||
tsch_ts_cca_offset,
|
||||
tsch_ts_cca,
|
||||
tsch_ts_tx_offset,
|
||||
tsch_ts_rx_offset,
|
||||
tsch_ts_rx_ack_delay,
|
||||
tsch_ts_tx_ack_delay,
|
||||
tsch_ts_rx_wait,
|
||||
tsch_ts_ack_wait,
|
||||
tsch_ts_rx_tx,
|
||||
tsch_ts_max_ack,
|
||||
tsch_ts_max_tx,
|
||||
tsch_ts_timeslot_length,
|
||||
tsch_ts_elements_count, /* Not a timing element */
|
||||
};
|
||||
|
||||
/***** External Variables *****/
|
||||
|
||||
/* 802.15.4 broadcast MAC address */
|
||||
extern const linkaddr_t tsch_broadcast_address;
|
||||
/* The address we use to identify EB queue */
|
||||
extern const linkaddr_t tsch_eb_address;
|
||||
/* The current Absolute Slot Number (ASN) */
|
||||
extern struct asn_t current_asn;
|
||||
extern uint8_t tsch_join_priority;
|
||||
extern struct tsch_link *current_link;
|
||||
/* TSCH channel hopping sequence */
|
||||
extern uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN];
|
||||
extern struct asn_divisor_t tsch_hopping_sequence_length;
|
||||
/* TSCH timeslot timing (in rtimer ticks) */
|
||||
extern rtimer_clock_t tsch_timing[tsch_ts_elements_count];
|
||||
|
||||
/* TSCH processes */
|
||||
PROCESS_NAME(tsch_process);
|
||||
PROCESS_NAME(tsch_send_eb_process);
|
||||
PROCESS_NAME(tsch_pending_events_process);
|
||||
|
||||
/********** Functions *********/
|
||||
|
||||
/* Set TSCH to send a keepalive message after TSCH_KEEPALIVE_TIMEOUT */
|
||||
void tsch_schedule_keepalive(void);
|
||||
/* Leave the TSCH network */
|
||||
void tsch_disassociate(void);
|
||||
|
||||
/************ Macros **********/
|
||||
|
||||
/* Calculate packet tx/rx duration in rtimer ticks based on sent
|
||||
* packet len in bytes with 802.15.4 250kbps data rate.
|
||||
* One byte = 32us. Add two bytes for CRC and one for len field */
|
||||
#define TSCH_PACKET_DURATION(len) US_TO_RTIMERTICKS(32 * ((len) + 3))
|
||||
|
||||
/* Convert rtimer ticks to clock and vice versa */
|
||||
#define TSCH_CLOCK_TO_TICKS(c) (((c) * RTIMER_SECOND) / CLOCK_SECOND)
|
||||
#define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length)
|
||||
|
||||
/* Wait for a condition with timeout t0+offset. */
|
||||
#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \
|
||||
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ;
|
||||
|
||||
#endif /* __TSCH_PRIVATE_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue