Contiki-NG
uipbuf.h
1 /*
2  * Copyright (c) 2017, RISE SICS, Yanzi Networks
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. The name of the authors may not be used to endorse or promote
14  * products derived from this software without specific prior
15  * written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28  * DAMAGE.
29  *
30  *
31  */
32 
33 #ifndef UIPBUF_H_
34 #define UIPBUF_H_
35 
36 #include "contiki.h"
37 
38 /**
39  * \brief Get the next IPv6 header.
40  * \param buffer A pointer to the buffer holding the IPv6 packet
41  * \param size The size of the data in the buffer
42  * \param protocol A pointer to a variable where the protocol of the header will be stored
43  * \param start A flag that indicates if this is expected to be the IPv6 packet header or a later header (Extension header)
44  * \retval returns address of the starting position of the next header
45  *
46  * This function moves to the next header in a IPv6 packet.
47  */
48 uint8_t* uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, uint8_t start);
49 
50 
51 /**
52  * \brief Get the last IPv6 header.
53  * \param buffer A pointer to the buffer holding the IPv6 packet
54  * \param size The size of the data in the buffer
55  * \param protocol A pointer to a variable where the protocol of the header will be stored
56  * \retval returns address of the starting position of the next header
57  *
58  * This function moves to the last header of the IPv6 packet.
59  */
60 uint8_t* uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol);
61 
62 
63 /**
64  * \brief Get the value of the attribute
65  * \param type The attribute to get the value of
66  * \retval the value of the attribute
67  *
68  * This function gets the value of a specific uipbuf attribute.
69  */
70 uint16_t uipbuf_get_attr(uint8_t type);
71 
72 
73 /**
74  * \brief Set the value of the attribute
75  * \param type The attribute to set the value of
76  * \param value The value to set
77  * \retval 0 - indicates failure of setting the value
78  * \retval 1 - indicates success of setting the value
79  *
80  * This function sets the value of a specific uipbuf attribute.
81  */
82 int uipbuf_set_attr(uint8_t type, uint16_t value);
83 
84 /**
85  * \brief Set bits in the uipbuf attribute flags.
86  * \param flag_bits The bits to set in the flag.
87  *
88  * This function sets the uipbuf attributes flag of specified bits.
89  */
90 void uipbuf_set_attr_flag(uint16_t flag_bits);
91 
92 /**
93  * \brief Clear bits in the uipbuf attribute flags.
94  * \param flag_bits The bits to clear in the flag.
95  *
96  * This function clears the uipbuf attributes flag of specified bits.
97  */
98 void uipbuf_clr_attr_flag(uint16_t flag_bits);
99 
100 /**
101  * \brief Check if bits in the uipbuf attribute flag are set.
102  * \param flag_bits The bits to check in the flag.
103  *
104  * This function checks if the specified bits are set in the
105  * uipbuf attributes flag.
106  */
107 uint16_t uipbuf_is_attr_flag(uint16_t flag_bits);
108 
109 
110 /**
111  * \brief Clear all attributes.
112  *
113  * This function clear all attributes in the uipbuf attributes
114  * including all flags.
115  */
116 void uipbuf_clear_attr(void);
117 
118 /**
119  * \brief The bits defined for uipbuf attributes flag.
120  *
121  */
122 /* Avoid using NHC compression on the packet (6LoWPAN) */
123 #define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_NHC_COMPRESSION 0x01
124 /* Avoid using prefix compression on the packet (6LoWPAN) */
125 #define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_PREFIX_COMPRESSION 0x02
126 
127 /**
128  * \brief The attributes defined for uipbuf attributes function.
129  *
130  */
131 enum {
132  UIPBUF_ATTR_LLSEC_LEVEL, /**< Control link layer security level. */
133  UIPBUF_ATTR_LLSEC_KEY_ID, /**< Control link layer security key ID. */
134  UIPBUF_ATTR_INTERFACE_ID, /**< The interface to output packet on */
135  UIPBUF_ATTR_PHYSICAL_NETWORK_ID, /**< Physical network ID (mapped to PAN ID)*/
136  UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, /**< MAX transmissions of the packet MAC */
137  UIPBUF_ATTR_FLAGS, /**< Flags that can control lower layers. see above. */
138  UIPBUF_ATTR_MAX
139 };
140 
141 #endif /* UIPBUF_H_ */
static bool start(void)
Start measurement.