Loading...
Searching...
No Matches
coap_net.h File Reference

CoAP context interface. More...

`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/time.h>`
`#include <time.h>`
`#include "coap_io.h"`
`#include "coap_dtls.h"`
`#include "coap_event.h"`
`#include "coap_pdu.h"`
`#include "coap_session.h"`
`#include "coap_debug.h"`
Include dependency graph for coap_net.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Macros

#define | coap_send_large(session, pdu)
#define | coap_join_mcast_group(ctx, groupname)
#define | COAP_IO_WAIT 0
#define | COAP_IO_NO_WAIT ((uint32_t)-1)
#define | coap_run_once(ctx, timeout_ms)
#define | coap_write(ctx, sockets, max_sockets, num_sockets, now)
#define | coap_read(ctx, now)
#define | COAP_RUN_NONBLOCK COAP_RUN_NONBLOCK_deprecated_use_COAP_IO_NO_WAIT
#define | COAP_RUN_BLOCK COAP_RUN_BLOCK_deprecated_use_COAP_IO_WAIT

## Typedefs

typedef enum coap_response_t | coap_response_t
typedef coap_response_t(* | coap_response_handler_t) (coap_session_t *session, const coap_pdu_t *sent, const coap_pdu_t *received, const coap_mid_t mid)
| Response handler that is used as callback in coap_context_t.
typedef void(* | coap_nack_handler_t) (coap_session_t *session, const coap_pdu_t *sent, const coap_nack_reason_t reason, const coap_mid_t mid)
| Negative Acknowedge handler that is used as callback in coap_context_t.
typedef void(* | coap_ping_handler_t) (coap_session_t *session, const coap_pdu_t *received, const coap_mid_t mid)
| Received Ping handler that is used as callback in coap_context_t.
typedef void(* | coap_pong_handler_t) (coap_session_t *session, const coap_pdu_t *received, const coap_mid_t mid)
| Received Pong handler that is used as callback in coap_context_t.
typedef int(* | coap_lwip_input_wait_handler_t) (void *arg, uint32_t milli_secs)
| LwIP callback handler that can be used to wait / timeout for the next input packet.

## Enumerations

enum | coap_response_t { COAP_RESPONSE_FAIL , COAP_RESPONSE_OK }

## Functions

