Contiki 3.x
oma-tlv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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 oma-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 OAM_TLV_H_
43 #define OAM_TLV_H_
44 
45 #include "contiki.h"
46 
47 enum {
48  OMA_TLV_TYPE_OBJECT_INSTANCE = 0,
49  OMA_TLV_TYPE_RESOURCE_INSTANCE = 1,
50  OMA_TLV_TYPE_MULTI_RESOURCE = 2,
51  OMA_TLV_TYPE_RESOURCE = 3
52 };
53 typedef uint8_t oma_tlv_type_t;
54 
55 typedef enum {
56  OMA_TLV_LEN_TYPE_NO_LEN = 0,
57  OMA_TLV_LEN_TYPE_8BIT_LEN = 1,
58  OMA_TLV_LEN_TYPE_16BIT_LEN = 2,
59  OMA_TLV_LEN_TYPE_24BIT_LEN = 3
60 } oma_tlv_len_type_t;
61 
62 typedef struct {
63  oma_tlv_type_t type;
64  uint16_t id; /* can be 8-bit or 16-bit when serialized */
65  uint32_t length;
66  const uint8_t *value;
67 } oma_tlv_t;
68 
69 size_t oma_tlv_get_size(const oma_tlv_t *tlv);
70 
71 /* read a TLV from the buffer */
72 size_t oma_tlv_read(oma_tlv_t *tlv, const uint8_t *buffer, size_t len);
73 
74 /* write a TLV to the buffer */
75 size_t oma_tlv_write(const oma_tlv_t *tlv, uint8_t *buffer, size_t len);
76 
77 int32_t oma_tlv_get_int32(const oma_tlv_t *tlv);
78 
79 /* write a int as a TLV to the buffer */
80 size_t oma_tlv_write_int32(int16_t id, int32_t value, uint8_t *buffer, size_t len);
81 
82 /* write a float converted from fixpoint as a TLV to the buffer */
83 size_t oma_tlv_write_float32(int16_t id, int32_t value, int bits, uint8_t *buffer, size_t len);
84 
85 /* convert TLV with float32 to fixpoint */
86 size_t oma_tlv_float32_to_fix(const oma_tlv_t *tlv, int32_t *value, int bits);
87 
88 #endif /* OAM_TLV_H_ */
89 /** @} */