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 /* LwM2M message functions */
43 struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx);
44 struct lwm2m_message *find_msg(struct coap_pending *pending, struct coap_reply *reply);
45 void lwm2m_reset_message(struct lwm2m_message *msg, bool release);
46 void lm2m_message_clear_allocations(struct lwm2m_message *msg);
47 int lwm2m_init_message(struct lwm2m_message *msg);
48 int lwm2m_send_message_async(struct lwm2m_message *msg);
49
50 void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len,
51 struct sockaddr *from_addr);
52
53 int generate_notify_message(struct lwm2m_ctx *ctx, struct observe_node *obs, void *user_data);
54 /* Notification and Send operation */
55 int lwm2m_information_interface_send(struct lwm2m_message *msg);
56 int lwm2m_send_empty_ack(struct lwm2m_ctx *client_ctx, uint16_t mid);
57
58 int lwm2m_register_payload_handler(struct lwm2m_message *msg);
59
60 int lwm2m_perform_read_op(struct lwm2m_message *msg, uint16_t content_format);
61
62 int lwm2m_perform_composite_read_op(struct lwm2m_message *msg, uint16_t content_format,
63 sys_slist_t *lwm2m_path_list);
64
65 int do_composite_read_op_for_parsed_list(struct lwm2m_message *msg, uint16_t content_format,
66 sys_slist_t *path_list);
67
68 int lwm2m_discover_handler(struct lwm2m_message *msg, bool is_bootstrap);
69
70 int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst, struct lwm2m_engine_res *res,
71 struct lwm2m_engine_res_inst *res_inst,
72 struct lwm2m_engine_obj_field *obj_field, struct lwm2m_message *msg);
73
74 enum coap_block_size lwm2m_default_block_size(void);
75
76 int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri);
77 void lwm2m_clear_block_contexts(void);
78
lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message * msg)79 static inline bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg)
80 {
81 return msg->block_send;
82 }
83
84 #endif /* LWM2M_MESSAGE_HANDLING_H */
85