void | coap_register_response_handler (coap_context_t *context, coap_response_handler_t handler)
| Registers a new message handler that is called whenever a response is received.
void | coap_register_nack_handler (coap_context_t *context, coap_nack_handler_t handler)
| Registers a new message handler that is called whenever a confirmable message (request or response) is dropped after all retries have been exhausted, or a rst message was received, or a network or TLS level event was received that indicates delivering the message is not possible.
void | coap_register_ping_handler (coap_context_t *context, coap_ping_handler_t handler)
| Registers a new message handler that is called whenever a CoAP Ping message is received.
void | coap_register_pong_handler (coap_context_t *context, coap_pong_handler_t handler)
| Registers a new message handler that is called whenever a CoAP Pong message is received.
COAP_API void | coap_register_option (coap_context_t *ctx, uint16_t type)
| Registers the option type `type` with the given context object `ctx`.
coap_context_t * | coap_new_context (const coap_address_t *listen_addr)
| Creates a new coap_context_t object that will hold the CoAP stack status.
COAP_API int | coap_context_set_psk (coap_context_t *context, const char *hint, const uint8_t *key, size_t key_len)
| Set the context's default PSK hint and/or key for a server.
COAP_API int | coap_context_set_psk2 (coap_context_t *context, coap_dtls_spsk_t *setup_data)
| Set the context's default PSK hint and/or key for a server.
COAP_API int | coap_context_set_pki (coap_context_t *context, const coap_dtls_pki_t *setup_data)
| Set the context's default PKI information for a server.
COAP_API int | coap_context_set_pki_root_cas (coap_context_t *context, const char *ca_file, const char *ca_dir)
| Set the context's default Root CA information for a client or server.
void | coap_context_set_keepalive (coap_context_t *context, unsigned int seconds)
| Set the context keepalive timer for sessions.
int | coap_context_set_cid_tuple_change (coap_context_t *context, uint8_t every)
| Set the Connection ID client tuple frequency change for testing CIDs.
void | coap_context_set_max_token_size (coap_context_t *context, size_t max_token_size)
| Set the maximum token size (RFC8974).
int | coap_context_get_coap_fd (const coap_context_t *context)
| Get the libcoap internal file descriptor for using in an application's select() or returned as an event in an application's epoll_wait() call.
void | coap_context_set_max_idle_sessions (coap_context_t *context, unsigned int max_idle_sessions)
| Set the maximum idle sessions count.
unsigned int | coap_context_get_max_idle_sessions (const coap_context_t *context)
| Get the maximum idle sessions count.
void | coap_context_set_session_timeout (coap_context_t *context, unsigned int session_timeout)
| Set the session timeout value.
unsigned int | coap_context_get_session_timeout (const coap_context_t *context)
| Get the session timeout value.
COAP_DEPRECATED void | coap_context_set_csm_timeout (coap_context_t *context, unsigned int csm_timeout)
| Set the CSM timeout value.
COAP_DEPRECATED unsigned int | coap_context_get_csm_timeout (const coap_context_t *context)
| Get the CSM timeout value.
void | coap_context_set_csm_timeout_ms (coap_context_t *context, unsigned int csm_timeout_ms)
| Set the CSM timeout value.
unsigned int | coap_context_get_csm_timeout_ms (const coap_context_t *context)
| Get the CSM timeout value.
void | coap_context_set_csm_max_message_size (coap_context_t *context, uint32_t csm_max_message_size)
| Set the CSM max session size value.
uint32_t | coap_context_get_csm_max_message_size (const coap_context_t *context)
| Get the CSM max session size value.
void | coap_context_set_max_handshake_sessions (coap_context_t *context, unsigned int max_handshake_sessions)
| Set the maximum number of sessions in (D)TLS handshake value.
unsigned int | coap_context_get_max_handshake_sessions (const coap_context_t *context)
| Get the session timeout value.
COAP_API uint16_t | coap_new_message_id (coap_session_t *session)
| Returns a new message id and updates `session->tx_mid` accordingly.
COAP_API void | coap_free_context (coap_context_t *context)
| CoAP stack context must be released with coap_free_context().
void | coap_set_app_data (coap_context_t *context, void *data)
void * | coap_get_app_data (const coap_context_t *context)
coap_pdu_t * | coap_new_error_response (const coap_pdu_t *request, coap_pdu_code_t code, coap_opt_filter_t *opts)
| Creates a new ACK PDU with specified error `code`.
COAP_API coap_mid_t | coap_send_error (coap_session_t *session, const coap_pdu_t *request, coap_pdu_code_t code, coap_opt_filter_t *opts)
| Sends an error response with code `code` for request `request` to `dst`.
COAP_API coap_mid_t | coap_send_message_type (coap_session_t *session, const coap_pdu_t *request, coap_pdu_type_t type)
| Helper function to create and send a message with `type` (usually ACK or RST).
COAP_API coap_mid_t | coap_send_ack (coap_session_t *session, const coap_pdu_t *request)
| Sends an ACK message with code `0` for the specified `request` to `dst`.
COAP_API coap_mid_t | coap_send_rst (coap_session_t *session, const coap_pdu_t *request)
| Sends an RST message with code `0` for the specified `request` to `dst`.
COAP_API coap_mid_t | coap_send (coap_session_t *session, coap_pdu_t *pdu)
| Sends a CoAP message to given peer.
COAP_API int | coap_handle_event (coap_context_t *context, coap_event_t event, coap_session_t *session)
| Invokes the event handler of `context` for the given `event` and `data`.
COAP_API int | coap_can_exit (coap_context_t *context)
| Returns 1 if there are no messages to send or to dispatch in the context's queues.
void | coap_ticks (coap_tick_t *)
| Returns the current value of an internal tick counter.
COAP_API int | coap_join_mcast_group_intf (coap_context_t *ctx, const char *groupname, const char *ifname)
| Function interface for joining a multicast group for listening for the currently defined endpoints that are UDP.
int | coap_mcast_set_hops (coap_session_t *session, size_t hops)
| Function interface for defining the hop count (ttl) for sending multicast traffic.
void | coap_mcast_per_resource (coap_context_t *context)
| Function interface to enable processing mcast requests on a per resource basis.
void | coap_context_set_app_data (coap_context_t *context, void *data)
| Stores `data` with the given context.
void * | coap_context_get_app_data (const coap_context_t *context)
| Returns any application-specific data that has been stored with `context` using the function coap_context_set_app_data().
COAP_API int | coap_io_process (coap_context_t *ctx, uint32_t timeout_ms)
| The main I/O processing function.
COAP_API int | coap_io_process_with_fds (coap_context_t *ctx, uint32_t timeout_ms, int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
| The main message processing loop with additional fds for internal select.
COAP_API int | coap_io_pending (coap_context_t *context)
| Check to see if there is any i/o pending for the `context`.
COAP_API unsigned int | coap_io_prepare_io (coap_context_t *ctx, coap_socket_t *sockets[], unsigned int max_sockets, unsigned int *num_sockets, coap_tick_t now)
| Iterates through all the coap_socket_t structures embedded in endpoints or sessions associated with the `ctx` to determine which are wanting any read, write, accept or connect I/O (COAP_SOCKET_WANT_xxx is set).
COAP_API void | coap_io_do_io (coap_context_t *ctx, coap_tick_t now)
| Processes any outstanding read, write, accept or connect I/O as indicated in the coap_socket_t structures (COAP_SOCKET_CAN_xxx set) embedded in endpoints or sessions associated with `ctx`.
COAP_API unsigned int | coap_io_prepare_epoll (coap_context_t *ctx, coap_tick_t now)
| Any now timed out delayed packet is transmitted, along with any packets associated with requested observable response.
COAP_API void | coap_io_do_epoll (coap_context_t *ctx, struct epoll_event *events, size_t nevents)
| Process all the epoll events.
void | coap_lwip_dump_memory_pools (coap_log_t log_level)
| Dump the current state of the LwIP memory pools.
void | coap_lwip_set_input_wait_handler (coap_context_t *context, coap_lwip_input_wait_handler_t handler, void *input_arg)
| Set up a wait / timeout callback handler for use when the application calls coap_io_process().

## Detailed Description

CoAP context interface.

Definition in file coap_net.h.

## Macro Definition Documentation

## coap_read

#define coap_read | ( |  | ctx,
|  |  | now )

