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"
37struct uip_ip_hdr;
38
39/**
40 * \brief Resets uIP buffer
41 */
42void uipbuf_clear(void);
43
44/**
45 * \brief Update uip buffer length for addition of an extension header
46 * \param len The length of the new extension header
47 * \retval true if the length fields were successfully set, false otherwise
48 */
49bool uipbuf_add_ext_hdr(int16_t len);
50
51/**
52 * \brief Set the length of the uIP buffer
53 * \param len The new length
54 * \retval true if the len was successfully set, false otherwise
55 */
56bool uipbuf_set_len(uint16_t len);
57
58/**
59 * \brief Updates the length field in the uIP buffer
60 * \param hdr The IPv6 header
61 * \param len The new length value
62 */
63void uipbuf_set_len_field(struct uip_ip_hdr *hdr, uint16_t len);
64
65/**
66 * \brief Returns the value of the length field in the uIP buffer
67 * \param hdr The IPv6 header
68 * \retval The length value
69 */
70uint16_t uipbuf_get_len_field(struct uip_ip_hdr *hdr);
71
72/**
73 * \brief Get the next IPv6 header.
74 * \param buffer A pointer to the buffer holding the IPv6 packet
75 * \param size The size of the data in the buffer
76 * \param protocol A pointer to a variable where the protocol of the header will be stored
77 * \param start A flag that indicates if this is expected to be the IPv6 packet header or a later header (Extension header)
78 * \retval returns address of the next header, or NULL in case of insufficient buffer space
79 *
80 * This function moves to the next header in a IPv6 packet.
81 */
82uint8_t *uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, bool start);
83
84
85/**
86 * \brief Get the last IPv6 header.
87 * \param buffer A pointer to the buffer holding the IPv6 packet
88 * \param size The size of the data in the buffer
89 * \param protocol A pointer to a variable where the protocol of the header will be stored
90 * \retval returns address of the last header, or NULL in case of insufficient buffer space
91 *
92 * This function moves to the last header of the IPv6 packet.
93 */
94uint8_t *uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol);
95
96/**
97 * \brief Get an IPv6 header with a given protocol field.
98 * \param buffer A pointer to the buffer holding the IPv6 packet
99 * \param size The size of the data in the buffer
100 * \param protocol The protocol we are looking for
101 * \retval returns address of the header if found, else NULL
102 *
103 * This function moves to the last header of the IPv6 packet.
104 */
105uint8_t *uipbuf_search_header(uint8_t *buffer, uint16_t size, uint8_t protocol);
106
107/**
108 * \brief Get the value of the attribute
109 * \param type The attribute to get the value of
110 * \retval the value of the attribute
111 *
112 * This function gets the value of a specific uipbuf attribute.
113 */
114uint16_t uipbuf_get_attr(uint8_t type);
115
116
117/**
118 * \brief Set the value of the attribute
119 * \param type The attribute to set the value of
120 * \param value The value to set
121 * \retval 0 - indicates failure of setting the value
122 * \retval 1 - indicates success of setting the value
123 *
124 * This function sets the value of a specific uipbuf attribute.
125 */
126int uipbuf_set_attr(uint8_t type, uint16_t value);
127
128/**
129 * \brief Set the default value of the attribute
130 * \param type The attribute to set the default value of
131 * \param value The value to set
132 * \retval 0 - indicates failure of setting the value
133 * \retval 1 - indicates success of setting the value
134 *
135 * This function sets the default value of a uipbuf attribute.
136 */
137int uipbuf_set_default_attr(uint8_t type, uint16_t value);
138
139/**
140 * \brief Set bits in the uipbuf attribute flags.
141 * \param flag_bits The bits to set in the flag.
142 *
143 * This function sets the uipbuf attributes flag of specified bits.
144 */
145void uipbuf_set_attr_flag(uint16_t flag_bits);
146
147/**
148 * \brief Clear bits in the uipbuf attribute flags.
149 * \param flag_bits The bits to clear in the flag.
150 *
151 * This function clears the uipbuf attributes flag of specified bits.
152 */
153void uipbuf_clr_attr_flag(uint16_t flag_bits);
154
155/**
156 * \brief Check if bits in the uipbuf attribute flag are set.
157 * \param flag_bits The bits to check in the flag.
158 *
159 * This function checks if the specified bits are set in the
160 * uipbuf attributes flag.
161 */
162uint16_t uipbuf_is_attr_flag(uint16_t flag_bits);
163
164
165/**
166 * \brief Clear all attributes.
167 *
168 * This function clear all attributes in the uipbuf attributes
169 * including all flags.
170 */
171void uipbuf_clear_attr(void);
172
173/**
174 * \brief Initialize uipbuf attributes.
175 *
176 * This function initialize all attributes in the uipbuf
177 * attributes including all flags.
178 */
179void uipbuf_init(void);
180
181/**
182 * \brief The bits defined for uipbuf attributes flag.
183 *
184 */
185/* Avoid using NHC compression on the packet (6LoWPAN) */
186#define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_NHC_COMPRESSION 0x01
187/* Avoid using prefix compression on the packet (6LoWPAN) */
188#define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_PREFIX_COMPRESSION 0x02
189
190
191/* Use this initial security level if defined */
192#ifdef UIPBUF_ATTR_LLSEC_STARTUP_LEVEL
193#define UIPBUF_ATTR_LLSEC_LEVEL_MAC_DEFAULT UIPBUF_ATTR_LLSEC_STARTUP_LEVEL
194#else
195/* Else MAC will set the default for this packet */
196#define UIPBUF_ATTR_LLSEC_LEVEL_MAC_DEFAULT 0xffff
197#endif
198
199
200/**
201 * \brief The attributes defined for uipbuf attributes function.
202 *
203 */
204enum {
205 UIPBUF_ATTR_LLSEC_LEVEL, /**< Control link layer security level. */
206 UIPBUF_ATTR_LLSEC_KEY_ID, /**< Control link layer security key ID. */
207 UIPBUF_ATTR_INTERFACE_ID, /**< The interface to output packet on */
208 UIPBUF_ATTR_PHYSICAL_NETWORK_ID, /**< Physical network ID (mapped to PAN ID)*/
209 UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, /**< MAX transmissions of the packet MAC */
210 UIPBUF_ATTR_FLAGS, /**< Flags that can control lower layers. see above. */
211 UIPBUF_ATTR_RSSI, /**< Last packet's RSSI */
212 UIPBUF_ATTR_LINK_QUALITY, /**< Last packet's LQI */
213 UIPBUF_ATTR_MAX
214};
215
216#endif /* UIPBUF_H_ */
static void start(void)
Start measurement.