1 /*
2  * Copyright (c) 2023 Basalte bv
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief CoAP Events code public header
10  */
11 
12 #ifndef ZEPHYR_INCLUDE_NET_COAP_MGMT_H_
13 #define ZEPHYR_INCLUDE_NET_COAP_MGMT_H_
14 
15 #include <zephyr/net/net_mgmt.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /**
22  * @brief CoAP Manager Events
23  * @defgroup coap_mgmt CoAP Manager Events
24  * @ingroup networking
25  * @{
26  */
27 
28 /** @cond INTERNAL_HIDDEN */
29 
30 /* CoAP events */
31 #define _NET_COAP_LAYER		NET_MGMT_LAYER_L4
32 #define _NET_COAP_CODE		0x1c0
33 #define _NET_COAP_IF_BASE	(NET_MGMT_EVENT_BIT |			\
34 				 NET_MGMT_LAYER(_NET_COAP_LAYER) |	\
35 				 NET_MGMT_LAYER_CODE(_NET_COAP_CODE))
36 
37 struct coap_service;
38 struct coap_resource;
39 struct coap_observer;
40 
41 /** @endcond */
42 
43 enum net_event_coap_cmd {
44 	/* Service events */
45 	NET_EVENT_COAP_CMD_SERVICE_STARTED = 1,
46 	NET_EVENT_COAP_CMD_SERVICE_STOPPED,
47 	/* Observer events */
48 	NET_EVENT_COAP_CMD_OBSERVER_ADDED,
49 	NET_EVENT_COAP_CMD_OBSERVER_REMOVED,
50 };
51 
52 /**
53  * @brief coap_mgmt event raised when a service has started
54  */
55 #define NET_EVENT_COAP_SERVICE_STARTED			\
56 	(_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_SERVICE_STARTED)
57 
58 /**
59  * @brief coap_mgmt event raised when a service has stopped
60  */
61 #define NET_EVENT_COAP_SERVICE_STOPPED			\
62 	(_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_SERVICE_STOPPED)
63 
64 /**
65  * @brief coap_mgmt event raised when an observer has been added to a resource
66  */
67 #define NET_EVENT_COAP_OBSERVER_ADDED			\
68 	(_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_OBSERVER_ADDED)
69 
70 /**
71  * @brief coap_mgmt event raised when an observer has been removed from a resource
72  */
73 #define NET_EVENT_COAP_OBSERVER_REMOVED			\
74 	(_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_OBSERVER_REMOVED)
75 
76 /**
77  * @brief CoAP Service event structure.
78  */
79 struct net_event_coap_service {
80 	/* The CoAP service for which the event is emitted */
81 	const struct coap_service *service;
82 };
83 
84 /**
85  * @brief CoAP Observer event structure.
86  */
87 struct net_event_coap_observer {
88 	/* The CoAP resource for which the event is emitted */
89 	struct coap_resource *resource;
90 	/* The observer that is added/removed */
91 	struct coap_observer *observer;
92 };
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 /**
99  * @}
100  */
101 
102 #endif /* ZEPHYR_INCLUDE_NET_COAP_MGMT_H_ */
103