1c87c5fbaSopenharmony_ci/* coap_session.h -- Session management for libcoap
2c87c5fbaSopenharmony_ci*
3c87c5fbaSopenharmony_ci* Copyright (C) 2017 Jean-Claue Michelou <jcm@spinetix.com>
4c87c5fbaSopenharmony_ci*
5c87c5fbaSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause
6c87c5fbaSopenharmony_ci *
7c87c5fbaSopenharmony_ci* This file is part of the CoAP library libcoap. Please see
8c87c5fbaSopenharmony_ci* README for terms of use.
9c87c5fbaSopenharmony_ci*/
10c87c5fbaSopenharmony_ci
11c87c5fbaSopenharmony_ci/**
12c87c5fbaSopenharmony_ci * @file coap_session.h
13c87c5fbaSopenharmony_ci * @brief Defines the application visible session information
14c87c5fbaSopenharmony_ci */
15c87c5fbaSopenharmony_ci
16c87c5fbaSopenharmony_ci#ifndef COAP_SESSION_H_
17c87c5fbaSopenharmony_ci#define COAP_SESSION_H_
18c87c5fbaSopenharmony_ci
19c87c5fbaSopenharmony_ci/**
20c87c5fbaSopenharmony_ci * @ingroup application_api
21c87c5fbaSopenharmony_ci * @defgroup session Sessions
22c87c5fbaSopenharmony_ci * API for CoAP Session access
23c87c5fbaSopenharmony_ci * @{
24c87c5fbaSopenharmony_ci */
25c87c5fbaSopenharmony_ci
26c87c5fbaSopenharmony_ci/**
27c87c5fbaSopenharmony_ci* Abstraction of a fixed point number that can be used where necessary instead
28c87c5fbaSopenharmony_ci* of a float.  1,000 fractional bits equals one integer
29c87c5fbaSopenharmony_ci*/
30c87c5fbaSopenharmony_citypedef struct coap_fixed_point_t {
31c87c5fbaSopenharmony_ci  uint16_t integer_part;    /**< Integer part of fixed point variable */
32c87c5fbaSopenharmony_ci  uint16_t fractional_part; /**< Fractional part of fixed point variable
33c87c5fbaSopenharmony_ci                                1/1000 (3 points) precision */
34c87c5fbaSopenharmony_ci} coap_fixed_point_t;
35c87c5fbaSopenharmony_ci
36c87c5fbaSopenharmony_ci#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
37c87c5fbaSopenharmony_ci#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS || \
38c87c5fbaSopenharmony_ci                                (p)==COAP_PROTO_WS || (p)==COAP_PROTO_WSS)
39c87c5fbaSopenharmony_ci
40c87c5fbaSopenharmony_ci/**
41c87c5fbaSopenharmony_ci * coap_session_type_t values
42c87c5fbaSopenharmony_ci */
43c87c5fbaSopenharmony_citypedef enum coap_session_type_t {
44c87c5fbaSopenharmony_ci  COAP_SESSION_TYPE_NONE = 0, /**< Not defined */
45c87c5fbaSopenharmony_ci  COAP_SESSION_TYPE_CLIENT,   /**< client-side */
46c87c5fbaSopenharmony_ci  COAP_SESSION_TYPE_SERVER,   /**< server-side */
47c87c5fbaSopenharmony_ci  COAP_SESSION_TYPE_HELLO,    /**< server-side ephemeral session for
48c87c5fbaSopenharmony_ci                                   responding to a client hello */
49c87c5fbaSopenharmony_ci} coap_session_type_t;
50c87c5fbaSopenharmony_ci
51c87c5fbaSopenharmony_ci/**
52c87c5fbaSopenharmony_ci * coap_session_state_t values
53c87c5fbaSopenharmony_ci */
54c87c5fbaSopenharmony_citypedef enum coap_session_state_t {
55c87c5fbaSopenharmony_ci  COAP_SESSION_STATE_NONE = 0,
56c87c5fbaSopenharmony_ci  COAP_SESSION_STATE_CONNECTING,
57c87c5fbaSopenharmony_ci  COAP_SESSION_STATE_HANDSHAKE,
58c87c5fbaSopenharmony_ci  COAP_SESSION_STATE_CSM,
59c87c5fbaSopenharmony_ci  COAP_SESSION_STATE_ESTABLISHED,
60c87c5fbaSopenharmony_ci} coap_session_state_t;
61c87c5fbaSopenharmony_ci
62c87c5fbaSopenharmony_ci/**
63c87c5fbaSopenharmony_ci * Increment reference counter on a session.
64c87c5fbaSopenharmony_ci *
65c87c5fbaSopenharmony_ci * @param session The CoAP session.
66c87c5fbaSopenharmony_ci * @return same as session
67c87c5fbaSopenharmony_ci */
68c87c5fbaSopenharmony_cicoap_session_t *coap_session_reference(coap_session_t *session);
69c87c5fbaSopenharmony_ci
70c87c5fbaSopenharmony_ci/**
71c87c5fbaSopenharmony_ci * Decrement reference counter on a session.
72c87c5fbaSopenharmony_ci * Note that the session may be deleted as a result and should not be used
73c87c5fbaSopenharmony_ci * after this call.
74c87c5fbaSopenharmony_ci *
75c87c5fbaSopenharmony_ci * @param session The CoAP session.
76c87c5fbaSopenharmony_ci */
77c87c5fbaSopenharmony_civoid coap_session_release(coap_session_t *session);
78c87c5fbaSopenharmony_ci
79c87c5fbaSopenharmony_ci/**
80c87c5fbaSopenharmony_ci * Notify session that it has failed.  This cleans up any outstanding / queued
81c87c5fbaSopenharmony_ci * transmissions, observations etc..
82c87c5fbaSopenharmony_ci *
83c87c5fbaSopenharmony_ci * @param session The CoAP session.
84c87c5fbaSopenharmony_ci * @param reason The reason why the session was disconnected.
85c87c5fbaSopenharmony_ci */
86c87c5fbaSopenharmony_civoid coap_session_disconnected(coap_session_t *session,
87c87c5fbaSopenharmony_ci                               coap_nack_reason_t reason);
88c87c5fbaSopenharmony_ci
89c87c5fbaSopenharmony_ci/**
90c87c5fbaSopenharmony_ci * Stores @p data with the given session. This function overwrites any value
91c87c5fbaSopenharmony_ci * that has previously been stored with @p session.
92c87c5fbaSopenharmony_ci *
93c87c5fbaSopenharmony_ci * @param session The CoAP session.
94c87c5fbaSopenharmony_ci * @param data The pointer to the data to store.
95c87c5fbaSopenharmony_ci */
96c87c5fbaSopenharmony_civoid coap_session_set_app_data(coap_session_t *session, void *data);
97c87c5fbaSopenharmony_ci
98c87c5fbaSopenharmony_ci/**
99c87c5fbaSopenharmony_ci * Returns any application-specific data that has been stored with @p
100c87c5fbaSopenharmony_ci * session using the function coap_session_set_app_data(). This function will
101c87c5fbaSopenharmony_ci * return @c NULL if no data has been stored.
102c87c5fbaSopenharmony_ci *
103c87c5fbaSopenharmony_ci * @param session The CoAP session.
104c87c5fbaSopenharmony_ci *
105c87c5fbaSopenharmony_ci * @return Pointer to the stored data or @c NULL.
106c87c5fbaSopenharmony_ci */
107c87c5fbaSopenharmony_civoid *coap_session_get_app_data(const coap_session_t *session);
108c87c5fbaSopenharmony_ci
109c87c5fbaSopenharmony_ci/**
110c87c5fbaSopenharmony_ci * Get the remote IP address and port from the session.
111c87c5fbaSopenharmony_ci *
112c87c5fbaSopenharmony_ci * Note: For clients, this can be the responding IP address for a multicast
113c87c5fbaSopenharmony_ci * request before the next coap_send() is called when the multicast address
114c87c5fbaSopenharmony_ci * is restored.
115c87c5fbaSopenharmony_ci *
116c87c5fbaSopenharmony_ci * @param session The CoAP session.
117c87c5fbaSopenharmony_ci *
118c87c5fbaSopenharmony_ci * @return The session's remote address or @c NULL on failure.
119c87c5fbaSopenharmony_ci */
120c87c5fbaSopenharmony_ciconst coap_address_t *coap_session_get_addr_remote(
121c87c5fbaSopenharmony_ci    const coap_session_t *session);
122c87c5fbaSopenharmony_ci
123c87c5fbaSopenharmony_ci/**
124c87c5fbaSopenharmony_ci * Get the remote multicast IP address and port from the session if the
125c87c5fbaSopenharmony_ci * original target IP was multicast.
126c87c5fbaSopenharmony_ci *
127c87c5fbaSopenharmony_ci * Note: This is only available for a client.
128c87c5fbaSopenharmony_ci *
129c87c5fbaSopenharmony_ci * @param session The CoAP session.
130c87c5fbaSopenharmony_ci *
131c87c5fbaSopenharmony_ci * @return The session's remote multicast address or @c NULL on failure or if
132c87c5fbaSopenharmony_ci *         this is not a multicast session.
133c87c5fbaSopenharmony_ci */
134c87c5fbaSopenharmony_ciconst coap_address_t *coap_session_get_addr_mcast(
135c87c5fbaSopenharmony_ci    const coap_session_t *session);
136c87c5fbaSopenharmony_ci
137c87c5fbaSopenharmony_ci/**
138c87c5fbaSopenharmony_ci * Get the local IP address and port from the session.
139c87c5fbaSopenharmony_ci *
140c87c5fbaSopenharmony_ci * @param session The CoAP session.
141c87c5fbaSopenharmony_ci *
142c87c5fbaSopenharmony_ci * @return The session's local address or @c NULL on failure.
143c87c5fbaSopenharmony_ci */
144c87c5fbaSopenharmony_ciconst coap_address_t *coap_session_get_addr_local(
145c87c5fbaSopenharmony_ci    const coap_session_t *session);
146c87c5fbaSopenharmony_ci
147c87c5fbaSopenharmony_ci/**
148c87c5fbaSopenharmony_ci * Get the session protocol type
149c87c5fbaSopenharmony_ci *
150c87c5fbaSopenharmony_ci * @param session The CoAP session.
151c87c5fbaSopenharmony_ci *
152c87c5fbaSopenharmony_ci * @return The session's protocol type
153c87c5fbaSopenharmony_ci */
154c87c5fbaSopenharmony_cicoap_proto_t coap_session_get_proto(const coap_session_t *session);
155c87c5fbaSopenharmony_ci
156c87c5fbaSopenharmony_ci/**
157c87c5fbaSopenharmony_ci * Get the session type
158c87c5fbaSopenharmony_ci *
159c87c5fbaSopenharmony_ci * @param session The CoAP session.
160c87c5fbaSopenharmony_ci *
161c87c5fbaSopenharmony_ci * @return The session's type
162c87c5fbaSopenharmony_ci */
163c87c5fbaSopenharmony_cicoap_session_type_t coap_session_get_type(const coap_session_t *session);
164c87c5fbaSopenharmony_ci
165c87c5fbaSopenharmony_ci/**
166c87c5fbaSopenharmony_ci * Get the session state
167c87c5fbaSopenharmony_ci *
168c87c5fbaSopenharmony_ci * @param session The CoAP session.
169c87c5fbaSopenharmony_ci *
170c87c5fbaSopenharmony_ci * @return The session's state
171c87c5fbaSopenharmony_ci */
172c87c5fbaSopenharmony_cicoap_session_state_t coap_session_get_state(const coap_session_t *session);
173c87c5fbaSopenharmony_ci
174c87c5fbaSopenharmony_ci/**
175c87c5fbaSopenharmony_ci * Get the session if index
176c87c5fbaSopenharmony_ci *
177c87c5fbaSopenharmony_ci * @param session The CoAP session.
178c87c5fbaSopenharmony_ci *
179c87c5fbaSopenharmony_ci * @return The session's if index, or @c -1 on error.
180c87c5fbaSopenharmony_ci */
181c87c5fbaSopenharmony_ciint coap_session_get_ifindex(const coap_session_t *session);
182c87c5fbaSopenharmony_ci
183c87c5fbaSopenharmony_ci/**
184c87c5fbaSopenharmony_ci * Get the session TLS security ptr (TLS type dependent)
185c87c5fbaSopenharmony_ci *
186c87c5fbaSopenharmony_ci * OpenSSL:  SSL*
187c87c5fbaSopenharmony_ci * GnuTLS:   gnutls_session_t (implicit *)
188c87c5fbaSopenharmony_ci * Mbed TLS: mbedtls_ssl_context*
189c87c5fbaSopenharmony_ci * TinyDTLS: struct dtls_context*
190c87c5fbaSopenharmony_ci *
191c87c5fbaSopenharmony_ci * @param session The CoAP session.
192c87c5fbaSopenharmony_ci * @param tls_lib Updated with the library type.
193c87c5fbaSopenharmony_ci *
194c87c5fbaSopenharmony_ci * @return The session TLS ptr or @c NULL if not set up
195c87c5fbaSopenharmony_ci */
196c87c5fbaSopenharmony_civoid *coap_session_get_tls(const coap_session_t *session,
197c87c5fbaSopenharmony_ci                           coap_tls_library_t *tls_lib);
198c87c5fbaSopenharmony_ci
199c87c5fbaSopenharmony_ci/**
200c87c5fbaSopenharmony_ci * Get the session context
201c87c5fbaSopenharmony_ci *
202c87c5fbaSopenharmony_ci * @param session The CoAP session.
203c87c5fbaSopenharmony_ci *
204c87c5fbaSopenharmony_ci * @return The session's context
205c87c5fbaSopenharmony_ci */
206c87c5fbaSopenharmony_cicoap_context_t *coap_session_get_context(const coap_session_t *session);
207c87c5fbaSopenharmony_ci
208c87c5fbaSopenharmony_ci/**
209c87c5fbaSopenharmony_ci * Set the session type to client. Typically used in a call-home server.
210c87c5fbaSopenharmony_ci * The session needs to be of type COAP_SESSION_TYPE_SERVER.
211c87c5fbaSopenharmony_ci * Note: If this function is successful, the session reference count is
212c87c5fbaSopenharmony_ci * incremented and a subsequent coap_session_release() taking the
213c87c5fbaSopenharmony_ci * reference count to 0 will cause the session to be freed off.
214c87c5fbaSopenharmony_ci *
215c87c5fbaSopenharmony_ci * @param session The CoAP session.
216c87c5fbaSopenharmony_ci *
217c87c5fbaSopenharmony_ci * @return @c 1 if updated, @c 0 on failure.
218c87c5fbaSopenharmony_ci */
219c87c5fbaSopenharmony_ciint coap_session_set_type_client(coap_session_t *session);
220c87c5fbaSopenharmony_ci
221c87c5fbaSopenharmony_ci/**
222c87c5fbaSopenharmony_ci * Set the session MTU. This is the maximum message size that can be sent,
223c87c5fbaSopenharmony_ci * excluding IP and UDP overhead.
224c87c5fbaSopenharmony_ci *
225c87c5fbaSopenharmony_ci * @param session The CoAP session.
226c87c5fbaSopenharmony_ci * @param mtu maximum message size
227c87c5fbaSopenharmony_ci */
228c87c5fbaSopenharmony_civoid coap_session_set_mtu(coap_session_t *session, unsigned mtu);
229c87c5fbaSopenharmony_ci
230c87c5fbaSopenharmony_ci/**
231c87c5fbaSopenharmony_ci * Get maximum acceptable PDU size
232c87c5fbaSopenharmony_ci *
233c87c5fbaSopenharmony_ci * @param session The CoAP session.
234c87c5fbaSopenharmony_ci * @return maximum PDU size, not including header (but including token).
235c87c5fbaSopenharmony_ci */
236c87c5fbaSopenharmony_cisize_t coap_session_max_pdu_size(const coap_session_t *session);
237c87c5fbaSopenharmony_ci
238c87c5fbaSopenharmony_ci/**
239c87c5fbaSopenharmony_ci* Creates a new client session to the designated server.
240c87c5fbaSopenharmony_ci* @param ctx The CoAP context.
241c87c5fbaSopenharmony_ci* @param local_if Address of local interface. It is recommended to use NULL to let the operating system choose a suitable local interface. If an address is specified, the port number should be zero, which means that a free port is automatically selected.
242c87c5fbaSopenharmony_ci* @param server The server's address. If the port number is zero, the default port for the protocol will be used.
243c87c5fbaSopenharmony_ci* @param proto Protocol.
244c87c5fbaSopenharmony_ci*
245c87c5fbaSopenharmony_ci* @return A new CoAP session or NULL if failed. Call coap_session_release to free.
246c87c5fbaSopenharmony_ci*/
247c87c5fbaSopenharmony_cicoap_session_t *coap_new_client_session(
248c87c5fbaSopenharmony_ci    coap_context_t *ctx,
249c87c5fbaSopenharmony_ci    const coap_address_t *local_if,
250c87c5fbaSopenharmony_ci    const coap_address_t *server,
251c87c5fbaSopenharmony_ci    coap_proto_t proto
252c87c5fbaSopenharmony_ci);
253c87c5fbaSopenharmony_ci
254c87c5fbaSopenharmony_ci/**
255c87c5fbaSopenharmony_ci* Creates a new client session to the designated server with PSK credentials
256c87c5fbaSopenharmony_ci *
257c87c5fbaSopenharmony_ci * @deprecated Use coap_new_client_session_psk2() instead.
258c87c5fbaSopenharmony_ci *
259c87c5fbaSopenharmony_ci* @param ctx The CoAP context.
260c87c5fbaSopenharmony_ci* @param local_if Address of local interface. It is recommended to use NULL to let the operating system choose a suitable local interface. If an address is specified, the port number should be zero, which means that a free port is automatically selected.
261c87c5fbaSopenharmony_ci* @param server The server's address. If the port number is zero, the default port for the protocol will be used.
262c87c5fbaSopenharmony_ci* @param proto Protocol.
263c87c5fbaSopenharmony_ci* @param identity PSK client identity
264c87c5fbaSopenharmony_ci* @param key PSK shared key
265c87c5fbaSopenharmony_ci* @param key_len PSK shared key length
266c87c5fbaSopenharmony_ci*
267c87c5fbaSopenharmony_ci* @return A new CoAP session or NULL if failed. Call coap_session_release to free.
268c87c5fbaSopenharmony_ci*/
269c87c5fbaSopenharmony_cicoap_session_t *coap_new_client_session_psk(
270c87c5fbaSopenharmony_ci    coap_context_t *ctx,
271c87c5fbaSopenharmony_ci    const coap_address_t *local_if,
272c87c5fbaSopenharmony_ci    const coap_address_t *server,
273c87c5fbaSopenharmony_ci    coap_proto_t proto,
274c87c5fbaSopenharmony_ci    const char *identity,
275c87c5fbaSopenharmony_ci    const uint8_t *key,
276c87c5fbaSopenharmony_ci    unsigned key_len
277c87c5fbaSopenharmony_ci);
278c87c5fbaSopenharmony_ci
279c87c5fbaSopenharmony_ci/**
280c87c5fbaSopenharmony_ci* Creates a new client session to the designated server with PSK credentials
281c87c5fbaSopenharmony_ci* @param ctx The CoAP context.
282c87c5fbaSopenharmony_ci* @param local_if Address of local interface. It is recommended to use NULL to
283c87c5fbaSopenharmony_ci*                 let the operating system choose a suitable local interface.
284c87c5fbaSopenharmony_ci*                 If an address is specified, the port number should be zero,
285c87c5fbaSopenharmony_ci*                 which means that a free port is automatically selected.
286c87c5fbaSopenharmony_ci* @param server The server's address. If the port number is zero, the default
287c87c5fbaSopenharmony_ci*               port for the protocol will be used.
288c87c5fbaSopenharmony_ci* @param proto CoAP Protocol.
289c87c5fbaSopenharmony_ci* @param setup_data PSK parameters.
290c87c5fbaSopenharmony_ci*
291c87c5fbaSopenharmony_ci* @return A new CoAP session or NULL if failed. Call coap_session_release()
292c87c5fbaSopenharmony_ci*         to free.
293c87c5fbaSopenharmony_ci*/
294c87c5fbaSopenharmony_cicoap_session_t *coap_new_client_session_psk2(
295c87c5fbaSopenharmony_ci    coap_context_t *ctx,
296c87c5fbaSopenharmony_ci    const coap_address_t *local_if,
297c87c5fbaSopenharmony_ci    const coap_address_t *server,
298c87c5fbaSopenharmony_ci    coap_proto_t proto,
299c87c5fbaSopenharmony_ci    coap_dtls_cpsk_t *setup_data
300c87c5fbaSopenharmony_ci);
301c87c5fbaSopenharmony_ci
302c87c5fbaSopenharmony_ci/**
303c87c5fbaSopenharmony_ci * Get the server session's current Identity Hint (PSK).
304c87c5fbaSopenharmony_ci *
305c87c5fbaSopenharmony_ci * @param session  The current coap_session_t object.
306c87c5fbaSopenharmony_ci *
307c87c5fbaSopenharmony_ci * @return @c hint if successful, else @c NULL.
308c87c5fbaSopenharmony_ci */
309c87c5fbaSopenharmony_ciconst coap_bin_const_t *coap_session_get_psk_hint(
310c87c5fbaSopenharmony_ci    const coap_session_t *session);
311c87c5fbaSopenharmony_ci
312c87c5fbaSopenharmony_ci/**
313c87c5fbaSopenharmony_ci * Get the server session's current PSK identity (PSK).
314c87c5fbaSopenharmony_ci *
315c87c5fbaSopenharmony_ci * @param session  The current coap_session_t object.
316c87c5fbaSopenharmony_ci *
317c87c5fbaSopenharmony_ci * @return PSK identity if successful, else @c NULL.
318c87c5fbaSopenharmony_ci */
319c87c5fbaSopenharmony_ciconst coap_bin_const_t *coap_session_get_psk_identity(
320c87c5fbaSopenharmony_ci    const coap_session_t *session);
321c87c5fbaSopenharmony_ci/**
322c87c5fbaSopenharmony_ci * Get the session's current pre-shared key (PSK).
323c87c5fbaSopenharmony_ci *
324c87c5fbaSopenharmony_ci * @param session  The current coap_session_t object.
325c87c5fbaSopenharmony_ci *
326c87c5fbaSopenharmony_ci * @return @c psk_key if successful, else @c NULL.
327c87c5fbaSopenharmony_ci */
328c87c5fbaSopenharmony_ciconst coap_bin_const_t *coap_session_get_psk_key(
329c87c5fbaSopenharmony_ci    const coap_session_t *session);
330c87c5fbaSopenharmony_ci
331c87c5fbaSopenharmony_ci/**
332c87c5fbaSopenharmony_ci* Creates a new client session to the designated server with PKI credentials
333c87c5fbaSopenharmony_ci* @param ctx The CoAP context.
334c87c5fbaSopenharmony_ci* @param local_if Address of local interface. It is recommended to use NULL to
335c87c5fbaSopenharmony_ci*                 let the operating system choose a suitable local interface.
336c87c5fbaSopenharmony_ci*                 If an address is specified, the port number should be zero,
337c87c5fbaSopenharmony_ci*                 which means that a free port is automatically selected.
338c87c5fbaSopenharmony_ci* @param server The server's address. If the port number is zero, the default
339c87c5fbaSopenharmony_ci*               port for the protocol will be used.
340c87c5fbaSopenharmony_ci* @param proto CoAP Protocol.
341c87c5fbaSopenharmony_ci* @param setup_data PKI parameters.
342c87c5fbaSopenharmony_ci*
343c87c5fbaSopenharmony_ci* @return A new CoAP session or NULL if failed. Call coap_session_release()
344c87c5fbaSopenharmony_ci*         to free.
345c87c5fbaSopenharmony_ci*/
346c87c5fbaSopenharmony_cicoap_session_t *coap_new_client_session_pki(
347c87c5fbaSopenharmony_ci    coap_context_t *ctx,
348c87c5fbaSopenharmony_ci    const coap_address_t *local_if,
349c87c5fbaSopenharmony_ci    const coap_address_t *server,
350c87c5fbaSopenharmony_ci    coap_proto_t proto,
351c87c5fbaSopenharmony_ci    coap_dtls_pki_t *setup_data
352c87c5fbaSopenharmony_ci);
353c87c5fbaSopenharmony_ci
354c87c5fbaSopenharmony_ci/**
355c87c5fbaSopenharmony_ci * Initializes the token value to use as a starting point.
356c87c5fbaSopenharmony_ci *
357c87c5fbaSopenharmony_ci * @param session The current coap_session_t object.
358c87c5fbaSopenharmony_ci * @param length  The length of the token (0 - 8 bytes).
359c87c5fbaSopenharmony_ci * @param token   The token data.
360c87c5fbaSopenharmony_ci *
361c87c5fbaSopenharmony_ci */
362c87c5fbaSopenharmony_civoid coap_session_init_token(coap_session_t *session, size_t length,
363c87c5fbaSopenharmony_ci                             const uint8_t *token);
364c87c5fbaSopenharmony_ci
365c87c5fbaSopenharmony_ci/**
366c87c5fbaSopenharmony_ci * Creates a new token for use.
367c87c5fbaSopenharmony_ci *
368c87c5fbaSopenharmony_ci * @param session The current coap_session_t object.
369c87c5fbaSopenharmony_ci * @param length  Updated with the length of the new token.
370c87c5fbaSopenharmony_ci * @param token   Updated with the new token data (must be 8 bytes long).
371c87c5fbaSopenharmony_ci *
372c87c5fbaSopenharmony_ci */
373c87c5fbaSopenharmony_civoid coap_session_new_token(coap_session_t *session, size_t *length,
374c87c5fbaSopenharmony_ci                            uint8_t *token);
375c87c5fbaSopenharmony_ci
376c87c5fbaSopenharmony_ci/**
377c87c5fbaSopenharmony_ci * @ingroup logging
378c87c5fbaSopenharmony_ci * Get session description.
379c87c5fbaSopenharmony_ci *
380c87c5fbaSopenharmony_ci * @param session  The CoAP session.
381c87c5fbaSopenharmony_ci * @return description string.
382c87c5fbaSopenharmony_ci */
383c87c5fbaSopenharmony_ciconst char *coap_session_str(const coap_session_t *session);
384c87c5fbaSopenharmony_ci
385c87c5fbaSopenharmony_ci/**
386c87c5fbaSopenharmony_ci * Create a new endpoint for communicating with peers.
387c87c5fbaSopenharmony_ci *
388c87c5fbaSopenharmony_ci * @param context     The coap context that will own the new endpoint,
389c87c5fbaSopenharmony_ci * @param listen_addr Address the endpoint will listen for incoming requests
390c87c5fbaSopenharmony_ci *                    on or originate outgoing requests from. Use NULL to
391c87c5fbaSopenharmony_ci *                    specify that no incoming request will be accepted and
392c87c5fbaSopenharmony_ci *                    use a random endpoint.
393c87c5fbaSopenharmony_ci * @param proto       Protocol used on this endpoint,
394c87c5fbaSopenharmony_ci *
395c87c5fbaSopenharmony_ci * @return The new endpoint or @c NULL on failure.
396c87c5fbaSopenharmony_ci */
397c87c5fbaSopenharmony_cicoap_endpoint_t *coap_new_endpoint(coap_context_t *context, const coap_address_t *listen_addr,
398c87c5fbaSopenharmony_ci                                   coap_proto_t proto);
399c87c5fbaSopenharmony_ci
400c87c5fbaSopenharmony_ci/**
401c87c5fbaSopenharmony_ci * Set the endpoint's default MTU. This is the maximum message size that can be
402c87c5fbaSopenharmony_ci * sent, excluding IP and UDP overhead.
403c87c5fbaSopenharmony_ci *
404c87c5fbaSopenharmony_ci * @param endpoint The CoAP endpoint.
405c87c5fbaSopenharmony_ci * @param mtu maximum message size
406c87c5fbaSopenharmony_ci */
407c87c5fbaSopenharmony_civoid coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu);
408c87c5fbaSopenharmony_ci
409c87c5fbaSopenharmony_ci/**
410c87c5fbaSopenharmony_ci * Release an endpoint and all the structures associated with it.
411c87c5fbaSopenharmony_ci *
412c87c5fbaSopenharmony_ci * @param endpoint The endpoint to release.
413c87c5fbaSopenharmony_ci */
414c87c5fbaSopenharmony_civoid coap_free_endpoint(coap_endpoint_t *endpoint);
415c87c5fbaSopenharmony_ci
416c87c5fbaSopenharmony_ci/**
417c87c5fbaSopenharmony_ci * Get the session associated with the specified @p remote_addr and @p index.
418c87c5fbaSopenharmony_ci *
419c87c5fbaSopenharmony_ci * @param context The context to search.
420c87c5fbaSopenharmony_ci * @param remote_addr The remote (peer) address to search for.
421c87c5fbaSopenharmony_ci * @param ifindex The Interface index that is used to access remote_addr.
422c87c5fbaSopenharmony_ci *
423c87c5fbaSopenharmony_ci * @return The found session or @c NULL if not found.
424c87c5fbaSopenharmony_ci */
425c87c5fbaSopenharmony_cicoap_session_t *coap_session_get_by_peer(const coap_context_t *context,
426c87c5fbaSopenharmony_ci                                         const coap_address_t *remote_addr,
427c87c5fbaSopenharmony_ci                                         int ifindex);
428c87c5fbaSopenharmony_ci
429c87c5fbaSopenharmony_ci/** @} */
430c87c5fbaSopenharmony_ci
431c87c5fbaSopenharmony_ci/**
432c87c5fbaSopenharmony_ci * @ingroup logging
433c87c5fbaSopenharmony_ci* Get endpoint description.
434c87c5fbaSopenharmony_ci*
435c87c5fbaSopenharmony_ci* @param endpoint  The CoAP endpoint.
436c87c5fbaSopenharmony_ci* @return description string.
437c87c5fbaSopenharmony_ci*/
438c87c5fbaSopenharmony_ciconst char *coap_endpoint_str(const coap_endpoint_t *endpoint);
439c87c5fbaSopenharmony_ci
440c87c5fbaSopenharmony_ci/**
441c87c5fbaSopenharmony_ci * @ingroup application_api
442c87c5fbaSopenharmony_ci * @defgroup cc Rate Control
443c87c5fbaSopenharmony_ci * API for updating transmission parameters for CoAP rate control.
444c87c5fbaSopenharmony_ci * The transmission parameters for CoAP rate control ("Congestion
445c87c5fbaSopenharmony_ci * Control" in stream-oriented protocols) are defined in
446c87c5fbaSopenharmony_ci * https://rfc-editor.org/rfc/rfc7252#section-4.8 and
447c87c5fbaSopenharmony_ci * https://rfc-editor.org/rfc/rfc9177#section-6.2
448c87c5fbaSopenharmony_ci * @{
449c87c5fbaSopenharmony_ci */
450c87c5fbaSopenharmony_ci
451c87c5fbaSopenharmony_ci/**
452c87c5fbaSopenharmony_ci * Number of seconds when to expect an ACK or a response to an
453c87c5fbaSopenharmony_ci * outstanding CON message.
454c87c5fbaSopenharmony_ci * RFC 7252, Section 4.8 Default value of ACK_TIMEOUT is 2
455c87c5fbaSopenharmony_ci *
456c87c5fbaSopenharmony_ci * Configurable using coap_session_set_ack_timeout()
457c87c5fbaSopenharmony_ci */
458c87c5fbaSopenharmony_ci#define COAP_DEFAULT_ACK_TIMEOUT ((coap_fixed_point_t){2,0})
459c87c5fbaSopenharmony_ci
460c87c5fbaSopenharmony_ci/**
461c87c5fbaSopenharmony_ci * A factor that is used to randomize the wait time before a message
462c87c5fbaSopenharmony_ci * is retransmitted to prevent synchronization effects.
463c87c5fbaSopenharmony_ci * RFC 7252, Section 4.8 Default value of ACK_RANDOM_FACTOR is 1.5
464c87c5fbaSopenharmony_ci *
465c87c5fbaSopenharmony_ci * Configurable using coap_session_set_ack_random_factor()
466c87c5fbaSopenharmony_ci */
467c87c5fbaSopenharmony_ci#define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500})
468c87c5fbaSopenharmony_ci
469c87c5fbaSopenharmony_ci/**
470c87c5fbaSopenharmony_ci * Number of message retransmissions before message sending is stopped.
471c87c5fbaSopenharmony_ci * RFC 7252, Section 4.8 Default value of MAX_RETRANSMIT is 4
472c87c5fbaSopenharmony_ci *
473c87c5fbaSopenharmony_ci * Configurable using coap_session_set_max_retransmit()
474c87c5fbaSopenharmony_ci */
475c87c5fbaSopenharmony_ci#define COAP_DEFAULT_MAX_RETRANSMIT  (4U)
476c87c5fbaSopenharmony_ci
477c87c5fbaSopenharmony_ci/**
478c87c5fbaSopenharmony_ci * The number of simultaneous outstanding interactions that a client
479c87c5fbaSopenharmony_ci * maintains to a given server.
480c87c5fbaSopenharmony_ci * RFC 7252, Section 4.8 Default value of NSTART is 1
481c87c5fbaSopenharmony_ci *
482c87c5fbaSopenharmony_ci * Configurable using coap_session_set_nstart()
483c87c5fbaSopenharmony_ci */
484c87c5fbaSopenharmony_ci#define COAP_DEFAULT_NSTART (1U)
485c87c5fbaSopenharmony_ci
486c87c5fbaSopenharmony_ci/**
487c87c5fbaSopenharmony_ci * The number of seconds to use as bounds for multicast traffic
488c87c5fbaSopenharmony_ci * RFC 7252, Section 4.8 Default value of DEFAULT_LEISURE is 5.0
489c87c5fbaSopenharmony_ci *
490c87c5fbaSopenharmony_ci * Configurable using coap_session_set_default_leisure()
491c87c5fbaSopenharmony_ci */
492c87c5fbaSopenharmony_ci#define COAP_DEFAULT_DEFAULT_LEISURE ((coap_fixed_point_t){5,0})
493c87c5fbaSopenharmony_ci
494c87c5fbaSopenharmony_ci/**
495c87c5fbaSopenharmony_ci * The number of bytes/second allowed when there is no response
496c87c5fbaSopenharmony_ci * RFC 7252, Section 4.8 Default value of PROBING_RATE is 1
497c87c5fbaSopenharmony_ci *
498c87c5fbaSopenharmony_ci * Configurable using coap_session_set_probing_rate()
499c87c5fbaSopenharmony_ci */
500c87c5fbaSopenharmony_ci#define COAP_DEFAULT_PROBING_RATE (1U)
501c87c5fbaSopenharmony_ci
502c87c5fbaSopenharmony_ci/**
503c87c5fbaSopenharmony_ci * Number of Q-Block1 or Q-Block2 payloads that can be sent in a burst
504c87c5fbaSopenharmony_ci * before a delay has to kick in.
505c87c5fbaSopenharmony_ci * RFC9177 Section 6.2 Default value of MAX_PAYLOAD is 10
506c87c5fbaSopenharmony_ci *
507c87c5fbaSopenharmony_ci * Configurable using coap_session_set_max_payloads()
508c87c5fbaSopenharmony_ci */
509c87c5fbaSopenharmony_ci#define COAP_DEFAULT_MAX_PAYLOADS (10U)
510c87c5fbaSopenharmony_ci
511c87c5fbaSopenharmony_ci/**
512c87c5fbaSopenharmony_ci * The number of times for requests for re-transmission of missing Q-Block1
513c87c5fbaSopenharmony_ci * when no response has been received.
514c87c5fbaSopenharmony_ci * RFC9177 Section 6.2 Default value of NON_MAX_RETRANSMIT is 4
515c87c5fbaSopenharmony_ci *
516c87c5fbaSopenharmony_ci * Configurable using coap_session_set_non_max_retransmit()
517c87c5fbaSopenharmony_ci */
518c87c5fbaSopenharmony_ci#define COAP_DEFAULT_NON_MAX_RETRANSMIT (4U)
519c87c5fbaSopenharmony_ci
520c87c5fbaSopenharmony_ci/**
521c87c5fbaSopenharmony_ci * The delay (+ ACK_RANDOM_FACTOR) to introduce once NON MAX_PAYLOADS
522c87c5fbaSopenharmony_ci * Q-Block1 or Q-Block2 have been sent to reduce congestion control.
523c87c5fbaSopenharmony_ci * RFC9177 Section 6.2 Default value of NON_TIMEOUT is 2.
524c87c5fbaSopenharmony_ci *
525c87c5fbaSopenharmony_ci * Configurable using coap_session_set_non_timeout()
526c87c5fbaSopenharmony_ci */
527c87c5fbaSopenharmony_ci#define COAP_DEFAULT_NON_TIMEOUT ((coap_fixed_point_t){2,0})
528c87c5fbaSopenharmony_ci
529c87c5fbaSopenharmony_ci/**
530c87c5fbaSopenharmony_ci * The time to wait for any missing Q-Block1 or Q-Block2 packets before
531c87c5fbaSopenharmony_ci * requesting re-transmission of missing packets.
532c87c5fbaSopenharmony_ci * RFC9177 Section 6.2 Default value of NON_RECEIVE_TIMEOUT is 4.
533c87c5fbaSopenharmony_ci *
534c87c5fbaSopenharmony_ci * Configurable using coap_session_set_non_receive_timeout()
535c87c5fbaSopenharmony_ci */
536c87c5fbaSopenharmony_ci#define COAP_DEFAULT_NON_RECEIVE_TIMEOUT ((coap_fixed_point_t){4,0})
537c87c5fbaSopenharmony_ci
538c87c5fbaSopenharmony_ci/**
539c87c5fbaSopenharmony_ci * The MAX_LATENCY definition.
540c87c5fbaSopenharmony_ci * RFC 7252, Section 4.8.2 MAX_LATENCY is 100.
541c87c5fbaSopenharmony_ci */
542c87c5fbaSopenharmony_ci#define COAP_DEFAULT_MAX_LATENCY (100U)
543c87c5fbaSopenharmony_ci
544c87c5fbaSopenharmony_ci/**
545c87c5fbaSopenharmony_ci* Set the CoAP initial ack response timeout before the next re-transmit
546c87c5fbaSopenharmony_ci*
547c87c5fbaSopenharmony_ci* Number of seconds when to expect an ACK or a response to an
548c87c5fbaSopenharmony_ci* outstanding CON message.
549c87c5fbaSopenharmony_ci* RFC7252 ACK_TIMEOUT
550c87c5fbaSopenharmony_ci*
551c87c5fbaSopenharmony_ci* @param session The CoAP session.
552c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 2.0 and should not normally
553c87c5fbaSopenharmony_ci*              get changed.
554c87c5fbaSopenharmony_ci*/
555c87c5fbaSopenharmony_civoid coap_session_set_ack_timeout(coap_session_t *session,
556c87c5fbaSopenharmony_ci                                  coap_fixed_point_t value);
557c87c5fbaSopenharmony_ci
558c87c5fbaSopenharmony_ci/**
559c87c5fbaSopenharmony_ci* Get the CoAP initial ack response timeout before the next re-transmit
560c87c5fbaSopenharmony_ci*
561c87c5fbaSopenharmony_ci* Number of seconds when to expect an ACK or a response to an
562c87c5fbaSopenharmony_ci* outstanding CON message.
563c87c5fbaSopenharmony_ci* RFC7252 ACK_TIMEOUT
564c87c5fbaSopenharmony_ci*
565c87c5fbaSopenharmony_ci* @param session The CoAP session.
566c87c5fbaSopenharmony_ci*
567c87c5fbaSopenharmony_ci* @return Current ack response timeout value
568c87c5fbaSopenharmony_ci*/
569c87c5fbaSopenharmony_cicoap_fixed_point_t coap_session_get_ack_timeout(const coap_session_t *session);
570c87c5fbaSopenharmony_ci
571c87c5fbaSopenharmony_ci/**
572c87c5fbaSopenharmony_ci* Set the CoAP ack randomize factor
573c87c5fbaSopenharmony_ci*
574c87c5fbaSopenharmony_ci* A factor that is used to randomize the wait time before a message
575c87c5fbaSopenharmony_ci* is retransmitted to prevent synchronization effects.
576c87c5fbaSopenharmony_ci* RFC7252 ACK_RANDOM_FACTOR
577c87c5fbaSopenharmony_ci*
578c87c5fbaSopenharmony_ci* @param session The CoAP session.
579c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 1.5 and should not normally
580c87c5fbaSopenharmony_ci*              get changed.
581c87c5fbaSopenharmony_ci*/
582c87c5fbaSopenharmony_civoid coap_session_set_ack_random_factor(coap_session_t *session,
583c87c5fbaSopenharmony_ci                                        coap_fixed_point_t value);
584c87c5fbaSopenharmony_ci
585c87c5fbaSopenharmony_ci/**
586c87c5fbaSopenharmony_ci* Get the CoAP ack randomize factor
587c87c5fbaSopenharmony_ci*
588c87c5fbaSopenharmony_ci* A factor that is used to randomize the wait time before a message
589c87c5fbaSopenharmony_ci* is retransmitted to prevent synchronization effects.
590c87c5fbaSopenharmony_ci* RFC7252 ACK_RANDOM_FACTOR
591c87c5fbaSopenharmony_ci*
592c87c5fbaSopenharmony_ci* @param session The CoAP session.
593c87c5fbaSopenharmony_ci*
594c87c5fbaSopenharmony_ci* @return Current ack randomize value
595c87c5fbaSopenharmony_ci*/
596c87c5fbaSopenharmony_cicoap_fixed_point_t coap_session_get_ack_random_factor(
597c87c5fbaSopenharmony_ci    const coap_session_t *session);
598c87c5fbaSopenharmony_ci
599c87c5fbaSopenharmony_ci/**
600c87c5fbaSopenharmony_ci* Set the CoAP maximum retransmit count before failure
601c87c5fbaSopenharmony_ci*
602c87c5fbaSopenharmony_ci* Number of message retransmissions before message sending is stopped
603c87c5fbaSopenharmony_ci* RFC7252 MAX_RETRANSMIT
604c87c5fbaSopenharmony_ci*
605c87c5fbaSopenharmony_ci* @param session The CoAP session.
606c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 4 and should not normally
607c87c5fbaSopenharmony_ci*              get changed.
608c87c5fbaSopenharmony_ci*/
609c87c5fbaSopenharmony_civoid coap_session_set_max_retransmit(coap_session_t *session,
610c87c5fbaSopenharmony_ci                                     uint16_t value);
611c87c5fbaSopenharmony_ci
612c87c5fbaSopenharmony_ci/**
613c87c5fbaSopenharmony_ci* Get the CoAP maximum retransmit before failure
614c87c5fbaSopenharmony_ci*
615c87c5fbaSopenharmony_ci* Number of message retransmissions before message sending is stopped
616c87c5fbaSopenharmony_ci* RFC7252 MAX_RETRANSMIT
617c87c5fbaSopenharmony_ci*
618c87c5fbaSopenharmony_ci* @param session The CoAP session.
619c87c5fbaSopenharmony_ci*
620c87c5fbaSopenharmony_ci* @return Current maximum retransmit value
621c87c5fbaSopenharmony_ci*/
622c87c5fbaSopenharmony_ciuint16_t coap_session_get_max_retransmit(const coap_session_t *session);
623c87c5fbaSopenharmony_ci
624c87c5fbaSopenharmony_ci/**
625c87c5fbaSopenharmony_ci* Set the CoAP maximum concurrent transmission count of Confirmable messages
626c87c5fbaSopenharmony_ci* RFC7252 NSTART
627c87c5fbaSopenharmony_ci*
628c87c5fbaSopenharmony_ci* @param session The CoAP session.
629c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 1 and should not normally
630c87c5fbaSopenharmony_ci*              get changed.
631c87c5fbaSopenharmony_ci*/
632c87c5fbaSopenharmony_civoid coap_session_set_nstart(coap_session_t *session,
633c87c5fbaSopenharmony_ci                             uint16_t value);
634c87c5fbaSopenharmony_ci
635c87c5fbaSopenharmony_ci/**
636c87c5fbaSopenharmony_ci* Get the CoAP maximum concurrent transmission count of Confirmable messages
637c87c5fbaSopenharmony_ci* RFC7252 NSTART
638c87c5fbaSopenharmony_ci*
639c87c5fbaSopenharmony_ci* @param session The CoAP session.
640c87c5fbaSopenharmony_ci*
641c87c5fbaSopenharmony_ci* @return Current nstart value
642c87c5fbaSopenharmony_ci*/
643c87c5fbaSopenharmony_ciuint16_t coap_session_get_nstart(const coap_session_t *session);
644c87c5fbaSopenharmony_ci
645c87c5fbaSopenharmony_ci/**
646c87c5fbaSopenharmony_ci* Set the CoAP default leisure time (for multicast)
647c87c5fbaSopenharmony_ci* RFC7252 DEFAULT_LEISURE
648c87c5fbaSopenharmony_ci*
649c87c5fbaSopenharmony_ci* @param session The CoAP session.
650c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 5.0 and should not normally
651c87c5fbaSopenharmony_ci*              get changed.
652c87c5fbaSopenharmony_ci*/
653c87c5fbaSopenharmony_civoid coap_session_set_default_leisure(coap_session_t *session,
654c87c5fbaSopenharmony_ci                                      coap_fixed_point_t value);
655c87c5fbaSopenharmony_ci
656c87c5fbaSopenharmony_ci/**
657c87c5fbaSopenharmony_ci* Get the CoAP default leisure time
658c87c5fbaSopenharmony_ci* RFC7252 DEFAULT_LEISURE
659c87c5fbaSopenharmony_ci*
660c87c5fbaSopenharmony_ci* @param session The CoAP session.
661c87c5fbaSopenharmony_ci*
662c87c5fbaSopenharmony_ci* @return Current default_leisure value
663c87c5fbaSopenharmony_ci*/
664c87c5fbaSopenharmony_cicoap_fixed_point_t coap_session_get_default_leisure(
665c87c5fbaSopenharmony_ci    const coap_session_t *session);
666c87c5fbaSopenharmony_ci
667c87c5fbaSopenharmony_ci/**
668c87c5fbaSopenharmony_ci* Set the CoAP probing rate when there is no response
669c87c5fbaSopenharmony_ci* RFC7252 PROBING_RATE
670c87c5fbaSopenharmony_ci*
671c87c5fbaSopenharmony_ci* @param session The CoAP session.
672c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 1 and should not normally
673c87c5fbaSopenharmony_ci*              get changed.
674c87c5fbaSopenharmony_ci*/
675c87c5fbaSopenharmony_civoid coap_session_set_probing_rate(coap_session_t *session, uint32_t value);
676c87c5fbaSopenharmony_ci
677c87c5fbaSopenharmony_ci/**
678c87c5fbaSopenharmony_ci* Get the CoAP probing rate when there is no response
679c87c5fbaSopenharmony_ci* RFC7252 PROBING_RATE
680c87c5fbaSopenharmony_ci*
681c87c5fbaSopenharmony_ci* @param session The CoAP session.
682c87c5fbaSopenharmony_ci*
683c87c5fbaSopenharmony_ci* @return Current probing_rate value
684c87c5fbaSopenharmony_ci*/
685c87c5fbaSopenharmony_ciuint32_t coap_session_get_probing_rate(const coap_session_t *session);
686c87c5fbaSopenharmony_ci
687c87c5fbaSopenharmony_ci/**
688c87c5fbaSopenharmony_ci* Set the CoAP maximum payloads count of Q-Block1 or Q-Block2 before delay
689c87c5fbaSopenharmony_ci* is introduced
690c87c5fbaSopenharmony_ci* RFC9177 MAX_PAYLOADS
691c87c5fbaSopenharmony_ci*
692c87c5fbaSopenharmony_ci* @param session The CoAP session.
693c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 10 and should not normally
694c87c5fbaSopenharmony_ci*              get changed.
695c87c5fbaSopenharmony_ci*/
696c87c5fbaSopenharmony_civoid coap_session_set_max_payloads(coap_session_t *session,
697c87c5fbaSopenharmony_ci                                   uint16_t value);
698c87c5fbaSopenharmony_ci
699c87c5fbaSopenharmony_ci/**
700c87c5fbaSopenharmony_ci* Get the CoAP maximum payloads count of Q-Block1 or Q-Block2 before delay
701c87c5fbaSopenharmony_ci* is introduced
702c87c5fbaSopenharmony_ci* RFC9177 MAX_PAYLOADS
703c87c5fbaSopenharmony_ci*
704c87c5fbaSopenharmony_ci* @param session The CoAP session.
705c87c5fbaSopenharmony_ci*
706c87c5fbaSopenharmony_ci* @return Current maximum payloads value
707c87c5fbaSopenharmony_ci*/
708c87c5fbaSopenharmony_ciuint16_t coap_session_get_max_payloads(const coap_session_t *session);
709c87c5fbaSopenharmony_ci
710c87c5fbaSopenharmony_ci/**
711c87c5fbaSopenharmony_ci* Set the CoAP NON maximum retransmit count of missing Q-Block1 or Q-Block2
712c87c5fbaSopenharmony_ci* requested before there is any response
713c87c5fbaSopenharmony_ci* RFC9177 NON_MAX_RETRANSMIT
714c87c5fbaSopenharmony_ci*
715c87c5fbaSopenharmony_ci* @param session The CoAP session.
716c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 4 and should not normally
717c87c5fbaSopenharmony_ci*              get changed.
718c87c5fbaSopenharmony_ci*/
719c87c5fbaSopenharmony_civoid coap_session_set_non_max_retransmit(coap_session_t *session,
720c87c5fbaSopenharmony_ci                                         uint16_t value);
721c87c5fbaSopenharmony_ci
722c87c5fbaSopenharmony_ci/**
723c87c5fbaSopenharmony_ci* Get the CoAP NON maximum retransmit count of missing Q-Block1 or Q-Block2
724c87c5fbaSopenharmony_ci* requested before there is any response
725c87c5fbaSopenharmony_ci* RFC9177 NON_MAX_RETRANSMIT
726c87c5fbaSopenharmony_ci*
727c87c5fbaSopenharmony_ci* @param session The CoAP session.
728c87c5fbaSopenharmony_ci*
729c87c5fbaSopenharmony_ci* @return Current maximum NON max retransmit value
730c87c5fbaSopenharmony_ci*/
731c87c5fbaSopenharmony_ciuint16_t coap_session_get_non_max_retransmit(const coap_session_t *session);
732c87c5fbaSopenharmony_ci
733c87c5fbaSopenharmony_ci/**
734c87c5fbaSopenharmony_ci* Set the CoAP non timeout delay timeout
735c87c5fbaSopenharmony_ci*
736c87c5fbaSopenharmony_ci* Number of seconds to delay (+ ACK_RANDOM_FACTOR) before sending off the next
737c87c5fbaSopenharmony_ci* set of NON MAX_PAYLOADS
738c87c5fbaSopenharmony_ci* RFC9177 NON_TIMEOUT
739c87c5fbaSopenharmony_ci*
740c87c5fbaSopenharmony_ci* @param session The CoAP session.
741c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 2.0 and should not normally
742c87c5fbaSopenharmony_ci*              get changed.
743c87c5fbaSopenharmony_ci*/
744c87c5fbaSopenharmony_civoid coap_session_set_non_timeout(coap_session_t *session,
745c87c5fbaSopenharmony_ci                                  coap_fixed_point_t value);
746c87c5fbaSopenharmony_ci
747c87c5fbaSopenharmony_ci/**
748c87c5fbaSopenharmony_ci* Get the CoAP MAX_PAYLOADS limit delay timeout
749c87c5fbaSopenharmony_ci*
750c87c5fbaSopenharmony_ci* Number of seconds to delay (+ ACK_RANDOM_FACTOR) before sending off the next
751c87c5fbaSopenharmony_ci* set of NON MAX_PAYLOADS
752c87c5fbaSopenharmony_ci* RFC9177 NON_TIMEOUT
753c87c5fbaSopenharmony_ci*
754c87c5fbaSopenharmony_ci* @param session The CoAP session.
755c87c5fbaSopenharmony_ci*
756c87c5fbaSopenharmony_ci* @return NON MAX_PAYLOADS delay
757c87c5fbaSopenharmony_ci*/
758c87c5fbaSopenharmony_cicoap_fixed_point_t coap_session_get_non_timeout(const coap_session_t *session);
759c87c5fbaSopenharmony_ci
760c87c5fbaSopenharmony_ci/**
761c87c5fbaSopenharmony_ci* Set the CoAP non receive timeout delay timeout
762c87c5fbaSopenharmony_ci*
763c87c5fbaSopenharmony_ci* Number of seconds to delay before requesting missing packets
764c87c5fbaSopenharmony_ci* RFC9177 NON_RECEIVE_TIMEOUT
765c87c5fbaSopenharmony_ci*
766c87c5fbaSopenharmony_ci* @param session The CoAP session.
767c87c5fbaSopenharmony_ci* @param value The value to set to. The default is 4.0 and should not normally
768c87c5fbaSopenharmony_ci*              get changed.  Must be 1 sec greater than NON_TIMEOUT_RANDOM
769c87c5fbaSopenharmony_ci*/
770c87c5fbaSopenharmony_civoid coap_session_set_non_receive_timeout(coap_session_t *session,
771c87c5fbaSopenharmony_ci                                          coap_fixed_point_t value);
772c87c5fbaSopenharmony_ci
773c87c5fbaSopenharmony_ci/**
774c87c5fbaSopenharmony_ci* Get the CoAP non receive timeout delay timeout
775c87c5fbaSopenharmony_ci*
776c87c5fbaSopenharmony_ci* Number of seconds to delay before requesting missing packets
777c87c5fbaSopenharmony_ci* RFC9177 NON_RECEIVE_TIMEOUT
778c87c5fbaSopenharmony_ci*
779c87c5fbaSopenharmony_ci* @param session The CoAP session.
780c87c5fbaSopenharmony_ci*
781c87c5fbaSopenharmony_ci* @return NON_RECEIVE_TIMEOUT delay
782c87c5fbaSopenharmony_ci*/
783c87c5fbaSopenharmony_cicoap_fixed_point_t coap_session_get_non_receive_timeout(
784c87c5fbaSopenharmony_ci    const coap_session_t *session);
785c87c5fbaSopenharmony_ci
786c87c5fbaSopenharmony_ci/** @} */
787c87c5fbaSopenharmony_ci/**
788c87c5fbaSopenharmony_ci * Send a ping message for the session.
789c87c5fbaSopenharmony_ci * @param session The CoAP session.
790c87c5fbaSopenharmony_ci *
791c87c5fbaSopenharmony_ci * @return COAP_INVALID_MID if there is an error
792c87c5fbaSopenharmony_ci */
793c87c5fbaSopenharmony_cicoap_mid_t coap_session_send_ping(coap_session_t *session);
794c87c5fbaSopenharmony_ci
795c87c5fbaSopenharmony_ci/**
796c87c5fbaSopenharmony_ci * Disable client automatically sending observe cancel on session close
797c87c5fbaSopenharmony_ci *
798c87c5fbaSopenharmony_ci * @param session The CoAP session.
799c87c5fbaSopenharmony_ci */
800c87c5fbaSopenharmony_civoid coap_session_set_no_observe_cancel(coap_session_t *session);
801c87c5fbaSopenharmony_ci
802c87c5fbaSopenharmony_ci#endif  /* COAP_SESSION_H */
803