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 /* Establish a request handler callback type */ 43 typedef int (*udp_request_handler_cb_t)(struct coap_packet *request, struct lwm2m_message *msg); 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 int handle_request(struct coap_packet *request, struct lwm2m_message *msg); 53 54 void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, 55 struct sockaddr *from_addr, udp_request_handler_cb_t udp_request_handler); 56 57 int generate_notify_message(struct lwm2m_ctx *ctx, struct observe_node *obs, void *user_data); 58 /* Notification and Send operation */ 59 int lwm2m_information_interface_send(struct lwm2m_message *msg); 60 int lwm2m_send_empty_ack(struct lwm2m_ctx *client_ctx, uint16_t mid); 61 62 int lwm2m_register_payload_handler(struct lwm2m_message *msg); 63 64 int lwm2m_perform_read_op(struct lwm2m_message *msg, uint16_t content_format); 65 66 int lwm2m_perform_composite_read_op(struct lwm2m_message *msg, uint16_t content_format, 67 sys_slist_t *lwm2m_path_list); 68 69 int do_composite_read_op_for_parsed_list(struct lwm2m_message *msg, uint16_t content_format, 70 sys_slist_t *path_list); 71 72 int lwm2m_discover_handler(struct lwm2m_message *msg, bool is_bootstrap); 73 74 int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst, struct lwm2m_engine_res *res, 75 struct lwm2m_engine_res_inst *res_inst, 76 struct lwm2m_engine_obj_field *obj_field, struct lwm2m_message *msg); 77 78 enum coap_block_size lwm2m_default_block_size(void); 79 80 int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri); 81 void lwm2m_clear_block_contexts(void); 82 83 #endif /* LWM2M_MESSAGE_HANDLING_H */ 84