Contiki-NG
lwm2m-tlv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, Yanzi Networks AB.
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 copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /** \addtogroup lwm2m
32  * @{ */
33 
34 /**
35  * \file
36  * Header file for the Contiki OMA LWM2M TLV
37  * \author
38  * Joakim Eriksson <joakime@sics.se>
39  * Niclas Finne <nfi@sics.se>
40  */
41 
42 #ifndef LWM2M_TLV_H_
43 #define LWM2M_TLV_H_
44 
45 #include <stdint.h>
46 #include <stddef.h>
47 
48 enum {
49  LWM2M_TLV_TYPE_OBJECT_INSTANCE = 0,
50  LWM2M_TLV_TYPE_RESOURCE_INSTANCE = 1,
51  LWM2M_TLV_TYPE_MULTI_RESOURCE = 2,
52  LWM2M_TLV_TYPE_RESOURCE = 3
53 };
54 typedef uint8_t lwm2m_tlv_type_t;
55 
56 typedef enum {
57  LWM2M_TLV_LEN_TYPE_NO_LEN = 0,
58  LWM2M_TLV_LEN_TYPE_8BIT_LEN = 1,
59  LWM2M_TLV_LEN_TYPE_16BIT_LEN = 2,
60  LWM2M_TLV_LEN_TYPE_24BIT_LEN = 3
61 } lwm2m_tlv_len_type_t;
62 
63 typedef struct {
64  lwm2m_tlv_type_t type;
65  uint16_t id; /* can be 8-bit or 16-bit when serialized */
66  uint32_t length;
67  const uint8_t *value;
68 } lwm2m_tlv_t;
69 
70 size_t lwm2m_tlv_get_size(const lwm2m_tlv_t *tlv);
71 
72 /* read a TLV from the buffer */
73 size_t lwm2m_tlv_read(lwm2m_tlv_t *tlv, const uint8_t *buffer, size_t len);
74 
75 /* write a TLV to the buffer */
76 size_t lwm2m_tlv_write(const lwm2m_tlv_t *tlv, uint8_t *buffer, size_t len);
77 
78 int32_t lwm2m_tlv_get_int32(const lwm2m_tlv_t *tlv);
79 
80 /* write a int as a TLV to the buffer */
81 size_t lwm2m_tlv_write_int32(uint8_t type, int16_t id, int32_t value, uint8_t *buffer, size_t len);
82 
83 /* write a float converted from fixpoint as a TLV to the buffer */
84 size_t lwm2m_tlv_write_float32(uint8_t type, int16_t id, int32_t value, int bits, uint8_t *buffer, size_t len);
85 
86 /* convert TLV with float32 to fixpoint */
87 size_t lwm2m_tlv_float32_to_fix(const lwm2m_tlv_t *tlv, int32_t *value, int bits);
88 
89 #endif /* LWM2M_TLV_H_ */
90 /** @} */