1c87c5fbaSopenharmony_ci// -*- mode:doc; -*-
2c87c5fbaSopenharmony_ci// vim: set syntax=asciidoc tw=0
3c87c5fbaSopenharmony_ci
4c87c5fbaSopenharmony_cicoap_session(3)
5c87c5fbaSopenharmony_ci===============
6c87c5fbaSopenharmony_ci:doctype: manpage
7c87c5fbaSopenharmony_ci:man source:   coap_session
8c87c5fbaSopenharmony_ci:man version:  @PACKAGE_VERSION@
9c87c5fbaSopenharmony_ci:man manual:   libcoap Manual
10c87c5fbaSopenharmony_ci
11c87c5fbaSopenharmony_ciNAME
12c87c5fbaSopenharmony_ci----
13c87c5fbaSopenharmony_cicoap_session,
14c87c5fbaSopenharmony_cicoap_session_reference,
15c87c5fbaSopenharmony_cicoap_session_release,
16c87c5fbaSopenharmony_cicoap_session_disconnected,
17c87c5fbaSopenharmony_cicoap_session_set_type_client,
18c87c5fbaSopenharmony_cicoap_session_set_app_data,
19c87c5fbaSopenharmony_cicoap_session_get_app_data,
20c87c5fbaSopenharmony_cicoap_session_get_addr_local,
21c87c5fbaSopenharmony_cicoap_session_get_addr_mcast,
22c87c5fbaSopenharmony_cicoap_session_get_addr_remote,
23c87c5fbaSopenharmony_cicoap_session_get_context,
24c87c5fbaSopenharmony_cicoap_session_get_ifindex,
25c87c5fbaSopenharmony_cicoap_session_get_proto,
26c87c5fbaSopenharmony_cicoap_session_get_state,
27c87c5fbaSopenharmony_cicoap_session_get_tls,
28c87c5fbaSopenharmony_cicoap_session_get_type,
29c87c5fbaSopenharmony_cicoap_session_get_psk_hint,
30c87c5fbaSopenharmony_cicoap_session_get_psk_key
31c87c5fbaSopenharmony_ci- Work with CoAP sessions
32c87c5fbaSopenharmony_ci
33c87c5fbaSopenharmony_ciSYNOPSIS
34c87c5fbaSopenharmony_ci--------
35c87c5fbaSopenharmony_ci*#include <coap@LIBCOAP_API_VERSION@/coap.h>*
36c87c5fbaSopenharmony_ci
37c87c5fbaSopenharmony_ci*coap_session_t *coap_session_reference(coap_session_t *_session_);*
38c87c5fbaSopenharmony_ci
39c87c5fbaSopenharmony_ci*void coap_session_release(coap_session_t *_session_);*
40c87c5fbaSopenharmony_ci
41c87c5fbaSopenharmony_ci*void coap_session_disconnected(coap_session_t *_session_, coap_nack_reason_t _reason_);*
42c87c5fbaSopenharmony_ci
43c87c5fbaSopenharmony_ci*int coap_session_set_type_client(coap_session_t *_session_);*
44c87c5fbaSopenharmony_ci
45c87c5fbaSopenharmony_ci*void coap_session_set_app_data(coap_session_t *_session_, void *_data_);*
46c87c5fbaSopenharmony_ci
47c87c5fbaSopenharmony_ci*void *coap_session_get_app_data(const coap_session_t *_session_);*
48c87c5fbaSopenharmony_ci
49c87c5fbaSopenharmony_ci*const coap_address_t *coap_session_get_addr_local(
50c87c5fbaSopenharmony_ciconst coap_session_t *_session_);*
51c87c5fbaSopenharmony_ci
52c87c5fbaSopenharmony_ci*const coap_address_t *coap_session_get_addr_mcast(
53c87c5fbaSopenharmony_ciconst coap_session_t *_session_);*
54c87c5fbaSopenharmony_ci
55c87c5fbaSopenharmony_ci*const coap_address_t *coap_session_get_addr_remote(
56c87c5fbaSopenharmony_ciconst coap_session_t *_session_);*
57c87c5fbaSopenharmony_ci
58c87c5fbaSopenharmony_ci*coap_context_t *coap_session_get_context(const coap_session_t *_session_);*
59c87c5fbaSopenharmony_ci
60c87c5fbaSopenharmony_ci*int coap_session_get_ifindex(const coap_session_t *_session_);*
61c87c5fbaSopenharmony_ci
62c87c5fbaSopenharmony_ci*coap_proto_t coap_session_get_proto(const coap_session_t *_session_);*
63c87c5fbaSopenharmony_ci
64c87c5fbaSopenharmony_ci*coap_session_state_t coap_session_get_state(const coap_session_t *_session_);*
65c87c5fbaSopenharmony_ci
66c87c5fbaSopenharmony_ci*void *coap_session_get_tls(const coap_session_t *_session_,
67c87c5fbaSopenharmony_cicoap_tls_library_t *tls_lib);*
68c87c5fbaSopenharmony_ci
69c87c5fbaSopenharmony_ci*coap_session_type_t coap_session_get_type(const coap_session_t *_session_);*
70c87c5fbaSopenharmony_ci
71c87c5fbaSopenharmony_ci*const coap_bin_const_t *coap_session_get_psk_hint(
72c87c5fbaSopenharmony_ciconst coap_session_t *_session_);*
73c87c5fbaSopenharmony_ci
74c87c5fbaSopenharmony_ci*const coap_bin_const_t *coap_session_get_psk_key(
75c87c5fbaSopenharmony_ciconst coap_session_t *_session_);*
76c87c5fbaSopenharmony_ci
77c87c5fbaSopenharmony_ciFor specific (D)TLS library support, link with
78c87c5fbaSopenharmony_ci*-lcoap-@LIBCOAP_API_VERSION@-notls*, *-lcoap-@LIBCOAP_API_VERSION@-gnutls*,
79c87c5fbaSopenharmony_ci*-lcoap-@LIBCOAP_API_VERSION@-openssl*, *-lcoap-@LIBCOAP_API_VERSION@-mbedtls*
80c87c5fbaSopenharmony_cior *-lcoap-@LIBCOAP_API_VERSION@-tinydtls*.   Otherwise, link with
81c87c5fbaSopenharmony_ci*-lcoap-@LIBCOAP_API_VERSION@* to get the default (D)TLS library support.
82c87c5fbaSopenharmony_ci
83c87c5fbaSopenharmony_ciDESCRIPTION
84c87c5fbaSopenharmony_ci-----------
85c87c5fbaSopenharmony_ciThis man page focuses on the CoAP Session and how to update or get information
86c87c5fbaSopenharmony_cifrom the opaque coap_session_t structure.
87c87c5fbaSopenharmony_ci
88c87c5fbaSopenharmony_ciA CoAP Session maintains the state of an ongoing connection between a Client
89c87c5fbaSopenharmony_ciand Server which is stored in a coap_session_t Session object. A CoAP session
90c87c5fbaSopenharmony_ciis tracked by local port, CoAP protocol, remote IP address and remote port.
91c87c5fbaSopenharmony_ci
92c87c5fbaSopenharmony_ciThe Session network traffic can be encrypted or un-encrypted if there is an
93c87c5fbaSopenharmony_ciunderlying TLS library.
94c87c5fbaSopenharmony_ci
95c87c5fbaSopenharmony_ciFUNCTIONS
96c87c5fbaSopenharmony_ci---------
97c87c5fbaSopenharmony_ci
98c87c5fbaSopenharmony_ci*Function: coap_session_reference()*
99c87c5fbaSopenharmony_ci
100c87c5fbaSopenharmony_ciThe *coap_session_reference*() function is used to increment the reference
101c87c5fbaSopenharmony_cicount of the _session_.  Incrementing the reference count by an application
102c87c5fbaSopenharmony_cimeans that the library will not inadvertently remove the session when it has
103c87c5fbaSopenharmony_cifinished processing the session.
104c87c5fbaSopenharmony_ci
105c87c5fbaSopenharmony_ci*Function: coap_session_release()*
106c87c5fbaSopenharmony_ci
107c87c5fbaSopenharmony_ciThe *coap_session_release*() function is be used to decrement the _session_
108c87c5fbaSopenharmony_cireference count, which when it gets to 0, will:-
109c87c5fbaSopenharmony_ci
110c87c5fbaSopenharmony_ciIf type Client, free off the session which then clears all entries from the
111c87c5fbaSopenharmony_cireceive queue and send queue. *NOTE:*  All client sessions start off with a
112c87c5fbaSopenharmony_cireference count of 1.
113c87c5fbaSopenharmony_ci
114c87c5fbaSopenharmony_ciIf type Server, then the _session_ is added to an idle pool ready for subsequent
115c87c5fbaSopenharmony_cire-use. If the Server _session_ is not used for 5 minutes, then it will get
116c87c5fbaSopenharmony_cicompletely freed off.  *NOTE:* Unless the application increments the
117c87c5fbaSopenharmony_cireference count, this is the case for all type server sessions as they start
118c87c5fbaSopenharmony_ciwith a reference count of 0.
119c87c5fbaSopenharmony_ci
120c87c5fbaSopenharmony_ci*Function: coap_session_disconnected()*
121c87c5fbaSopenharmony_ci
122c87c5fbaSopenharmony_ciThe *coap_session_disconnected*() function is used to force the closure of a
123c87c5fbaSopenharmony_ci_session_ for the reason _reason_. It will cause any outstanding traffic to
124c87c5fbaSopenharmony_ciget dropped.
125c87c5fbaSopenharmony_ci
126c87c5fbaSopenharmony_ci*Function: coap_session_set_type_client()*
127c87c5fbaSopenharmony_ci
128c87c5fbaSopenharmony_ciThe *coap_session_set_type_client*() function is used to convert the _session_
129c87c5fbaSopenharmony_cifrrm a session endpoint type of Server to Client.  This typically is used in a
130c87c5fbaSopenharmony_ciCall-Home type environment where the roles have to change following the
131c87c5fbaSopenharmony_ciestablishment of a session.  The reference count is incremented by 1.
132c87c5fbaSopenharmony_ci
133c87c5fbaSopenharmony_ci*Function: coap_session_set_app_data()*
134c87c5fbaSopenharmony_ci
135c87c5fbaSopenharmony_ciThe *coap_session_set_app_data*() function is used to define a _data_ pointer
136c87c5fbaSopenharmony_cifor the _session_ which can then be retrieved at a later date.
137c87c5fbaSopenharmony_ci
138c87c5fbaSopenharmony_ci*Function: coap_session_get_app_data()*
139c87c5fbaSopenharmony_ci
140c87c5fbaSopenharmony_ciThe *coap_session_get_app_data*() function is used to retrieve the data
141c87c5fbaSopenharmony_cipointer previously defined by *coap_session_set_app_data*().
142c87c5fbaSopenharmony_ci
143c87c5fbaSopenharmony_ci*Function: coap_session_get_addr_local()*
144c87c5fbaSopenharmony_ci
145c87c5fbaSopenharmony_ciThe *coap_session_get_addr_local*() function is used to get the local IP
146c87c5fbaSopenharmony_ciaddress and port information from the _session_.
147c87c5fbaSopenharmony_ci
148c87c5fbaSopenharmony_ci*Function: coap_session_get_addr_mcast()*
149c87c5fbaSopenharmony_ci
150c87c5fbaSopenharmony_ciThe *coap_session_get_addr_mcast*() function is used to get the remote (peer)
151c87c5fbaSopenharmony_cimulticast IP address and port information from the _session_ if the _session_
152c87c5fbaSopenharmony_ciwas originally set up to send requests to a multicast IP.
153c87c5fbaSopenharmony_ci
154c87c5fbaSopenharmony_ci*Function: coap_session_get_addr_remote()*
155c87c5fbaSopenharmony_ci
156c87c5fbaSopenharmony_ciThe *coap_session_get_addr_remote*() function is used to get the remote (peer)
157c87c5fbaSopenharmony_ciIP address and port information from the _session_.  If the _session_ was
158c87c5fbaSopenharmony_cioriginally set up to send requests to a multicast IP, then the returned IP
159c87c5fbaSopenharmony_ciwill be that of the unicast response from a peer. The returned IP will get
160c87c5fbaSopenharmony_ciset back to the multicast IP when the next *coap_send*(3) is called.
161c87c5fbaSopenharmony_ci
162c87c5fbaSopenharmony_ci*Function: coap_session_get_context()*
163c87c5fbaSopenharmony_ci
164c87c5fbaSopenharmony_ciThe *coap_session_get_context*() function is used to get the CoAP context
165c87c5fbaSopenharmony_ciassociated with the _session_.
166c87c5fbaSopenharmony_ci
167c87c5fbaSopenharmony_ci*Function: coap_session_get_ifindex()*
168c87c5fbaSopenharmony_ci
169c87c5fbaSopenharmony_ciThe  *coap_session_get_ifindex*() function is used to get the network interface
170c87c5fbaSopenharmony_ciindex that the traffic came in over from the _session_.
171c87c5fbaSopenharmony_ci
172c87c5fbaSopenharmony_ci[source, c]
173c87c5fbaSopenharmony_ci----
174c87c5fbaSopenharmony_ciCOAP_PROTO_UDP
175c87c5fbaSopenharmony_ciCOAP_PROTO_DTLS
176c87c5fbaSopenharmony_ciCOAP_PROTO_TCP
177c87c5fbaSopenharmony_ciCOAP_PROTO_TLS
178c87c5fbaSopenharmony_ciCOAP_PROTO_WS
179c87c5fbaSopenharmony_ciCOAP_PROTO_WSS
180c87c5fbaSopenharmony_ci----
181c87c5fbaSopenharmony_ci
182c87c5fbaSopenharmony_ciThe *coap_session_get_proto*() function is used to get the CoAP protocol from
183c87c5fbaSopenharmony_cithe _session_.
184c87c5fbaSopenharmony_ci
185c87c5fbaSopenharmony_ci[source, c]
186c87c5fbaSopenharmony_ci----
187c87c5fbaSopenharmony_ciCOAP_SESSION_STATE_NONE
188c87c5fbaSopenharmony_ciCOAP_SESSION_STATE_CONNECTING
189c87c5fbaSopenharmony_ciCOAP_SESSION_STATE_HANDSHAKE
190c87c5fbaSopenharmony_ciCOAP_SESSION_STATE_CSM
191c87c5fbaSopenharmony_ciCOAP_SESSION_STATE_ESTABLISHED
192c87c5fbaSopenharmony_ci----
193c87c5fbaSopenharmony_ci
194c87c5fbaSopenharmony_ciThe *coap_session_get_state*() function is used to get the current state
195c87c5fbaSopenharmony_ciof the _session_.
196c87c5fbaSopenharmony_ci
197c87c5fbaSopenharmony_ci[source, c]
198c87c5fbaSopenharmony_ci----
199c87c5fbaSopenharmony_ciOpenSSL:  SSL*
200c87c5fbaSopenharmony_ciGnuTLS:   gnutls_session_t (implicit *)
201c87c5fbaSopenharmony_ciMbed TLS: mbedtls_ssl_context*
202c87c5fbaSopenharmony_ciTinyDTLS: struct dtls_context*
203c87c5fbaSopenharmony_ci----
204c87c5fbaSopenharmony_ci
205c87c5fbaSopenharmony_ciThe *coap_session_get_tls*() function is used to get the pointer to the TLS
206c87c5fbaSopenharmony_ciinformation from the _session_.  This is TLS library specific. _tls_lib_ is
207c87c5fbaSopenharmony_ciupdated with the underlying (D)TLS library type.
208c87c5fbaSopenharmony_ci
209c87c5fbaSopenharmony_ci[source, c]
210c87c5fbaSopenharmony_ci----
211c87c5fbaSopenharmony_ciCOAP_SESSION_TYPE_CLIENT
212c87c5fbaSopenharmony_ciCOAP_SESSION_TYPE_SERVER
213c87c5fbaSopenharmony_ciCOAP_SESSION_TYPE_HELLO  /* Negotiating a (D)TLS session */
214c87c5fbaSopenharmony_ci----
215c87c5fbaSopenharmony_ci
216c87c5fbaSopenharmony_ciThe *coap_session_get_type*() function is used to get the session type from the
217c87c5fbaSopenharmony_ci_session_.
218c87c5fbaSopenharmony_ci
219c87c5fbaSopenharmony_ciThe *coap_session_get_psk_hint*() function is used to get the current server
220c87c5fbaSopenharmony_ci_session_'s pre-shared-key identity hint.
221c87c5fbaSopenharmony_ci
222c87c5fbaSopenharmony_ciThe *coap_session_get_psk_key*() function is used to get the current
223c87c5fbaSopenharmony_ci_session_'s pre-shared-key key information.
224c87c5fbaSopenharmony_ci
225c87c5fbaSopenharmony_ciRETURN VALUES
226c87c5fbaSopenharmony_ci-------------
227c87c5fbaSopenharmony_ci
228c87c5fbaSopenharmony_ci*coap_session_reference*() returns a pointer to the session.
229c87c5fbaSopenharmony_ci
230c87c5fbaSopenharmony_ci*coap_session_set_type_client*() returns 1 on success, otherwise 0.
231c87c5fbaSopenharmony_ci
232c87c5fbaSopenharmony_ci*coap_session_get_app_data*() returns a previously defined pointer.
233c87c5fbaSopenharmony_ci
234c87c5fbaSopenharmony_ci*coap_session_get_addr_local*() and *coap_session_get_addr_remote*() return
235c87c5fbaSopenharmony_cia pointer to the IP address / port or NULL on error.
236c87c5fbaSopenharmony_ci
237c87c5fbaSopenharmony_ci*coap_session_get_addr_mcast*() returns a pointer to the remote multicast IP
238c87c5fbaSopenharmony_ciaddress / port or NULL on error or this is not a multicast session.
239c87c5fbaSopenharmony_ci
240c87c5fbaSopenharmony_ci*coap_session_get_context*() returns a pointer to the current CoAP Context or
241c87c5fbaSopenharmony_ciNULL on error.
242c87c5fbaSopenharmony_ci
243c87c5fbaSopenharmony_ci*coap_session_get_ifindex*() returns the network interface the traffic last
244c87c5fbaSopenharmony_cicame in over, or -1 on error.
245c87c5fbaSopenharmony_ci
246c87c5fbaSopenharmony_ci*coap_session_get_proto*() returns the current session's protocol or 0 on error.
247c87c5fbaSopenharmony_ci
248c87c5fbaSopenharmony_ci*coap_session_get_state*() returns the current session's state or 0 on error.
249c87c5fbaSopenharmony_ci
250c87c5fbaSopenharmony_ci*coap_session_get_tls*() returns a pointer to the current session's TLS
251c87c5fbaSopenharmony_ciinformation (TLS library dependent) or NULL if there is none or there is an
252c87c5fbaSopenharmony_cierror.
253c87c5fbaSopenharmony_ci
254c87c5fbaSopenharmony_ci*coap_session_get_type*() returns the current session's type or 0 on error.
255c87c5fbaSopenharmony_ci
256c87c5fbaSopenharmony_ci*coap_session_get_psk_hint*() returns the current server session's
257c87c5fbaSopenharmony_cipre-shared-key identity hint, or NULL if not defined.
258c87c5fbaSopenharmony_ci
259c87c5fbaSopenharmony_ci*coap_session_get_psk_key*() returns the current session's pre-shared-key
260c87c5fbaSopenharmony_cikey information, or NULL if not defined.
261c87c5fbaSopenharmony_ci
262c87c5fbaSopenharmony_ciSEE ALSO
263c87c5fbaSopenharmony_ci--------
264c87c5fbaSopenharmony_ci*coap_context*(3), *coap_endpoint_client*(3) and *coap_endpoint_server*(3)
265c87c5fbaSopenharmony_ci
266c87c5fbaSopenharmony_ciFURTHER INFORMATION
267c87c5fbaSopenharmony_ci-------------------
268c87c5fbaSopenharmony_ciSee
269c87c5fbaSopenharmony_ci
270c87c5fbaSopenharmony_ci"https://rfc-editor.org/rfc/rfc7252[RFC7252: The Constrained Application Protocol (CoAP)]"
271c87c5fbaSopenharmony_ci
272c87c5fbaSopenharmony_cifor further information.
273c87c5fbaSopenharmony_ci
274c87c5fbaSopenharmony_ciBUGS
275c87c5fbaSopenharmony_ci----
276c87c5fbaSopenharmony_ciPlease report bugs on the mailing list for libcoap:
277c87c5fbaSopenharmony_cilibcoap-developers@lists.sourceforge.net or raise an issue on GitHub at
278c87c5fbaSopenharmony_cihttps://github.com/obgm/libcoap/issues
279c87c5fbaSopenharmony_ci
280c87c5fbaSopenharmony_ciAUTHORS
281c87c5fbaSopenharmony_ci-------
282c87c5fbaSopenharmony_ciThe libcoap project <libcoap-developers@lists.sourceforge.net>
283