1 /* 2 * Copyright (c) 2022 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef LWM2M_OBSERVATION_H 7 #define LWM2M_OBSERVATION_H 8 #include "lwm2m_object.h" 9 10 int lwm2m_notify_observer(uint16_t obj_id, uint16_t obj_inst_id, uint16_t res_id); 11 int lwm2m_notify_observer_path(const struct lwm2m_obj_path *path); 12 13 #define MAX_TOKEN_LEN 8 14 15 struct observe_node { 16 sys_snode_t node; 17 sys_slist_t path_list; /* List of Observation path */ 18 uint8_t token[MAX_TOKEN_LEN]; /* Observation Token */ 19 int64_t event_timestamp; /* Timestamp for trig next Notify */ 20 int64_t last_timestamp; /* Timestamp from last Notify */ 21 struct lwm2m_message *active_notify; /* Currently active notification */ 22 uint32_t counter; 23 uint16_t format; 24 uint8_t tkl; 25 bool resource_update : 1; /* Resource is updated */ 26 bool composite : 1; /* Composite Observation */ 27 }; 28 /* Attribute handling. */ 29 30 struct lwm2m_attr *lwm2m_engine_get_next_attr(const void *ref, struct lwm2m_attr *prev); 31 const char *lwm2m_engine_get_attr_name(const struct lwm2m_attr *attr); 32 33 void clear_attrs(void *ref); 34 35 int64_t engine_observe_shedule_next_event(struct observe_node *obs, uint16_t srv_obj_inst, 36 const int64_t timestamp); 37 38 void remove_observer_from_list(struct lwm2m_ctx *ctx, sys_snode_t *prev_node, 39 struct observe_node *obs); 40 41 struct observe_node *engine_observe_node_discover(sys_slist_t *observe_node_list, 42 sys_snode_t **prev_node, 43 sys_slist_t *lwm2m_path_list, 44 const uint8_t *token, uint8_t tkl); 45 46 int engine_remove_observer_by_token(struct lwm2m_ctx *ctx, const uint8_t *token, uint8_t tkl); 47 48 int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg); 49 50 int lwm2m_engine_observation_handler(struct lwm2m_message *msg, int observe, uint16_t accept, 51 bool composite); 52 53 void engine_remove_observer_by_id(uint16_t obj_id, int32_t obj_inst_id); 54 55 /* path object list */ 56 struct lwm2m_obj_path_list { 57 sys_snode_t node; 58 struct lwm2m_obj_path path; 59 }; 60 /* Initialize path list */ 61 void lwm2m_engine_path_list_init(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list, 62 struct lwm2m_obj_path_list path_object_buf[], 63 uint8_t path_object_size); 64 /** 65 * Add new path to the list while maintaining hierarchical sort order 66 * 67 * @param lwm2m_path_list sorted path list 68 * @param lwm2m_free_list free list 69 * @param path path to be added 70 * @return 0 on success or a negative error code 71 */ 72 int lwm2m_engine_add_path_to_list(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list, 73 const struct lwm2m_obj_path *path); 74 75 int lwm2m_get_path_reference_ptr(struct lwm2m_engine_obj *obj, const struct lwm2m_obj_path *path, 76 void **ref); 77 78 /** 79 * Remove paths when parent already exists in the list 80 * 81 * @note Path list must be sorted 82 * @see lwm2m_engine_add_path_to_list() 83 * 84 * @param lwm2m_path_list sorted path list 85 * @param lwm2m_free_list free list 86 */ 87 void lwm2m_engine_clear_duplicate_path(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list); 88 89 /* Resources */ 90 sys_slist_t *lwm2m_obs_obj_path_list(void); 91 #endif /* LWM2M_OBSERVATION_H */ 92