Contiki-NG
lwm2m-engine.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/**
32 * \addtogroup lwm2m
33 * @{
34 */
35
36/**
37 * \file
38 * Header file for the Contiki OMA LWM2M engine
39 * \author
40 * Joakim Eriksson <joakime@sics.se>
41 * Niclas Finne <nfi@sics.se>
42 * Carlos Gonzalo Peces <carlosgp143@gmail.com>
43 */
44
45#ifndef LWM2M_ENGINE_H
46#define LWM2M_ENGINE_H
47
48#include "lwm2m-object.h"
50
51#define LWM2M_FLOAT32_BITS 10
52#define LWM2M_FLOAT32_FRAC (1L << LWM2M_FLOAT32_BITS)
53
54/* LWM2M / CoAP Content-Formats */
55typedef enum {
56 LWM2M_TEXT_PLAIN = 1541,
57 LWM2M_TLV = 11542,
58 LWM2M_JSON = 11543,
59 LWM2M_OLD_TLV = 1542,
60 LWM2M_OLD_JSON = 1543,
61 LWM2M_OLD_OPAQUE = 1544
62} lwm2m_content_format_t;
63
64void lwm2m_engine_init(void);
65
66int lwm2m_engine_set_rd_data(lwm2m_buffer_t *outbuf, int block);
67
68typedef lwm2m_status_t
69(* lwm2m_object_instance_callback_t)(lwm2m_object_instance_t *object,
70 lwm2m_context_t *ctx);
71typedef int
72(* lwm2m_resource_dim_callback_t)(lwm2m_object_instance_t *object,
73 uint16_t resource_id);
74
75#define LWM2M_OBJECT_INSTANCE_NONE 0xffff
76
77struct lwm2m_object_instance {
78 lwm2m_object_instance_t *next;
79 uint16_t object_id;
80 uint16_t instance_id;
81 /* an array of resource IDs for discovery, etc */
82 const lwm2m_resource_id_t *resource_ids;
83 uint16_t resource_count;
84 /* the callback for requests */
85 lwm2m_object_instance_callback_t callback;
86 lwm2m_resource_dim_callback_t resource_dim_callback;
87};
88
89typedef struct {
90 uint16_t object_id;
91 lwm2m_object_instance_t *(* create_instance)(uint16_t instance_id,
92 lwm2m_status_t *status);
93 int (* delete_instance)(uint16_t instance_id, lwm2m_status_t *status);
94 lwm2m_object_instance_t *(* get_first)(lwm2m_status_t *status);
95 lwm2m_object_instance_t *(* get_next)(lwm2m_object_instance_t *instance,
96 lwm2m_status_t *status);
97 lwm2m_object_instance_t *(* get_by_id)(uint16_t instance_id,
98 lwm2m_status_t *status);
99} lwm2m_object_impl_t;
100
101typedef struct lwm2m_object lwm2m_object_t;
102struct lwm2m_object {
103 lwm2m_object_t *next;
104 const lwm2m_object_impl_t *impl;
105};
106
107lwm2m_object_instance_t *lwm2m_engine_get_instance_buffer(void);
108
109int lwm2m_engine_has_instance(uint16_t object_id, uint16_t instance_id);
110int lwm2m_engine_add_object(lwm2m_object_instance_t *object);
111void lwm2m_engine_remove_object(lwm2m_object_instance_t *object);
112int lwm2m_engine_add_generic_object(lwm2m_object_t *object);
113void lwm2m_engine_remove_generic_object(lwm2m_object_t *object);
114void lwm2m_notify_object_observers(lwm2m_object_instance_t *obj,
115 uint16_t resource);
116
117void lwm2m_engine_set_opaque_callback(lwm2m_context_t *ctx, lwm2m_write_opaque_callback cb);
118
119#endif /* LWM2M_ENGINE_H */
120/** @} */
Header file for the LWM2M object API.
Queue Mode Configuration Parameters.