1c87c5fbaSopenharmony_ci// -*- mode:doc; -*- 2c87c5fbaSopenharmony_ci// vim: set syntax=asciidoc tw=0 3c87c5fbaSopenharmony_ci 4c87c5fbaSopenharmony_cicoap_context(3) 5c87c5fbaSopenharmony_ci=============== 6c87c5fbaSopenharmony_ci:doctype: manpage 7c87c5fbaSopenharmony_ci:man source: coap_context 8c87c5fbaSopenharmony_ci:man version: @PACKAGE_VERSION@ 9c87c5fbaSopenharmony_ci:man manual: libcoap Manual 10c87c5fbaSopenharmony_ci 11c87c5fbaSopenharmony_ciNAME 12c87c5fbaSopenharmony_ci---- 13c87c5fbaSopenharmony_cicoap_context, 14c87c5fbaSopenharmony_cicoap_new_context, 15c87c5fbaSopenharmony_cicoap_free_context, 16c87c5fbaSopenharmony_cicoap_context_set_max_idle_sessions, 17c87c5fbaSopenharmony_cicoap_context_get_max_idle_sessions, 18c87c5fbaSopenharmony_cicoap_context_set_max_handshake_sessions, 19c87c5fbaSopenharmony_cicoap_context_get_max_handshake_sessions, 20c87c5fbaSopenharmony_cicoap_context_set_session_timeout, 21c87c5fbaSopenharmony_cicoap_context_get_session_timeout, 22c87c5fbaSopenharmony_cicoap_context_set_csm_timeout, 23c87c5fbaSopenharmony_cicoap_context_get_csm_timeout, 24c87c5fbaSopenharmony_cicoap_context_set_max_token_size 25c87c5fbaSopenharmony_ci- Work with CoAP contexts 26c87c5fbaSopenharmony_ci 27c87c5fbaSopenharmony_ciSYNOPSIS 28c87c5fbaSopenharmony_ci-------- 29c87c5fbaSopenharmony_ci*#include <coap@LIBCOAP_API_VERSION@/coap.h>* 30c87c5fbaSopenharmony_ci 31c87c5fbaSopenharmony_ci*coap_context_t *coap_new_context(const coap_address_t *_listen_addr_);* 32c87c5fbaSopenharmony_ci 33c87c5fbaSopenharmony_ci*void coap_free_context(coap_context_t *_context_);* 34c87c5fbaSopenharmony_ci 35c87c5fbaSopenharmony_ci*void coap_context_set_max_idle_sessions(coap_context_t *_context_, 36c87c5fbaSopenharmony_ciunsigned int _max_idle_sessions_);* 37c87c5fbaSopenharmony_ci 38c87c5fbaSopenharmony_ci*unsigned int coap_context_get_max_idle_sessions( 39c87c5fbaSopenharmony_ciconst coap_context_t *_context_);* 40c87c5fbaSopenharmony_ci 41c87c5fbaSopenharmony_ci*void coap_context_set_max_handshake_sessions(coap_context_t *_context_, 42c87c5fbaSopenharmony_ciunsigned int _max_handshake_sessions_);* 43c87c5fbaSopenharmony_ci 44c87c5fbaSopenharmony_ci*unsigned int coap_context_get_max_handshake_sessions( 45c87c5fbaSopenharmony_ciconst coap_context_t *_context_);* 46c87c5fbaSopenharmony_ci 47c87c5fbaSopenharmony_ci*void coap_context_set_session_timeout(coap_context_t *_context_, 48c87c5fbaSopenharmony_ciunsigned int _session_timeout_);* 49c87c5fbaSopenharmony_ci 50c87c5fbaSopenharmony_ci*unsigned int coap_context_get_session_timeout( 51c87c5fbaSopenharmony_ciconst coap_context_t *_context_);* 52c87c5fbaSopenharmony_ci 53c87c5fbaSopenharmony_ci*void coap_context_set_csm_timeout(coap_context_t *_context_, 54c87c5fbaSopenharmony_ciunsigned int _csm_timeout_);* 55c87c5fbaSopenharmony_ci 56c87c5fbaSopenharmony_ci*unsigned int coap_context_get_csm_timeout(const coap_context_t *_context_);* 57c87c5fbaSopenharmony_ci 58c87c5fbaSopenharmony_ci*void coap_context_set_max_token_size(coap_context_t *_context_, 59c87c5fbaSopenharmony_cisize_t _max_token_size_);* 60c87c5fbaSopenharmony_ci 61c87c5fbaSopenharmony_ciFor specific (D)TLS library support, link with 62c87c5fbaSopenharmony_ci*-lcoap-@LIBCOAP_API_VERSION@-notls*, *-lcoap-@LIBCOAP_API_VERSION@-gnutls*, 63c87c5fbaSopenharmony_ci*-lcoap-@LIBCOAP_API_VERSION@-openssl*, *-lcoap-@LIBCOAP_API_VERSION@-mbedtls* 64c87c5fbaSopenharmony_cior *-lcoap-@LIBCOAP_API_VERSION@-tinydtls*. Otherwise, link with 65c87c5fbaSopenharmony_ci*-lcoap-@LIBCOAP_API_VERSION@* to get the default (D)TLS library support. 66c87c5fbaSopenharmony_ci 67c87c5fbaSopenharmony_ciDESCRIPTION 68c87c5fbaSopenharmony_ci----------- 69c87c5fbaSopenharmony_ciThis man page focuses on the CoAP Context and how to update or get information 70c87c5fbaSopenharmony_cifrom the opaque coap_context_t structure. 71c87c5fbaSopenharmony_ci 72c87c5fbaSopenharmony_ciThe CoAP stack's global state is stored in a coap_context_t Context object. 73c87c5fbaSopenharmony_ciResources, Endpoints and Sessions are associated with this context object. 74c87c5fbaSopenharmony_ciThere can be more than one coap_context_t object per application, it is up to 75c87c5fbaSopenharmony_cithe application to manage each one accordingly. 76c87c5fbaSopenharmony_ci 77c87c5fbaSopenharmony_ciFUNCTIONS 78c87c5fbaSopenharmony_ci--------- 79c87c5fbaSopenharmony_ci 80c87c5fbaSopenharmony_ci*Function: coap_new_context()* 81c87c5fbaSopenharmony_ci 82c87c5fbaSopenharmony_ciThe *coap_new_context*() function creates a new Context that is then used 83c87c5fbaSopenharmony_cito keep all the CoAP Resources, Endpoints and Sessions information. 84c87c5fbaSopenharmony_ciThe optional _listen_addr_ parameter, if set for a CoAP server, creates an 85c87c5fbaSopenharmony_ciEndpoint that is added to the _context_ that is listening for un-encrypted 86c87c5fbaSopenharmony_citraffic on the IP address and port number defined by _listen_addr_. 87c87c5fbaSopenharmony_ci 88c87c5fbaSopenharmony_ci*Function: coap_free_context()* 89c87c5fbaSopenharmony_ci 90c87c5fbaSopenharmony_ciThe *coap_free_context*() function must be used to release the CoAP stack 91c87c5fbaSopenharmony_ci_context_. It clears all entries from the receive queue and send queue and 92c87c5fbaSopenharmony_cideletes the Resources that have been registered with _context_, and frees the 93c87c5fbaSopenharmony_ciattached Sessions and Endpoints. 94c87c5fbaSopenharmony_ci 95c87c5fbaSopenharmony_ci*WARNING:* It is unsafe to call *coap_free_context*() in an atexit() handler 96c87c5fbaSopenharmony_cias other libraries may also call atexit() and clear down some CoAP 97c87c5fbaSopenharmony_cirequired functionality. 98c87c5fbaSopenharmony_ci 99c87c5fbaSopenharmony_ci*Function: coap_context_set_max_idle_sessions()* 100c87c5fbaSopenharmony_ci 101c87c5fbaSopenharmony_ciThe *coap_context_set_max_idle_sessions*() function sets the maximum number of 102c87c5fbaSopenharmony_ciidle server sessions to _max_idle_sessions_ for _context_. If this number is 103c87c5fbaSopenharmony_ciexceeded, the least recently used server session is completely removed. 0 (the 104c87c5fbaSopenharmony_ciinitial default) means that the number of idle sessions is not monitored. 105c87c5fbaSopenharmony_ci 106c87c5fbaSopenharmony_ci*Function: coap_context_get_max_idle_sessions()* 107c87c5fbaSopenharmony_ci 108c87c5fbaSopenharmony_ciThe *coap_context_get_max_idle_sessions*() function returns the maximum number 109c87c5fbaSopenharmony_ciof idle server sessions for _context_. 110c87c5fbaSopenharmony_ci 111c87c5fbaSopenharmony_ci*Function: coap_context_set_max_handshake_sessions()* 112c87c5fbaSopenharmony_ci 113c87c5fbaSopenharmony_ciThe *coap_context_set_max_handshake_sessions*() function sets the maximum 114c87c5fbaSopenharmony_cinumber of outstanding server sessions in (D)TLS handshake to 115c87c5fbaSopenharmony_ci_max_handshake_sessions_ for _context_. If this number is exceeded, the least 116c87c5fbaSopenharmony_cirecently used server session in handshake is completely removed. 0 (the default) 117c87c5fbaSopenharmony_cimeans that the number of handshakes is not monitored. 118c87c5fbaSopenharmony_ci 119c87c5fbaSopenharmony_ci*Function: coap_context_get_max_handshake_sessions()* 120c87c5fbaSopenharmony_ci 121c87c5fbaSopenharmony_ciThe *coap_context_get_max_handshake_sessions*() function returns the maximum 122c87c5fbaSopenharmony_cinumber of outstanding server sessions in (D)TLS handshake for _context_. 123c87c5fbaSopenharmony_ci 124c87c5fbaSopenharmony_ci*Function: coap_context_set_session_timeout()* 125c87c5fbaSopenharmony_ci 126c87c5fbaSopenharmony_ciThe *coap_context_set_session_timeout*() function sets the number of seconds of 127c87c5fbaSopenharmony_ciinactivity to _session_timeout_ for _context_ before an idle server session is 128c87c5fbaSopenharmony_ciremoved. 0 (the default) means wait for the default of 300 seconds. 129c87c5fbaSopenharmony_ci 130c87c5fbaSopenharmony_ci*Function: coap_context_get_session_timeout()* 131c87c5fbaSopenharmony_ci 132c87c5fbaSopenharmony_ciThe *coap_context_get_session_timeout*() function returns the seconds to wait 133c87c5fbaSopenharmony_cibefore timing out an idle server session for _context_. 134c87c5fbaSopenharmony_ci 135c87c5fbaSopenharmony_ci*Function: coap_context_set_csm_timeout()* 136c87c5fbaSopenharmony_ci 137c87c5fbaSopenharmony_ciThe *coap_context_set_csm_timeout*() function sets the number of seconds to 138c87c5fbaSopenharmony_ciwait for a (TCP) CSM negotiation response from the peer to _csm_timeout_ for 139c87c5fbaSopenharmony_ci_context_. 0 (the default) means wait forever. 140c87c5fbaSopenharmony_ci 141c87c5fbaSopenharmony_ci*Function: coap_context_get_csm_timeout()* 142c87c5fbaSopenharmony_ci 143c87c5fbaSopenharmony_ciThe *coap_context_get_csm_timeout*() function returns the seconds to wait for 144c87c5fbaSopenharmony_cia (TCP) CSM negotiation response from the peer for _context_, 145c87c5fbaSopenharmony_ci 146c87c5fbaSopenharmony_ci*Function: coap_context_set_max_token_size()* 147c87c5fbaSopenharmony_ci 148c87c5fbaSopenharmony_ciThe *coap_context_set_max_token_size*() function sets the _max_token_size_ 149c87c5fbaSopenharmony_cifor _context_. _max_token_size_ must be greater than 8 to indicate 150c87c5fbaSopenharmony_cisupport for https://rfc-editor.org/rfc/rfc8974[RFC8974] up to _max_token_size_ 151c87c5fbaSopenharmony_cibytes, else 8 to disable https://rfc-editor.org/rfc/rfc8974[RFC8974] 152c87c5fbaSopenharmony_ci(if previously set). 153c87c5fbaSopenharmony_ci 154c87c5fbaSopenharmony_ci*NOTE:* For the client, it will send an initial PDU to test the server 155c87c5fbaSopenharmony_cisupports the requested extended token size as per 156c87c5fbaSopenharmony_ci"https://rfc-editor.org/rfc/rfc8974.html#section-2.2.2[RFC8794 Section 2.2.2]" 157c87c5fbaSopenharmony_ci 158c87c5fbaSopenharmony_ciRETURN VALUES 159c87c5fbaSopenharmony_ci------------- 160c87c5fbaSopenharmony_ci*coap_new_context*() returns a newly created context or 161c87c5fbaSopenharmony_ciNULL if there is a creation failure. 162c87c5fbaSopenharmony_ci 163c87c5fbaSopenharmony_ci*coap_context_get_max_idle_sessions*() returns the maximum number of idle 164c87c5fbaSopenharmony_ciserver sessions. 165c87c5fbaSopenharmony_ci 166c87c5fbaSopenharmony_ci*coap_context_get_max_handshake_sessions*() returns the maximum number of 167c87c5fbaSopenharmony_cioutstanding server sessions in (D)TLS handshake. 168c87c5fbaSopenharmony_ci 169c87c5fbaSopenharmony_ci*coap_context_get_session_timeout*() returns the seconds to wait before timing 170c87c5fbaSopenharmony_ciout an idle server session. 171c87c5fbaSopenharmony_ci 172c87c5fbaSopenharmony_ci*coap_context_get_csm_timeout*() returns the seconds to wait for a (TCP) CSM 173c87c5fbaSopenharmony_cinegotiation response from the peer. 174c87c5fbaSopenharmony_ci 175c87c5fbaSopenharmony_ciSEE ALSO 176c87c5fbaSopenharmony_ci-------- 177c87c5fbaSopenharmony_ci*coap_session*(3) 178c87c5fbaSopenharmony_ci 179c87c5fbaSopenharmony_ciFURTHER INFORMATION 180c87c5fbaSopenharmony_ci------------------- 181c87c5fbaSopenharmony_ciSee 182c87c5fbaSopenharmony_ci 183c87c5fbaSopenharmony_ci"https://rfc-editor.org/rfc/rfc7252[RFC7252: The Constrained Application Protocol (CoAP)]" 184c87c5fbaSopenharmony_ci 185c87c5fbaSopenharmony_ci"https://rfc-editor.org/rfc/rfc8974[RFC8974: Extended Tokens and Stateless Clients in the Constrained Application Protocol (CoAP)]" 186c87c5fbaSopenharmony_ci 187c87c5fbaSopenharmony_cifor further information. 188c87c5fbaSopenharmony_ci 189c87c5fbaSopenharmony_ciBUGS 190c87c5fbaSopenharmony_ci---- 191c87c5fbaSopenharmony_ciPlease report bugs on the mailing list for libcoap: 192c87c5fbaSopenharmony_cilibcoap-developers@lists.sourceforge.net or raise an issue on GitHub at 193c87c5fbaSopenharmony_cihttps://github.com/obgm/libcoap/issues 194c87c5fbaSopenharmony_ci 195c87c5fbaSopenharmony_ciAUTHORS 196c87c5fbaSopenharmony_ci------- 197c87c5fbaSopenharmony_ciThe libcoap project <libcoap-developers@lists.sourceforge.net> 198