net.h File Reference
`#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_time.h"`
`#include "option.h"`
`#include "pdu.h"`
`#include "prng.h"`
`#include "coap_session.h"`
Include dependency graph for net.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | coap_queue_t
| Queue entry. More...
struct | coap_context_t
| The CoAP stack's global state is stored in a coap_context_t object. More...

## Macros

#define | COAP_RUN_BLOCK 0
#define | COAP_RUN_NONBLOCK 1

## Typedefs

typedef struct coap_queue_t | coap_queue_t
| Queue entry. More...
typedef void(* | coap_response_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id)
| Response handler that is used as call-back in coap_context_t. More...
typedef void(* | coap_nack_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_nack_reason_t reason, const coap_tid_t id)
| Negative Acknowedge handler that is used as call-back in coap_context_t. More...
typedef void(* | coap_ping_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *received, const coap_tid_t id)
| Recieved Ping handler that is used as call-back in coap_context_t. More...
typedef void(* | coap_pong_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *received, const coap_tid_t id)
| Recieved Pong handler that is used as call-back in coap_context_t. More...
typedef struct coap_context_t | coap_context_t
| The CoAP stack's global state is stored in a coap_context_t object. More...

## Functions

int | coap_insert_node (coap_queue_t **queue, coap_queue_t *node)
| Adds `node` to given `queue`, ordered by variable t in `node`. More...
int | coap_delete_node (coap_queue_t *node)
| Destroys specified `node`. More...
void | coap_delete_all (coap_queue_t *queue)
| Removes all items from given `queue` and frees the allocated storage. More...
coap_queue_t * | coap_new_node (void)
| Creates a new node suitable for adding to the CoAP sendqueue. More...
COAP_STATIC_INLINE 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 was received that matches an ongoing transaction. More...
COAP_STATIC_INLINE 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. More...
COAP_STATIC_INLINE 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. More...
COAP_STATIC_INLINE 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. More...
COAP_STATIC_INLINE void | coap_register_option (coap_context_t *ctx, uint16_t type)
| Registers the option type `type` with the given context object `ctx`. More...
unsigned int | coap_adjust_basetime (coap_context_t *ctx, coap_tick_t now)
| Set sendqueue_basetime in the given context object `ctx` to `now`. More...
coap_queue_t * | coap_peek_next (coap_context_t *context)
| Returns the next pdu to send without removing from sendqeue. More...
coap_queue_t * | coap_pop_next (coap_context_t *context)
| Returns the next pdu to send and removes it from the sendqeue. More...
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. More...
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. More...
int | coap_context_set_pki (coap_context_t *context, coap_dtls_pki_t *setup_data)
| Set the context's default PKI information for a server. More...
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. More...
void | coap_context_set_keepalive (coap_context_t *context, unsigned int seconds)
| Set the context keepalive timer for sessions. More...
int | coap_context_get_coap_fd (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. More...
COAP_STATIC_INLINE uint16_t | coap_new_message_id (coap_session_t *session)
| Returns a new message id and updates `session->tx_mid` accordingly. More...
void | coap_free_context (coap_context_t *context)
| CoAP stack context must be released with coap_free_context(). More...
void | coap_set_app_data (coap_context_t *context, void *data)
| Stores `data` with the given CoAP context. More...
void * | coap_get_app_data (const coap_context_t *context)
| Returns any application-specific data that has been stored with `context` using the function coap_set_app_data(). More...
coap_pdu_t * | coap_new_error_response (coap_pdu_t *request, unsigned char code, coap_opt_filter_t opts)
| Creates a new ACK PDU with specified error `code`. More...
coap_tid_t | coap_send_error (coap_session_t *session, coap_pdu_t *request, unsigned char code, coap_opt_filter_t opts)
| Sends an error response with code `code` for request `request` to `dst`. More...
coap_tid_t | coap_send_message_type (coap_session_t *session, coap_pdu_t *request, unsigned char type)
| Helper funktion to create and send a message with `type` (usually ACK or RST). More...
coap_tid_t | coap_send_ack (coap_session_t *session, coap_pdu_t *request)
| Sends an ACK message with code `0` for the specified `request` to `dst`. More...
COAP_STATIC_INLINE coap_tid_t | coap_send_rst (coap_session_t *session, coap_pdu_t *request)
| Sends an RST message with code `0` for the specified `request` to `dst`. More...
coap_tid_t | coap_send (coap_session_t *session, coap_pdu_t *pdu)
| Sends a CoAP message to given peer. More...
coap_tid_t | coap_retransmit (coap_context_t *context, coap_queue_t *node)
| Handles retransmissions of confirmable messages. More...
unsigned int | coap_write (coap_context_t *ctx, coap_socket_t *sockets[], unsigned int max_sockets, unsigned int *num_sockets, coap_tick_t now)
| For applications with their own message loop, send all pending retransmits and return the list of sockets with events to wait for and the next timeout The application should call coap_read, then coap_write again when any condition below is true: More...
void | coap_read (coap_context_t *ctx, coap_tick_t now)
| For applications with their own message loop, reads all data from the network. More...
int | coap_run_once (coap_context_t *ctx, unsigned int timeout_ms)
| The main message processing loop. More...
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. More...
void | coap_io_do_events (coap_context_t *ctx, struct epoll_event *events, size_t nevents)
| Process all the epoll events. More...
int | coap_handle_dgram (coap_context_t *ctx, coap_session_t *session, uint8_t *data, size_t data_len)
| Parses and interprets a CoAP datagram with context `ctx`. More...
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`. More...
int | coap_remove_from_queue (coap_queue_t **queue, coap_session_t *session, coap_tid_t id, coap_queue_t **node)
| This function removes the element with given `id` from the list given list. More...
coap_tid_t | coap_wait_ack (coap_context_t *context, coap_session_t *session, coap_queue_t *node)
coap_queue_t * | coap_find_transaction (coap_queue_t *queue, coap_session_t *session, coap_tid_t id)
| Retrieves transaction from the queue. More...
void | coap_cancel_all_messages (coap_context_t *context, coap_session_t *session, const uint8_t *token, size_t token_length)
| Cancels all outstanding messages for session `session` that have the specified token. More...
void | coap_cancel_session_messages (coap_context_t *context, coap_session_t *session, coap_nack_reason_t reason)
| Cancels all outstanding messages for session `session`. More...
void | coap_dispatch (coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu)
| Dispatches the PDUs from the receive queue in given context. More...
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. More...
void | coap_ticks (coap_tick_t *)
| Returns the current value of an internal tick counter. More...
int | coap_option_check_critical (coap_context_t *ctx, coap_pdu_t *pdu, coap_opt_filter_t unknown)
| Verifies that `pdu` contains no unknown critical options. More...
coap_pdu_t * | coap_wellknown_response (coap_context_t *context, coap_session_t *session, coap_pdu_t *request)
| Creates a new response for given `request` with the contents of ``.well-known/core. More...
unsigned int | coap_calc_timeout (coap_session_t *session, unsigned char r)
| Calculates the initial timeout based on the session CoAP transmission parameters 'ack_timeout', 'ack_random_factor', and COAP_TICKS_PER_SECOND. More...
int | coap_join_mcast_group (coap_context_t *ctx, const char *groupname)
| Function interface for joining a multicast group for listening. More...

## Macro Definition Documentation

## COAP_RUN_BLOCK

#define COAP_RUN_BLOCK 0

Definition at line 570 of file net.h.

## COAP_RUN_NONBLOCK

#define COAP_RUN_NONBLOCK 1

Definition at line 571 of file net.h.

## Typedef Documentation

## coap_context_t

typedef struct coap_context_t coap_context_t

The CoAP stack's global state is stored in a coap_context_t object.

## coap_nack_handler_t

typedef void(* coap_nack_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_nack_reason_t reason, const coap_tid_t id)

Negative Acknowedge handler that is used as call-back in coap_context_t.

Parameters

  context | CoAP session.
  session | CoAP session.
  sent | The PDU that was transmitted.
  reason | The reason for the NACK.
  id | CoAP transaction ID.

Definition at line 112 of file net.h.

## coap_ping_handler_t

typedef void(* coap_ping_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *received, const coap_tid_t id)

Recieved Ping handler that is used as call-back in coap_context_t.

Parameters

  context | CoAP session.
  session | CoAP session.
  received | The PDU that was received.
  id | CoAP transaction ID.

Definition at line 126 of file net.h.

## coap_pong_handler_t

typedef void(* coap_pong_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *received, const coap_tid_t id)

Recieved Pong handler that is used as call-back in coap_context_t.

Parameters

  context | CoAP session.
  session | CoAP session.
  received | The PDU that was received.
  id | CoAP transaction ID.

Definition at line 139 of file net.h.

## coap_queue_t

typedef struct coap_queue_t coap_queue_t

Queue entry.

## coap_response_handler_t

typedef void(* coap_response_handler_t) (struct coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id)

Response handler that is used as call-back in coap_context_t.

Parameters

  context | CoAP session.
  session | CoAP session.
  sent | The PDU that was transmitted.
  received | The PDU that was received.
  id | CoAP transaction ID.

Definition at line 97 of file net.h.

## Function Documentation

## coap_adjust_basetime()

unsigned int coap_adjust_basetime | ( | coap_context_t * | ctx,
|  | coap_tick_t | now
| ) |  |

Set sendqueue_basetime in the given context object `ctx` to `now`.

This function returns the number of elements in the queue head that have timed out.

Definition at line 145 of file net.c.

Here is the caller graph for this function:

## coap_calc_timeout()

unsigned int coap_calc_timeout | ( | coap_session_t * | session,
|  | unsigned char | r
| ) |  |

Calculates the initial timeout based on the session CoAP transmission parameters 'ack_timeout', 'ack_random_factor', and COAP_TICKS_PER_SECOND.

The calculation requires 'ack_timeout' and 'ack_random_factor' to be in Qx.FRAC_BITS fixed point notation, whereas the passed parameter `r` is interpreted as the fractional part of a Q0.MAX_BITS random value.

Parameters

  session | session timeout is associated with
  r | random value as fractional part of a Q0.MAX_BITS fixed point value

Returns
  COAP_TICKS_PER_SECOND * 'ack_timeout' * (1 + ('ack_random_factor' - 1) * r)

Definition at line 862 of file net.c.

Here is the caller graph for this function:

## coap_can_exit()

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.

Definition at line 2553 of file net.c.

## coap_cancel_all_messages()

void coap_cancel_all_messages | ( | coap_context_t * | context,
|  | coap_session_t * | session,
|  | const uint8_t * | token,
|  | size_t | token_length
| ) |  |

Cancels all outstanding messages for session `session` that have the specified token.

Parameters

  context | The context in use.
  session | Session of the messages to remove.
  token | Message token.
  token_length | Actual length of `token`.

Definition at line 1672 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_cancel_session_messages()

void coap_cancel_session_messages | ( | coap_context_t * | context,
|  | coap_session_t * | session,
|  | coap_nack_reason_t | reason
| ) |  |

Cancels all outstanding messages for session `session`.

Parameters

  context | The context in use.
  session | Session of the messages to remove.
  reason | The reasion for the session cancellation

Definition at line 1635 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_context_get_coap_fd()

int coap_context_get_coap_fd | ( | 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.

Parameters

  context | The coap_context_t object.

Returns
  The libcoap file descriptor or `-1` if epoll is not available.

Definition at line 413 of file net.c.

Here is the caller graph for this function:

## coap_context_set_keepalive()

void coap_context_set_keepalive | ( | coap_context_t * | context,
|  | unsigned int | seconds
| ) |  |

Set the context keepalive timer for sessions.

A keepalive message will be sent after if a session has been inactive, i.e. no packet sent or received, for the given number of seconds. For unreliable protocols, a CoAP Empty message will be sent. If a CoAP RST is not received, the CoAP Empty messages will get resent based on the Confirmable retry parameters until there is a failure timeout, at which point the session will be considered as disconnected. For reliable protocols, a CoAP PING message will be sent. If a CoAP PONG has not been received before the next PING is due to be sent, the session will be considered as disconnected.

Parameters

  context | The coap_context_t object.
  seconds | Number of seconds for the inactivity timer, or zero to disable CoAP-level keepalive messages.

Returns
  1 if successful, else 0

Definition at line 409 of file net.c.

Here is the caller graph for this function:

## coap_context_set_pki()

int coap_context_set_pki | ( | coap_context_t * | context,
|  | coap_dtls_pki_t * | setup_data
| ) |  |

Set the context's default PKI information for a server.

Parameters

  context | The current coap_context_t object.
  setup_data | If `NULL`, PKI authentication will fail. Certificate information required.

Returns
  `1` if successful, else `0`.

Definition at line 384 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_context_set_pki_root_cas()

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.

Parameters

  context | The current coap_context_t object.
  ca_file | If not `NULL`, is the full path name of a PEM encoded file containing all the Root CAs to be used.
  ca_dir | If not `NULL`, points to a directory containing PEM encoded files containing all the Root CAs to be used.

Returns
  `1` if successful, else `0`.

Definition at line 399 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_context_set_psk()

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.

Parameters

  context | The current coap_context_t object.
  hint | The default PSK server hint sent to a client. If `NULL`, PSK authentication is disabled. Empty string is a valid hint.
  key | The default PSK key. If `NULL`, PSK authentication will fail.
  key_len | The default PSK key's length. If `0`, PSK authentication will fail.

Returns
  `1` if successful, else `0`.

Definition at line 341 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_delete_all()

void coap_delete_all | ( | coap_queue_t * | queue | ) |

Removes all items from given `queue` and frees the allocated storage.

Parameters

  queue | The queue to delete.

Definition at line 239 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_delete_node()

int coap_delete_node | ( | coap_queue_t * | node | ) |

Destroys specified `node`.

Parameters

  node | Node entry to remove.

Returns
  `1` node deleted from queue, `0` failure.

Definition at line 219 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_dispatch()

void coap_dispatch | ( | coap_context_t * | context,
|  | coap_session_t * | session,
|  | coap_pdu_t * | pdu
| ) |  |

Dispatches the PDUs from the receive queue in given context.

Definition at line 2373 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_find_transaction()

coap_queue_t* coap_find_transaction | ( | coap_queue_t * | queue,
|  | coap_session_t * | session,
|  | coap_tid_t | id
| ) |  |

Retrieves transaction from the queue.

Parameters

  queue | The transaction queue to be searched.
  session | The session to find.
  id | The transaction id to find.

Returns
  A pointer to the transaction object or `NULL` if not found.

Definition at line 1713 of file net.c.

## coap_free_context()

void coap_free_context | ( | coap_context_t * | context | ) |

CoAP stack context must be released with coap_free_context().

This function clears all entries from the receive queue and send queue and deletes the resources that have been registered with `context`, and frees the attached endpoints.

Parameters

  context | The current coap_context_t object to free off.

Definition at line 552 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_get_app_data()

void* coap_get_app_data | ( | const coap_context_t * | context | ) |

Returns any application-specific data that has been stored with `context` using the function coap_set_app_data().

This function will return `NULL` if no data has been stored.

Parameters

  context | The CoAP context.

Returns
  The data previously stored or `NULL` if not data stored.

Definition at line 546 of file net.c.

Here is the caller graph for this function:

## coap_handle_dgram()

int coap_handle_dgram | ( | coap_context_t * | ctx,
|  | coap_session_t * | session,
|  | uint8_t * | data,
|  | size_t | data_len
| ) |  |

Parses and interprets a CoAP datagram with context `ctx`.

This function returns `0` if the datagram was handled, or a value less than zero on error.

Parameters

  ctx | The current CoAP context.
  session | The current CoAP session.
  data | The received packet'd data.
  data_len | The received packet'd data length.

Returns
  `0` if message was handled successfully, or less than zero on error.

Definition at line 1557 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_handle_event()

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`.

Parameters

  context | The CoAP context whose event handler is to be called.
  event | The event to deliver.
  session | The session related to `event`.

Returns
  The result from the associated event handler or 0 if none was registered.

Definition at line 2542 of file net.c.

Here is the caller graph for this function:

## coap_insert_node()

int coap_insert_node | ( | coap_queue_t ** | queue,
|  | coap_queue_t * | node
| ) |  |

Adds `node` to given `queue`, ordered by variable t in `node`.

Parameters

  queue | Queue to add to.
  node | Node entry to add to Queue.

Returns
  `1` added to queue, `0` failure.

Definition at line 182 of file net.c.

Here is the caller graph for this function:

## coap_io_do_events()

void coap_io_do_events | ( | coap_context_t * | ctx,
|  | struct epoll_event * | events,
|  | size_t | nevents
| ) |  |

Process all the epoll events.

Internal function

Parameters

  ctx | The current CoAP context.
  events | The list of events returned from an epoll_wait() call.
  nevents | The number of events.

Definition at line 1458 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_io_prepare_epoll()

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.

In addition, it returns when the next expected I/O is expected to take place (e.g. a packet retransmit).

Note: If epoll support is compiled into libcoap, coap_io_prepare_epoll() must be used instead of coap_write().

Internal function.

Parameters

  ctx | The CoAP context
  now | Current time.

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

Definition at line 1248 of file coap_io.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_join_mcast_group()

int coap_join_mcast_group | ( | coap_context_t * | ctx,
|  | const char * | groupname
| ) |  |

Function interface for joining a multicast group for listening.

Parameters

  ctx | The current context
  groupname | The name of the group that is to be joined for listening

Returns
  0 on success, -1 on error

Definition at line 2602 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_new_context()

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.

Definition at line 423 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_new_error_response()

coap_pdu_t* coap_new_error_response | ( | coap_pdu_t * | request,
|  | unsigned char | code,
|  | coap_opt_filter_t | opts
| ) |  |

Creates a new ACK PDU with specified error `code`.

The options specified by the filter expression `opts` will be copied from the original request contained in `request`. Unless `SHORT_ERROR_RESPONSE` was defined at build time, the textual reason phrase for `code` will be added as payload, with Content-Type `0`. This function returns a pointer to the new response message, or `NULL` on error. The storage allocated for the new message must be relased with coap_free().

Parameters

  request | Specification of the received (confirmable) request.
  code | The error code to set.
  opts | An option filter that specifies which options to copy from the original request in `node`.

Returns
  A pointer to the new message or `NULL` on error.

Definition at line 1721 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_new_message_id()

COAP_STATIC_INLINE uint16_t coap_new_message_id | ( | coap_session_t * | session | ) |

Returns a new message id and updates `session->tx_mid` accordingly.

The message id is returned in network byte order to make it easier to read in tracing tools.

Parameters

  session | The current coap_session_t object.

Returns
  Incremented message id in network byte order.

Definition at line 390 of file net.h.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_new_node()

coap_queue_t* coap_new_node | ( | void |  | ) |

Creates a new node suitable for adding to the CoAP sendqueue.

Returns
  New node entry, or `NULL` if failure.

Definition at line 248 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_option_check_critical()

int coap_option_check_critical | ( | coap_context_t * | ctx,
|  | coap_pdu_t * | pdu,
|  | coap_opt_filter_t | unknown
| ) |  |

Verifies that `pdu` contains no unknown critical options.

Options must be registered at `ctx`, using the function coap_register_option(). A basic set of options is registered automatically by coap_new_context(). This function returns `1` if `pdu` is ok, `0` otherwise. The given filter object `unknown` will be updated with the unknown options. As only `COAP_MAX_OPT` options can be signalled this way, remaining options must be examined manually.

coap_opt_filter_t f = COAP_OPT_NONE;
coap_opt_iterator_t opt_iter;
if (coap_option_check_critical(ctx, pdu, f) == 0) {
coap_option_iterator_init(pdu, &opt_iter, f);
while (coap_option_next(&opt_iter)) {
if (opt_iter.type & 0x01) {
... handle unknown critical option in opt_iter ...
}
}
}

Parameters

  ctx | The context where all known options are registered.
  pdu | The PDU to check.
  unknown | The output filter that will be updated to indicate the unknown critical options found in `pdu`.

Returns
  `1` if everything was ok, `0` otherwise.

Definition at line 617 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_peek_next()

coap_queue_t* coap_peek_next | ( | coap_context_t * | context | ) |

Returns the next pdu to send without removing from sendqeue.

Definition at line 262 of file net.c.

Here is the caller graph for this function:

## coap_pop_next()

coap_queue_t* coap_pop_next | ( | coap_context_t * | context | ) |

Returns the next pdu to send and removes it from the sendqeue.

Definition at line 270 of file net.c.

Here is the caller graph for this function:

## coap_read()

void coap_read | ( | coap_context_t * | ctx,
|  | coap_tick_t | now
| ) |  |

For applications with their own message loop, reads all data from the network.

Parameters

  ctx | The CoAP context
  now | Current time

Definition at line 1397 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_register_nack_handler()

COAP_STATIC_INLINE 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.

Parameters

  context | The context to register the handler for.
  handler | The nack handler to register.

Definition at line 242 of file net.h.

## coap_register_option()

COAP_STATIC_INLINE void coap_register_option | ( | coap_context_t * | ctx,
|  | uint16_t | type
| ) |  |

Registers the option type `type` with the given context object `ctx`.

Parameters

  ctx | The context to use.
  type | The option type to register.

Definition at line 280 of file net.h.

Here is the call graph for this function:

## coap_register_ping_handler()

COAP_STATIC_INLINE 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.

Parameters

  context | The context to register the handler for.
  handler | The ping handler to register.

Definition at line 255 of file net.h.

## coap_register_pong_handler()

COAP_STATIC_INLINE 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.

Parameters

  context | The context to register the handler for.
  handler | The pong handler to register.

Definition at line 268 of file net.h.

## coap_register_response_handler()

COAP_STATIC_INLINE 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 was received that matches an ongoing transaction.

Parameters

  context | The context to register the handler for.
  handler | The response handler to register.

Definition at line 227 of file net.h.

## coap_remove_from_queue()

int coap_remove_from_queue | ( | coap_queue_t ** | queue,
|  | coap_session_t * | session,
|  | coap_tid_t | id,
|  | coap_queue_t ** | node
| ) |  |

This function removes the element with given `id` from the list given list.

If `id` was found, `node` is updated to point to the removed element. Note that the storage allocated by `node` is not released. The caller must do this manually using coap_delete_node(). This function returns `1` if the element with id `id` was found, `0` otherwise. For a return value of `0`, the contents of `node` is undefined.

Parameters

  queue | The queue to search for `id`.
  session | The session to look for.
  id | The transaction id to look for.
  node | If found, `node` is updated to point to the removed node. You must release the storage pointed to by `node` manually.

Returns
  `1` if `id` was found, `0` otherwise.

Definition at line 1585 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_retransmit()

coap_tid_t coap_retransmit | ( | coap_context_t * | context,
|  | coap_queue_t * | node
| ) |  |

Handles retransmissions of confirmable messages.

Parameters

  context | The CoAP context.
  node | The node to retransmit.

Returns
  The message id of the sent message or `COAP_INVALID_TID` on error.

Definition at line 1021 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_run_once()

int coap_run_once | ( | coap_context_t * | ctx,
|  | unsigned int | timeout_ms
| ) |  |

The main message processing loop.

Parameters

  ctx | The CoAP context
  timeout_ms | Minimum number of milliseconds to wait for new packets before returning. If COAP_RUN_BLOCK, the call will block until at least one new packet is received. If COAP_RUN_NONBLOCK, the function will return immediately following without waiting for any new input not already available.

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

## coap_send()

coap_tid_t coap_send | ( | coap_session_t * | session,
|  | coap_pdu_t * | pdu
| ) |  |

Sends a CoAP message to given peer.

The memory that is allocated by pdu will be released by coap_send(). The caller must not use the pdu after calling coap_send().

Parameters

  session | The CoAP session.
  pdu | The CoAP PDU to send.

Returns
  The message id of the sent message or `COAP_INVALID_TID` on error.

Definition at line 966 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_send_ack()

coap_tid_t coap_send_ack | ( | coap_session_t * | session,
|  | coap_pdu_t * | request
| ) |  |

Sends an ACK message with code `0` for the specified `request` to `dst`.

This function returns the corresponding transaction id if the message was sent or `COAP_INVALID_TID` on error.

Parameters

  session | The CoAP session.
  request | The request to be acknowledged.

Returns
  The transaction id if ACK was sent or `COAP_INVALID_TID` on error.

Definition at line 669 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_send_error()

coap_tid_t coap_send_error | ( | coap_session_t * | session,
|  | coap_pdu_t * | request,
|  | unsigned char | code,
|  | coap_opt_filter_t | opts
| ) |  |

Sends an error response with code `code` for request `request` to `dst`.

`opts` will be passed to coap_new_error_response() to copy marked options from the request. This function returns the transaction id if the message was sent, or `COAP_INVALID_TID` otherwise.

Parameters

  session | The CoAP session.
  request | The original request to respond to.
  code | The response code.
  opts | A filter that specifies the options to copy from the `request`.

Returns
  The transaction id if the message was sent, or `COAP_INVALID_TID` otherwise.

Definition at line 818 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_send_message_type()

coap_tid_t coap_send_message_type | ( | coap_session_t * | session,
|  | coap_pdu_t * | request,
|  | unsigned char | type
| ) |  |

Helper funktion to create and send a message with `type` (usually ACK or RST).

This function returns `COAP_INVALID_TID` when the message was not sent, a valid transaction id otherwise.

Parameters

  session | The CoAP session.
  request | The request that should be responded to.
  type | Which type to set.

Returns
  transaction id on success or `COAP_INVALID_TID` otherwise.

Definition at line 836 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_send_rst()

COAP_STATIC_INLINE coap_tid_t coap_send_rst | ( | coap_session_t * | session,
|  | coap_pdu_t * | request
| ) |  |

Sends an RST message with code `0` for the specified `request` to `dst`.

This function returns the corresponding transaction id if the message was sent or `COAP_INVALID_TID` on error.

Parameters

  session | The CoAP session.
  request | The request to be reset.

Returns
  The transaction id if RST was sent or `COAP_INVALID_TID` on error.

Definition at line 506 of file net.h.

Here is the call graph for this function:

## coap_set_app_data()

void coap_set_app_data | ( | coap_context_t * | context,
|  | void * | data
| ) |  |

Stores `data` with the given CoAP context.

This function overwrites any value that has previously been stored with `context`.

Parameters

  context | The CoAP context.
  data | The data to store with wih the context. Note that this data must be valid during the lifetime of `context`.

Definition at line 540 of file net.c.

Here is the caller graph for this function:

## coap_ticks()

void coap_ticks | ( | coap_tick_t * |  | ) |

Returns the current value of an internal tick counter.

The counter counts `COAP_TICKS_PER_SECOND` ticks every second.

## coap_wait_ack()

coap_tid_t coap_wait_ack | ( | coap_context_t * | context,
|  | coap_session_t * | session,
|  | coap_queue_t * | node
| ) |  |

Definition at line 888 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_wellknown_response()

coap_pdu_t* coap_wellknown_response | ( | coap_context_t * | context,
|  | coap_session_t * | session,
|  | coap_pdu_t * | request
| ) |  |

Creates a new response for given `request` with the contents of ``.well-known/core.

The result is NULL on error or a newly allocated PDU that must be either sent with coap_sent() or released by coap_delete_pdu().

Parameters

  context | The current coap context to use.
  session | The CoAP session.
  request | The request for ``.well-known/core .

Returns
  A new 2.05 response for ``.well-known/core or NULL on error.

Definition at line 1837 of file net.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## coap_write()

unsigned int coap_write | ( | coap_context_t * | ctx,
|  | coap_socket_t * | sockets[],
|  | unsigned int | max_sockets,
|  | unsigned int * | num_sockets,
|  | coap_tick_t | now
| ) |  |

For applications with their own message loop, send all pending retransmits and return the list of sockets with events to wait for and the next timeout The application should call coap_read, then coap_write again when any condition below is true:

- data is available on any of the sockets with the COAP_SOCKET_WANT_READ
- an incoming connection is pending in the listen queue and the COAP_SOCKET_WANT_ACCEPT flag is set
- at least some data can be written without blocking on any of the sockets with the COAP_SOCKET_WANT_WRITE flag set
- a connection event occured (success or failure) and the COAP_SOCKET_WANT_CONNECT flag is set
- the timeout has expired Before calling coap_read or coap_write again, the application should position COAP_SOCKET_CAN_READ and COAP_SOCKET_CAN_WRITE flags as applicable.

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 as maxmimum number of milliseconds that the application should wait for network events or 0 if the application should wait forever.

Definition at line 1294 of file coap_io.c.

Here is the call graph for this function:
Here is the caller graph for this function: