1 /*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #ifndef LWM2M_MESSAGE_HANDLING_H
7 #define LWM2M_MESSAGE_HANDLING_H
8 #include "lwm2m_object.h"
9 #include "lwm2m_observation.h"
10
11 /* LWM2M / CoAP Content-Formats */
12 #define LWM2M_FORMAT_PLAIN_TEXT 0
13 #define LWM2M_FORMAT_APP_LINK_FORMAT 40
14 #define LWM2M_FORMAT_APP_OCTET_STREAM 42
15 #define LWM2M_FORMAT_APP_EXI 47
16 #define LWM2M_FORMAT_APP_JSON 50
17 #define LWM2M_FORMAT_APP_CBOR 60
18 #define LWM2M_FORMAT_APP_SEML_JSON 110
19 #define LWM2M_FORMAT_APP_SENML_CBOR 112
20 #define LWM2M_FORMAT_OMA_PLAIN_TEXT 1541
21 #define LWM2M_FORMAT_OMA_OLD_TLV 1542
22 #define LWM2M_FORMAT_OMA_OLD_JSON 1543
23 #define LWM2M_FORMAT_OMA_OLD_OPAQUE 1544
24 #define LWM2M_FORMAT_OMA_TLV 11542
25 #define LWM2M_FORMAT_OMA_JSON 11543
26 /* 65000 ~ 65535 inclusive are reserved for experiments */
27 #define LWM2M_FORMAT_NONE 65535
28
29 #define COAP_RESPONSE_CODE_CLASS(x) (x >> 5)
30 #define COAP_RESPONSE_CODE_DETAIL(x) (x & 0x1F)
31
32 /* coap reply status */
33 #define COAP_REPLY_STATUS_NONE 0
34 #define COAP_REPLY_STATUS_ERROR 1
35
36 #define NUM_BLOCK1_CONTEXT CONFIG_LWM2M_NUM_BLOCK1_CONTEXT
37
38 #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER)
39 #define NUM_OUTPUT_BLOCK_CONTEXT CONFIG_LWM2M_NUM_OUTPUT_BLOCK_CONTEXT
40 #endif
41
42 int coap_options_to_path(struct coap_option *opt, int options_count,
43 struct lwm2m_obj_path *path);
44 /* LwM2M message functions */
45 struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx);
46 struct lwm2m_message *find_msg(struct coap_pending *pending, struct coap_reply *reply);
47 void lwm2m_reset_message(struct lwm2m_message *msg, bool release);
48 void lm2m_message_clear_allocations(struct lwm2m_message *msg);
49 int lwm2m_init_message(struct lwm2m_message *msg);
50 int lwm2m_send_message_async(struct lwm2m_message *msg);
51
52 void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len,
53 struct sockaddr *from_addr);
54
55 int generate_notify_message(struct lwm2m_ctx *ctx, struct observe_node *obs, void *user_data);
56 /* Notification and Send operation */
57 int lwm2m_information_interface_send(struct lwm2m_message *msg);
58 int lwm2m_send_empty_ack(struct lwm2m_ctx *client_ctx, uint16_t mid);
59
60 int lwm2m_register_payload_handler(struct lwm2m_message *msg);
61
62 int lwm2m_perform_read_op(struct lwm2m_message *msg, uint16_t content_format);
63
64 int lwm2m_perform_composite_read_op(struct lwm2m_message *msg, uint16_t content_format,
65 sys_slist_t *lwm2m_path_list);
66
67 int do_composite_read_op_for_parsed_list(struct lwm2m_message *msg, uint16_t content_format,
68 sys_slist_t *path_list);
69
70 int lwm2m_discover_handler(struct lwm2m_message *msg, bool is_bootstrap);
71
72 int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst, struct lwm2m_engine_res *res,
73 struct lwm2m_engine_res_inst *res_inst,
74 struct lwm2m_engine_obj_field *obj_field, struct lwm2m_message *msg);
75
76 enum coap_block_size lwm2m_default_block_size(void);
77
78 int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri);
79 void lwm2m_clear_block_contexts(void);
80
lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message * msg)81 static inline bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg)
82 {
83 return msg->block_send;
84 }
85
86 #endif /* LWM2M_MESSAGE_HANDLING_H */
87