406#if IS_USED(MODULE_GCOAP_DTLS)
426#ifndef CONFIG_GCOAP_PORT
427#define CONFIG_GCOAP_PORT (5683)
432#ifndef CONFIG_GCOAPS_PORT
433#define CONFIG_GCOAPS_PORT (5684)
439#ifndef CONFIG_GCOAP_DTLS_HANDSHAKE_TIMEOUT_MSEC
440#define CONFIG_GCOAP_DTLS_HANDSHAKE_TIMEOUT_MSEC (3 * MS_PER_SEC)
448#ifndef CONFIG_GCOAP_DTLS_MINIMUM_AVAILABLE_SESSIONS
449#define CONFIG_GCOAP_DTLS_MINIMUM_AVAILABLE_SESSIONS (1)
456#ifndef CONFIG_GCOAP_DTLS_MINIMUM_AVAILABLE_SESSIONS_TIMEOUT_MSEC
457#define CONFIG_GCOAP_DTLS_MINIMUM_AVAILABLE_SESSIONS_TIMEOUT_MSEC (15 * MS_PER_SEC)
463#ifndef CONFIG_GCOAP_PDU_BUF_SIZE
464#define CONFIG_GCOAP_PDU_BUF_SIZE (128)
470#ifndef CONFIG_GCOAP_REQ_WAITING_MAX
471#define CONFIG_GCOAP_REQ_WAITING_MAX (2)
478#define GCOAP_TOKENLEN_MAX (8)
483#define GCOAP_HEADER_MAXLEN (sizeof(coap_hdr_t) + GCOAP_TOKENLEN_MAX)
491#ifndef CONFIG_GCOAP_TOKENLEN
492#define CONFIG_GCOAP_TOKENLEN (2)
498#define GCOAP_PAYLOAD_MARKER (0xFF)
506#ifndef CONFIG_GCOAP_NO_AUTO_INIT
507#define CONFIG_GCOAP_NO_AUTO_INIT 0
514#define GCOAP_MEMO_UNUSED (0)
515#define GCOAP_MEMO_RETRANSMIT (1)
516#define GCOAP_MEMO_WAIT (2)
517#define GCOAP_MEMO_RESP (3)
518#define GCOAP_MEMO_TIMEOUT (4)
519#define GCOAP_MEMO_ERR (5)
520#define GCOAP_MEMO_RESP_TRUNC (6)
527#define GCOAP_SEND_LIMIT_NON (-1)
539#define CONFIG_GCOAP_NO_RETRANS_BACKOFF
548#ifndef CONFIG_GCOAP_NON_TIMEOUT_MSEC
549#define CONFIG_GCOAP_NON_TIMEOUT_MSEC (5000U)
560#ifndef CONFIG_GCOAP_OBS_CLIENTS_MAX
561#define CONFIG_GCOAP_OBS_CLIENTS_MAX (2)
573#ifndef CONFIG_GCOAP_OBS_NOTIFIERS_MAX
574#define CONFIG_GCOAP_OBS_NOTIFIERS_MAX (2)
585#ifndef CONFIG_GCOAP_OBS_REGISTRATIONS_MAX
586#define CONFIG_GCOAP_OBS_REGISTRATIONS_MAX (2)
593#define GCOAP_OBS_MEMO_UNUSED (0)
594#define GCOAP_OBS_MEMO_IDLE (1)
595#define GCOAP_OBS_MEMO_PENDING (2)
618#ifndef CONFIG_GCOAP_OBS_VALUE_WIDTH
619#define CONFIG_GCOAP_OBS_VALUE_WIDTH (3)
625#if (CONFIG_GCOAP_OBS_VALUE_WIDTH == 3)
626#define GCOAP_OBS_TICK_EXPONENT (0)
627#elif (CONFIG_GCOAP_OBS_VALUE_WIDTH == 2)
628#define GCOAP_OBS_TICK_EXPONENT (6)
629#elif (CONFIG_GCOAP_OBS_VALUE_WIDTH == 1)
630#define GCOAP_OBS_TICK_EXPONENT (14)
637#define GCOAP_OBS_INIT_OK (0)
638#define GCOAP_OBS_INIT_ERR (-1)
639#define GCOAP_OBS_INIT_UNUSED (-2)
646#ifndef GCOAP_DTLS_EXTRA_STACKSIZE
647#if IS_USED(MODULE_GCOAP_DTLS)
648#define GCOAP_DTLS_EXTRA_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
650#define GCOAP_DTLS_EXTRA_STACKSIZE (0)
657#if IS_USED(MODULE_GCOAP_FILESERVER)
659#define GCOAP_VFS_EXTRA_STACKSIZE (VFS_DIR_BUFFER_SIZE + VFS_FILE_BUFFER_SIZE)
661#define GCOAP_VFS_EXTRA_STACKSIZE (0)
664#ifndef GCOAP_STACK_SIZE
665#define GCOAP_STACK_SIZE (THREAD_STACKSIZE_DEFAULT + DEBUG_EXTRA_STACKSIZE \
666 + sizeof(coap_pkt_t) + GCOAP_DTLS_EXTRA_STACKSIZE \
667 + GCOAP_VFS_EXTRA_STACKSIZE)
675#ifndef CONFIG_GCOAP_RESEND_BUFS_MAX
676#define CONFIG_GCOAP_RESEND_BUFS_MAX (1)
684#define COAP_LINK_FLAG_INIT_RESLIST (1)
717#define GCOAP_RESOURCE_FOUND (0)
718#define GCOAP_RESOURCE_WRONG_METHOD (1)
719#define GCOAP_RESOURCE_NO_PATH (2)
720#define GCOAP_RESOURCE_ERROR (3)
763#if IS_USED(MODULE_GCOAP_DTLS) || defined(DOXYGEN)
767#if IS_USED(MODULE_GCOAP_DTLS) || defined(DOXYGEN)
848#if IS_USED(MODULE_NANOCOAP_CACHE) || DOXYGEN
913 const char *uri_path);
942 unsigned code,
const char *path,
970 unsigned code,
const char *path)
973 (path) ? strlen(path) : 0U);
989 unsigned code,
char *path)
992 if (
IS_USED(MODULE_NANOCOAP_CACHE)) {
1053 return gcoap_req_send(buf, len, remote, NULL, resp_handler, context, tl_type);
1083 size_t len,
unsigned code)
1208#if IS_USED(MODULE_GCOAP_DTLS) || defined(DOXYGEN)
Provides a callback-with-argument event type.
Provides functionality to trigger events after timeout.
int16_t kernel_pid_t
Unique process identifier.
int gcoap_req_init_path_buffer(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code, const char *path, size_t path_len)
Initializes a CoAP request PDU on a buffer.
int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf, gcoap_socket_type_t tl_type)
Get the resource list, currently only CoRE Link Format (COAP_FORMAT_LINK) supported.
int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
Initializes a CoAP response packet on a buffer.
ssize_t(* gcoap_link_encoder_t)(const coap_resource_t *resource, char *buf, size_t maxlen, coap_link_encoder_ctx_t *context)
Handler function to write a resource link.
void gcoap_register_listener(gcoap_listener_t *listener)
Starts listening for resource paths.
static coap_hdr_t * gcoap_request_memo_get_hdr(const gcoap_request_memo_t *memo)
Get the header of a request from a gcoap_request_memo_t.
static ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len, const sock_udp_ep_t *remote, gcoap_resp_handler_t resp_handler, void *context, gcoap_socket_type_t tl_type)
Sends a buffer containing a CoAP request to the provided endpoint.
static int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code, const char *path)
Initializes a CoAP request PDU on a buffer.
#define GCOAP_TOKENLEN_MAX
Maximum length in bytes for a token.
gcoap_socket_type_t
CoAP socket types.
int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, const coap_resource_t *resource)
Initializes a CoAP Observe notification packet on a buffer, for the observer registered for a resourc...
ssize_t gcoap_req_send(const uint8_t *buf, size_t len, const sock_udp_ep_t *remote, const sock_udp_ep_t *local, gcoap_resp_handler_t resp_handler, void *context, gcoap_socket_type_t tl_type)
Sends a buffer containing a CoAP request to the provided endpoint.
const coap_resource_t * gcoap_get_resource_by_path_iterator(const gcoap_listener_t **last_listener, const coap_resource_t *last_resource, const char *uri_path)
Iterate through all registered listeners and check for a resource, matching by uri_path.
#define GCOAP_HEADER_MAXLEN
Maximum length in bytes for a header, including the token.
sock_dtls_t * gcoap_get_sock_dtls(void)
Get the underlying DTLS socket of gcoap.
void(* gcoap_resp_handler_t)(const gcoap_request_memo_t *memo, coap_pkt_t *pdu, const sock_udp_ep_t *remote)
Handler function for a server response, including the state for the originating request.
#define GCOAP_SEND_LIMIT_NON
Value for send_limit in request memo when non-confirmable type.
ssize_t gcoap_encode_link(const coap_resource_t *resource, char *buf, size_t maxlen, coap_link_encoder_ctx_t *context)
Writes a resource in CoRE Link Format to a provided buffer.
size_t gcoap_obs_send(const uint8_t *buf, size_t len, const coap_resource_t *resource)
Sends a buffer containing a CoAP Observe notification to the observer registered for a resource.
int gcoap_obs_req_forget(const sock_udp_ep_t *remote, const uint8_t *token, size_t tokenlen)
Forgets (invalidates) an existing observe request.
static ssize_t gcoap_response(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
Writes a complete CoAP response PDU when there is no payload.
int(* gcoap_request_matcher_t)(gcoap_listener_t *listener, const coap_resource_t **resource, coap_pkt_t *pdu)
Handler function for the request matcher strategy.
kernel_pid_t gcoap_init(void)
Initializes the gcoap thread and device.
uint8_t gcoap_op_state(void)
Provides important operational statistics.
static ssize_t gcoap_request(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code, char *path)
Writes a complete CoAP request PDU when there is not a payload.
@ GCOAP_SOCKET_TYPE_UDP
Unencrypted UDP transport.
@ GCOAP_SOCKET_TYPE_UNDEF
undefined
@ GCOAP_SOCKET_TYPE_DTLS
DTLS-over-UDP transport.
#define CONFIG_NANOCOAP_CACHE_KEY_LENGTH
The length of the cache key in bytes.
#define COAP_OPT_FINISH_NONE
no special handling required
ssize_t coap_opt_remove(coap_pkt_t *pkt, uint16_t optnum)
Removes an option previously added with function in the coap_opt_add_...() group.
ssize_t coap_opt_finish(coap_pkt_t *pkt, uint16_t flags)
Finalizes options as required and prepares for payload.
int socket(int domain, int type, int protocol)
Create an endpoint for communication.
Definitions for IPv6 addresses.
#define IS_USED(module)
Checks whether a module is being used or not.
Common IP-based transport layer end point.
Raw CoAP PDU header structure.
Context information required to write a resource link.
unsigned content_format
link format
size_t link_pos
position of link within listener
uint16_t flags
encoder switches; see COAP_LINK_FLAG_ constants
CoAP PDU parsing context structure.
Type for CoAP resource entry.
Callback Event structure definition.
A modular collection of resources for a server.
gcoap_link_encoder_t link_encoder
Writes a link for a resource.
struct gcoap_listener * next
Next listener in list.
size_t resources_len
Length of array.
gcoap_socket_type_t tl_type
Transport type for the listener.
const coap_resource_t * resources
First element in the array of resources.
gcoap_request_matcher_t request_matcher
Function that picks a suitable request handler from a request.
Memo for Observe registration and notifications.
unsigned token_len
Actual length of token attribute.
gcoap_socket_t socket
Transport type to observer.
const coap_resource_t * resource
Entity being observed.
sock_udp_ep_t * notifier
Local endpoint to send notifications.
uint16_t last_msgid
Message ID of last notification.
sock_udp_ep_t * observer
Client endpoint; unused if null.
Memo to handle a response for a request.
void * context
ptr to user defined context data
gcoap_resp_handler_t resp_handler
Callback for the response.
event_callback_t resp_tmout_cb
Callback for response timeout.
union gcoap_request_memo::@356 msg
Request message data; if confirmable, supports resending message.
unsigned state
State of this memo, a GCOAP_MEMO...
int send_limit
Remaining resends, 0 if none; GCOAP_SEND_LIMIT_NON if non-confirmable.
gcoap_resend_t data
Endpoint and PDU buffer, for resend.
uint8_t cache_key[CONFIG_NANOCOAP_CACHE_KEY_LENGTH]
Cache key for the request.
sock_udp_ep_t remote_ep
Remote endpoint.
gcoap_socket_t socket
Transport type to remote endpoint.
uint8_t hdr_buf[GCOAP_HEADER_MAXLEN]
Copy of PDU header, if no resends.
event_timeout_t resp_evt_tmout
Limits wait for response.
Extends request memo for resending a confirmable request.
uint8_t * pdu_buf
Buffer containing the PDU.
size_t pdu_len
Length of pdu_buf.
CoAP socket to handle multiple transport types.
gcoap_socket_type_t type
Type of stored socket.
sock_dtls_session_t ctx_dtls_session
Session object for the stored socket.
Information about remote client connected to the server.
Information about DTLS sock.
Utility library for comparing and computing timestamps.