Value:
coap_io_do_io(ctx, now)
coap_io_do_io
COAP_API void coap_io_do_io(coap_context_t *ctx, coap_tick_t now)
Processes any outstanding read, write, accept or connect I/O as indicated in the coap_socket_t struct...
Definition coap_net.c:2306

Deprecated
  Use coap_io_do_io() instead.

This function just calls coap_io_do_io().

Internal function.

Parameters

  ctx | The CoAP context
  now | Current time

Definition at line 906 of file coap_net.h.

## COAP_RUN_BLOCK

#define COAP_RUN_BLOCK COAP_RUN_BLOCK_deprecated_use_COAP_IO_WAIT

Definition at line 910 of file coap_net.h.

## COAP_RUN_NONBLOCK

#define COAP_RUN_NONBLOCK COAP_RUN_NONBLOCK_deprecated_use_COAP_IO_NO_WAIT

Definition at line 909 of file coap_net.h.

## coap_run_once

#define coap_run_once | ( |  | ctx,
|  |  | timeout_ms )

Value:
coap_io_process(ctx, timeout_ms)
coap_io_process
COAP_API int coap_io_process(coap_context_t *ctx, uint32_t timeout_ms)
The main I/O processing function.
Definition coap_io.c:1581

Deprecated
  Use coap_io_process() instead.

This function just calls coap_io_process().

Parameters

  ctx | The CoAP context

  timeout_ms

  Minimum number of milliseconds to wait for new packets before returning after doing any processing. If COAP_IO_WAIT, the call will block until the next internal action (e.g. packet retransmit) if any, or block until the next packet is received whichever is the sooner and do the necessary processing. If COAP_IO_NO_WAIT, the function will return immediately after processing without waiting for any new input packets to arrive.

Returns
  Number of milliseconds spent in function or `-1` if there was an error

Definition at line 873 of file coap_net.h.

## coap_write

#define coap_write | ( |  | ctx,
|  |  | sockets,
|  |  | max_sockets,
|  |  | num_sockets,
|  |  | now )

Value:
coap_io_prepare_io(ctx, sockets, max_sockets, num_sockets, now)
coap_io_prepare_io
COAP_API unsigned int coap_io_prepare_io(coap_context_t *ctx, coap_socket_t *sockets[], unsigned int max_sockets, unsigned int *num_sockets, coap_tick_t now)
Iterates through all the coap_socket_t structures embedded in endpoints or sessions associated with t...
Definition coap_io.c:1303

Deprecated
  Use coap_io_prepare_io() instead.

This function just calls coap_io_prepare_io().

Internal function.

Parameters

  ctx | The CoAP context
  sockets | Array of socket descriptors, filled on output
  max_sockets | Size of socket array.
  num_sockets | Pointer to the number of valid entries in the socket arrays on output.
  now | Current time.

Returns
  timeout Maxmimum number of milliseconds that can be used by a select() to wait for network events or 0 if wait should be forever.

Definition at line 893 of file coap_net.h.