1 /**
2  * @file lwm2m_obj_gateway.h
3  * @brief
4  *
5  * Copyright (c) 2021 Laird Connectivity
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 #ifndef __LWM2M_OBJ_GATEWAY__
10 #define __LWM2M_OBJ_GATEWAY__
11 
12 #include <lwm2m_object.h>
13 
14 /* LwM2M Gateway resource IDs */
15 /* clang-format off */
16 #define LWM2M_GATEWAY_DEVICE_RID             0
17 #define LWM2M_GATEWAY_PREFIX_RID             1
18 #define LWM2M_GATEWAY_DEPRECATED_RID         2
19 #define LWM2M_GATEWAY_IOT_DEVICE_OBJECTS_RID 3
20 /* clang-format on */
21 
22 /**
23  * @brief A callback which handles the prefixed messages from the server.
24  *
25  * The callback gets triggered each time the prefix in front of a received lwm2m
26  * msg path matches the prefix set in the LWM2M_GATEWAY_PREFIX_RID buffer.
27  *
28  * It must handle the content of the coap message completely.
29  * In case of success the LwM2M engine will then send the formatted coap message,
30  * otherwise a coap response code is sent.
31  *
32  * Example of returning CoAP response:
33  * @code{.c}
34  * lwm2m_init_message(msg);
35  * // Write CoAP packet to msg->out.out_cpkt
36  * return 0;
37  * @endcode
38  *
39  *
40  * @return 0 if msg contains a  valid CoAP response.
41  * @return  negative error code otherwise.
42  */
43 typedef int (*lwm2m_engine_gateway_msg_cb)(struct lwm2m_message *msg);
44 /**
45  * @brief Register a callback which handles the prefixed messages from the server.
46  *
47  * @return 0 on success
48  * @return -ENOENT if no object instance with obj_inst_id was found
49  */
50 int lwm2m_register_gw_callback(uint16_t obj_inst_id, lwm2m_engine_gateway_msg_cb cb);
51 /**
52  * @brief Check if given message is handled by Gateway callback.
53  *
54  * @return 0 if msg was handled by Gateawy and contains a valid response. Negative error code
55  * otherwise.
56  * @return -ENOENT if this msg was not handled by Gateway object.
57  */
58 int lwm2m_gw_handle_req(struct lwm2m_message *msg);
59 
60 #endif /* __LWM2M_OBJ_GATEWAY__ */
61