Contiki-NG
tsch-packet.h
Go to the documentation of this file.
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 /**
34  * \addtogroup tsch
35  * @{
36  * \file
37  * TSCH packet parsing and creation. EBs and EACKs.
38 */
39 
40 #ifndef __TSCH_PACKET_H__
41 #define __TSCH_PACKET_H__
42 
43 /********** Includes **********/
44 
45 #include "contiki.h"
48 
49 /********** Functions *********/
50 
51 /**
52  * \brief Construct Enhanced ACK packet
53  * \param buf The buffer where to build the EACK
54  * \param buf_size The buffer size
55  * \param dest_addr The link-layer address of the neighbor we are ACKing
56  * \param seqno The sequence number we are ACKing
57  * \param drift The time offset in usec measured at Rx of the packer we are ACKing
58  * \param nack Value of the NACK bit
59  * \return The length of the packet that was created. -1 if failure.
60  */
61 int tsch_packet_create_eack(uint8_t *buf, uint16_t buf_size,
62  const linkaddr_t *dest_addr, uint8_t seqno,
63  int16_t drift, int nack);
64 /**
65  * \brief Parse enhanced ACK packet
66  * \param buf The buffer where to parse the EACK from
67  * \param buf_size The buffer size
68  * \param seqno The sequence number we are expecting
69  * \param frame The frame structure where to store parsed fields
70  * \param ies The IE structure where to store parsed IEs
71  * \param hdr_len A pointer where to store the length of the parsed header
72  * \return 1 if the EACK is correct and acknowledges the specified frame, 0 otherwise
73  */
74 int tsch_packet_parse_eack(const uint8_t *buf, int buf_size,
75  uint8_t seqno, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len);
76 /**
77  * \brief Create an EB packet directly in packetbuf
78  * \param hdr_len A pointer where to store the length of the created header
79  * \param tsch_sync_ie_ptr A pointer where to store the address of the TSCH synchronization IE
80  * \return The total length of the EB
81  */
82 int tsch_packet_create_eb(uint8_t *hdr_len, uint8_t *tsch_sync_ie_ptr);
83 /**
84  * \brief Update ASN in EB packet
85  * \param buf The buffer that contains the EB
86  * \param buf_size The buffer size
87  * \param tsch_sync_ie_offset The offset of the TSCH synchronization IE, in which the ASN is to be written
88  * \return 1 if success, 0 otherwise
89  */
90 int tsch_packet_update_eb(uint8_t *buf, int buf_size, uint8_t tsch_sync_ie_offset);
91 /**
92  * \brief Parse EB
93  * \param buf The buffer where to parse the EB from
94  * \param buf_size The buffer sizecting
95  * \param frame The frame structure where to store parsed fields
96  * \param ies The IE structure where to store parsed IEs
97  * \param hdrlen A pointer where to store the length of the parsed header
98  * \param frame_without_mic When set, the security MIC will not be parsed
99  * \return The length of the parsed EB
100  */
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  * \brief Set frame pending bit in a packet (whose header was already build)
106  * \param buf The buffer where the packet resides
107  * \param buf_size The buffer size
108  */
109 void tsch_packet_set_frame_pending(uint8_t *buf, int buf_size);
110 /**
111  * \brief Get frame pending bit from a packet
112  * \param buf The buffer where the packet resides
113  * \param buf_size The buffer size
114  * \return The value of the frame pending bit, 1 or 0
115  */
116 int tsch_packet_get_frame_pending(uint8_t *buf, int buf_size);
117 /**
118  * \brief Set a packet attribute for the current eack. We not use standard
119  * packetbuf for eacks because these are generated from interrupt context.
120  * \param type The attribute identifier
121  * \param val The attribute value
122  */
123 void tsch_packet_eackbuf_set_attr(uint8_t type, const packetbuf_attr_t val);
124 /**
125  * \brief Return the value of a specified attribute
126  * \param type The attribute identifier
127  * \return The attribute value
128  */
129 packetbuf_attr_t tsch_packet_eackbuf_attr(uint8_t type);
130 
131 #endif /* __TSCH_PACKET_H__ */
132 /** @} */
int tsch_packet_create_eb(uint8_t *hdr_len, uint8_t *tsch_sync_ie_offset)
Create an EB packet directly in packetbuf.
Definition: tsch-packet.c:220
IEEE 802.15.4e Information Element (IE) creation and parsing.
int tsch_packet_update_eb(uint8_t *buf, int buf_size, uint8_t tsch_sync_ie_offset)
Update ASN in EB packet.
Definition: tsch-packet.c:377
int tsch_packet_parse_eack(const uint8_t *buf, int buf_size, uint8_t seqno, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len)
Parse enhanced ACK packet.
Definition: tsch-packet.c:155
void tsch_packet_eackbuf_set_attr(uint8_t type, const packetbuf_attr_t val)
Set a packet attribute for the current eack.
Definition: tsch-packet.c:78
802.15.4 frame creation and parsing functions
Parameters used by the frame802154_create() function.
Definition: frame802154.h:198
void tsch_packet_set_frame_pending(uint8_t *buf, int buf_size)
Set frame pending bit in a packet (whose header was already build)
Definition: tsch-packet.c:454
int tsch_packet_get_frame_pending(uint8_t *buf, int buf_size)
Get frame pending bit from a packet.
Definition: tsch-packet.c:461
packetbuf_attr_t tsch_packet_eackbuf_attr(uint8_t type)
Return the value of a specified attribute.
Definition: tsch-packet.c:86
int tsch_packet_parse_eb(const uint8_t *buf, int buf_size, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len, int frame_without_mic)
Parse EB.
Definition: tsch-packet.c:387
int tsch_packet_create_eack(uint8_t *buf, uint16_t buf_len, const linkaddr_t *dest_addr, uint8_t seqno, int16_t drift, int nack)
Construct Enhanced ACK packet.
Definition: tsch-packet.c:93