Contiki 3.x
tsch-packet.h
1 /*
2  * Copyright (c) 2014, 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_PACKET_H__
34 #define __TSCH_PACKET_H__
35 
36 /********** Includes **********/
37 
38 #include "contiki.h"
39 #include "net/packetbuf.h"
41 #include "net/mac/frame802154.h"
43 
44 /******** Configuration *******/
45 
46 /* TSCH EB: include timeslot timing Information Element? */
47 #ifdef TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING
48 #define TSCH_PACKET_EB_WITH_TIMESLOT_TIMING TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING
49 #else
50 #define TSCH_PACKET_EB_WITH_TIMESLOT_TIMING 0
51 #endif
52 
53 /* TSCH EB: include hopping sequence Information Element? */
54 #ifdef TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE
55 #define TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE
56 #else
57 #define TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE 0
58 #endif
59 
60 /* TSCH EB: include slotframe and link Information Element? */
61 #ifdef TSCH_PACKET_CONF_EB_WITH_SLOTFRAME_AND_LINK
62 #define TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK TSCH_PACKET_CONF_EB_WITH_SLOTFRAME_AND_LINK
63 #else
64 #define TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK 0
65 #endif
66 
67 /* Include source address in ACK? */
68 #ifdef TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR
69 #define TSCH_PACKET_EACK_WITH_SRC_ADDR TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR
70 #else
71 #define TSCH_PACKET_EACK_WITH_SRC_ADDR 0
72 #endif
73 
74 /* Include destination address in ACK? */
75 #ifdef TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR
76 #define TSCH_PACKET_EACK_WITH_DEST_ADDR TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR
77 #else
78 #define TSCH_PACKET_EACK_WITH_DEST_ADDR 1 /* Include destination address
79 by default, useful in case of duplicate seqno */
80 #endif
81 
82 /********** Constants *********/
83 
84 /* Max TSCH packet lenght */
85 #define TSCH_PACKET_MAX_LEN MIN(127,PACKETBUF_SIZE)
86 
87 /********** Functions *********/
88 
89 /* Construct enhanced ACK packet and return ACK length */
90 int tsch_packet_create_eack(uint8_t *buf, int buf_size,
91  linkaddr_t *dest_addr, uint8_t seqno, int16_t drift, int nack);
92 /* Parse enhanced ACK packet, extract drift and nack */
93 int tsch_packet_parse_eack(const uint8_t *buf, int buf_size,
94  uint8_t seqno, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len);
95 /* Create an EB packet */
96 int tsch_packet_create_eb(uint8_t *buf, int buf_size,
97  uint8_t seqno, uint8_t *hdr_len, uint8_t *tsch_sync_ie_ptr);
98 /* Update ASN in EB packet */
99 int tsch_packet_update_eb(uint8_t *buf, int buf_size, uint8_t tsch_sync_ie_offset);
100 /* Parse EB and extract ASN and join priority */
101 int tsch_packet_parse_eb(const uint8_t *buf, int buf_size,
102  frame802154_t *frame, struct ieee802154_ies *ies,
103  uint8_t *hdrlen, int frame_without_mic);
104 
105 #endif /* __TSCH_PACKET_H__ */
Private TSCH definitions (meant for use by TSCH implementation files only) ...
Header file for the Rime buffer (packetbuf) management
IEEE 802.15.4e Information Element (IE) creation and parsing.
802.15.4 frame creation and parsing functions
Parameters used by the frame802154_create() function.
Definition: frame802154.h:192