net.c File Reference
`#include "coap_config.h"`
`#include <ctype.h>`
`#include <stdio.h>`
`#include <errno.h>`
`#include <sys/types.h>`
`#include "debug.h"`
`#include "mem.h"`
`#include "str.h"`
`#include "async.h"`
`#include "resource.h"`
`#include "option.h"`
`#include "encode.h"`
`#include "block.h"`
`#include "net.h"`
Include dependency graph for net.c:

Go to the source code of this file.

## Macros

#define | COAP_DEFAULT_ACK_TIMEOUT 2 /* see RFC 7252, Section 4.8 */
| Number of seconds when to expect an ACK or a response to an outstanding CON message. More...
#define | COAP_DEFAULT_ACK_RANDOM_FACTOR 1.5 /* see RFC 7252, Section 4.8 */
| A factor that is used to randomize the wait time before a message is retransmitted to prevent synchronization effects. More...
#define | COAP_DEFAULT_MAX_RETRANSMIT 4 /* see RFC 7252, Section 4.8 */
| Number of message retransmissions before message sending is stopped. More...
#define | COAP_DEFAULT_NSTART 1 /* see RFC 7252, Section 4.8 */
| The number of simultaneous outstanding interactions that a client maintains to a given server. More...
#define | FRAC_BITS 6
| The number of bits for the fractional part of ACK_TIMEOUT and ACK_RANDOM_FACTOR. More...
#define | MAX_BITS 8
| The maximum number of bits for fixed point integers that are used for retransmission time calculation. More...
#define | Q(frac, fval) ((unsigned short)(((1 << (frac)) * (fval))))
| creates a Qx.frac from fval More...
#define | ACK_RANDOM_FACTOR Q(FRAC_BITS, COAP_DEFAULT_ACK_RANDOM_FACTOR)
| creates a Qx.FRAC_BITS from COAP_DEFAULT_ACK_RANDOM_FACTOR More...
#define | ACK_TIMEOUT Q(FRAC_BITS, COAP_DEFAULT_ACK_TIMEOUT)
| creates a Qx.FRAC_BITS from COAP_DEFAULT_ACK_TIMEOUT More...
#define | FP1 Q(FRAC_BITS, 1)
#define | SHR_FP(val, frac) (((val) + (1 << ((frac) - 1))) >> (frac))
#define | INET6_ADDRSTRLEN 40
#define | SZX_TO_BYTES(SZX) ((size_t)(1 << ((SZX) + 4)))
#define | WANT_WKC(Pdu, Key) (((Pdu)->hdr->code == COAP_REQUEST_GET) && is_wkc(Key))

## Enumerations

enum | respond_t { RESPONSE_DEFAULT, RESPONSE_DROP, RESPONSE_SEND }
| Internal flags to control the treatment of responses (specifically in presence of the No-Response option). More...

## Functions

static coap_queue_t * | coap_malloc_node (void)
static void | coap_free_node (coap_queue_t *node)
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...
int | coap_insert_node (coap_queue_t **queue, coap_queue_t *node)
| Adds node to given queue, ordered by node->t. 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_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...
int | is_wkc (coap_key_t k)
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...
void | coap_free_context (coap_context_t *context)
| CoAP stack context must be released with coap_free_context(). 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...
void | coap_transaction_id (const coap_address_t *peer, const coap_pdu_t *pdu, coap_tid_t *id)
| Calculates a unique transaction id from given arguments `peer` and `pdu`. More...
coap_tid_t | coap_send_ack (coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *request)
| Sends an ACK message with code `0` for the specified `request` to `dst`. More...
static coap_tid_t | coap_send_impl (coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *pdu)
coap_tid_t | coap_send (coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *pdu)
| Sends a non-confirmed CoAP message to given destination. More...
coap_tid_t | coap_send_error (coap_context_t *context, coap_pdu_t *request, const coap_endpoint_t *local_interface, const coap_address_t *dst, 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_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *request, unsigned char type)
| Helper funktion to create and send a message with `type` (usually ACK or RST). More...
static unsigned int | calc_timeout (unsigned char r)
| Calculates the initial timeout based on the global CoAP transmission parameters ACK_TIMEOUT, ACK_RANDOM_FACTOR, and COAP_TICKS_PER_SECOND. More...
coap_tid_t | coap_send_confirmed (coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, coap_pdu_t *pdu)
| Sends a confirmed CoAP message to given destination. More...
coap_tid_t | coap_retransmit (coap_context_t *context, coap_queue_t *node)
| Handles retransmissions of confirmable messages. More...
void | coap_dispatch (coap_context_t *context, coap_queue_t *rcvd)
| Dispatches the PDUs from the receive queue in given context. More...
int | coap_read (coap_context_t *ctx)
| Reads data from the network and tries to parse as CoAP PDU. More...
int | coap_handle_message (coap_context_t *ctx, coap_packet_t *packet)
| Parses and interprets a CoAP message with context `ctx`. More...
int | coap_remove_from_queue (coap_queue_t **queue, coap_tid_t id, coap_queue_t **node)
| This function removes the element with given `id` from the list given list. More...
static int | token_match (const unsigned char *a, size_t alen, const unsigned char *b, size_t blen)
void | coap_cancel_all_messages (coap_context_t *context, const coap_address_t *dst, const unsigned char *token, size_t token_length)
| Cancels all outstanding messages for peer `dst` that have the specified token. More...
coap_queue_t * | coap_find_transaction (coap_queue_t *queue, coap_tid_t id)
| Retrieves transaction from the queue. 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...
static size_t | get_wkc_len (coap_context_t *context, coap_opt_t *query_filter)
| Quick hack to determine the size of the resource description for .well-known/core. More...
coap_pdu_t * | coap_wellknown_response (coap_context_t *context, coap_pdu_t *request)
| Creates a new response for given `request` with the contents of ``.well-known/core. More...
static int | coap_cancel (coap_context_t *context, const coap_queue_t *sent)
| This function cancels outstanding messages for the remote peer and token specified in `sent`. More...
static enum respond_t | no_response (coap_pdu_t *request, coap_pdu_t *response)
| Checks for No-Response option in given `request` and returns `1` if `response` should be suppressed according to RFC 7967. More...
static void | handle_request (coap_context_t *context, coap_queue_t *node)
static void | handle_response (coap_context_t *context, coap_queue_t *sent, coap_queue_t *rcvd)
static int | handle_locally (coap_context_t *context, coap_queue_t *node)
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...

## Variables

time_t | clock_offset

## Macro Definition Documentation

## ACK_RANDOM_FACTOR

#define ACK_RANDOM_FACTOR Q(FRAC_BITS, COAP_DEFAULT_ACK_RANDOM_FACTOR)

creates a Qx.FRAC_BITS from COAP_DEFAULT_ACK_RANDOM_FACTOR

Definition at line 110 of file net.c.

## ACK_TIMEOUT

#define ACK_TIMEOUT Q(FRAC_BITS, COAP_DEFAULT_ACK_TIMEOUT)

creates a Qx.FRAC_BITS from COAP_DEFAULT_ACK_TIMEOUT

Definition at line 114 of file net.c.

## FP1

#define FP1 Q(FRAC_BITS, 1)

## FRAC_BITS

#define FRAC_BITS 6

The number of bits for the fractional part of ACK_TIMEOUT and ACK_RANDOM_FACTOR.

Must be less or equal 8.

Definition at line 94 of file net.c.

## INET6_ADDRSTRLEN

#define INET6_ADDRSTRLEN 40

## MAX_BITS

#define MAX_BITS 8

The maximum number of bits for fixed point integers that are used for retransmission time calculation.

Currently this must be `8`.

Definition at line 100 of file net.c.

## Q

#define Q | ( |  | frac,
|  |  | fval
| ) |  | ((unsigned short)(((1 << (frac)) * (fval))))

creates a Qx.frac from fval

Definition at line 107 of file net.c.

## SHR_FP

#define SHR_FP | ( |  | val,
|  |  | frac
| ) |  | (((val) + (1 << ((frac) - 1))) >> (frac))

## SZX_TO_BYTES

#define SZX_TO_BYTES | ( |  | SZX | ) | ((size_t)(1 << ((SZX) + 4)))

Definition at line 1140 of file net.c.

## WANT_WKC

#define WANT_WKC | ( |  | Pdu,
|  |  | Key
| ) |  | (((Pdu)->hdr->code == COAP_REQUEST_GET) && is_wkc(Key))

Definition at line 1367 of file net.c.

## Enumeration Type Documentation

## respond_t

enum respond_t

Internal flags to control the treatment of responses (specifically in presence of the No-Response option).

Enumerator
RESPONSE_DEFAULT |
RESPONSE_DROP |
RESPONSE_SEND |

Definition at line 1303 of file net.c.

## Function Documentation

## calc_timeout()

static unsigned int calc_timeout | ( | unsigned char | r | ) |

inline static

Calculates the initial timeout based on the global 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

  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 673 of file net.c.

Here is the caller graph for this function:

## 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 180 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 1671 of file net.c.

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

## coap_cancel()

static int coap_cancel | ( | coap_context_t * | context,
|  | const coap_queue_t * | sent
| ) |  |

static

This function cancels outstanding messages for the remote peer and token specified in `sent`.

Any observation relationship for sent->remote and the token are removed. Calling this function is required when receiving an RST message (usually in response to a notification) or a GET request with the Observe option set to 1.

This function returns `0` when the token is unknown with this peer, or a value greater than zero otherwise.

Definition at line 1277 of file net.c.

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

## coap_cancel_all_messages()

void coap_cancel_all_messages | ( | coap_context_t * | context,
|  | const coap_address_t * | dst,
|  | const unsigned char * | token,
|  | size_t | token_length
| ) |  |

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

Parameters

  context | The context in use.
  dst | Destination address of the messages to remove.
  token | Message token.
  token_length | Actual length of `token`.

Definition at line 980 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.

Definition at line 265 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.

Definition at line 254 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_queue_t * | rcvd
| ) |  |

Dispatches the PDUs from the receive queue in given context.

Definition at line 1564 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_tid_t | id
| ) |  |

Retrieves transaction from the queue.

Parameters

  queue | The transaction queue to be searched.
  id | Unique key of the transaction to find.

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

Definition at line 1020 of file net.c.

Here is the caller graph for this function:

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

Definition at line 418 of file net.c.

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

## coap_free_node()

static void coap_free_node | ( | coap_queue_t * | node | ) |

inline static

Definition at line 126 of file net.c.

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

## coap_handle_message()

int coap_handle_message | ( | coap_context_t * | ctx,
|  | coap_packet_t * | packet
| ) |  |

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

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

Parameters

  ctx | The current CoAP context.
  packet | The received packet.

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

get debug to work again ** unsigned char addr[INET6_ADDRSTRLEN+8], localaddr[INET6_ADDRSTRLEN+8]; if (coap_print_addr(remote, addr, INET6_ADDRSTRLEN+8) && coap_print_addr(&packet->dst, localaddr, INET6_ADDRSTRLEN+8) ) debug("** received %d bytes from %s on interface %s:\n", (int)msg_len, addr, localaddr);

Definition at line 845 of file net.c.

Here is the call graph for this function:
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 node->t.

Definition at line 217 of file net.c.

Here is the caller graph for this function:

## coap_malloc_node()

static coap_queue_t* coap_malloc_node | ( | void |  | ) |

inline static

Definition at line 121 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 333 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 1028 of file net.c.

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.

Definition at line 274 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 443 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 290 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 298 of file net.c.

Here is the caller graph for this function:

## coap_read()

int coap_read | ( | coap_context_t * | context | ) |

Reads data from the network and tries to parse as CoAP PDU.

On success, 0 is returned and a new node with the parsed PDU is added to the receive queue in the specified context object.

Definition at line 822 of file net.c.

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

## coap_remove_from_queue()

int coap_remove_from_queue | ( | coap_queue_t ** | queue,
|  | 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`.
  id | The node 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 930 of file net.c.

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.

Definition at line 771 of file net.c.

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

## coap_send()

coap_tid_t coap_send | ( | coap_context_t * | context,
|  | const coap_endpoint_t * | local_interface,
|  | const coap_address_t * | dst,
|  | coap_pdu_t * | pdu
| ) |  |

Sends a non-confirmed CoAP message to given destination.

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

Parameters

  context | The CoAP context to use.
  local_interface | The local network interface where the outbound packet is sent.
  dst | The address to send to.
  pdu | The CoAP PDU to send.

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

Definition at line 613 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_context_t * | context,
|  | const coap_endpoint_t * | local_interface,
|  | const coap_address_t * | dst,
|  | 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

  context | The context to use.
  local_interface | The local network interface where the outbound packet is sent.
  dst | The destination address.
  request | The request to be acknowledged.

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

Definition at line 533 of file net.c.

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

## coap_send_confirmed()

coap_tid_t coap_send_confirmed | ( | coap_context_t * | context,
|  | const coap_endpoint_t * | local_interface,
|  | const coap_address_t * | dst,
|  | coap_pdu_t * | pdu
| ) |  |

Sends a confirmed CoAP message to given destination.

The memory that is allocated by pdu will not be released by coap_send_confirmed(). The caller must release the memory.

Parameters

  context | The CoAP context to use.
  local_interface | The local network interface where the outbound packet is sent.
  dst | The address to send to.
  pdu | The CoAP PDU to send.

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

Definition at line 699 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_context_t * | context,
|  | coap_pdu_t * | request,
|  | const coap_endpoint_t * | local_interface,
|  | const coap_address_t * | dst,
|  | 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

  context | The context to use.
  request | The original request to respond to.
  local_interface | The local network interface where the outbound packet is sent.
  dst | The remote peer that sent the request.
  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 621 of file net.c.

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

## coap_send_impl()

static coap_tid_t coap_send_impl | ( | coap_context_t * | context,
|  | const coap_endpoint_t * | local_interface,
|  | const coap_address_t * | dst,
|  | coap_pdu_t * | pdu
| ) |  |

static

Definition at line 553 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_context_t * | context,
|  | const coap_endpoint_t * | local_interface,
|  | const coap_address_t * | dst,
|  | 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

  context | The CoAP context.
  local_interface | The local network interface where the outbound packet is sent.
  dst | Where to send the context.
  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 643 of file net.c.

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

## coap_transaction_id()

void coap_transaction_id | ( | const coap_address_t * | peer,
|  | const coap_pdu_t * | pdu,
|  | coap_tid_t * | id
| ) |  |

Calculates a unique transaction id from given arguments `peer` and `pdu`.

The id is returned in `id`.

Parameters

  peer | The remote party who sent `pdu`.
  pdu | The message that initiated the transaction.
  id | Set to the new id.

Definition at line 495 of file net.c.

Here is the caller graph for this function:

## coap_wellknown_response()

coap_pdu_t* coap_wellknown_response | ( | coap_context_t * | context,
|  | 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 released by coap_delete_pdu().

Parameters

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

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

Definition at line 1143 of file net.c.

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

## get_wkc_len()

static size_t get_wkc_len | ( | coap_context_t * | context,
|  | coap_opt_t * | query_filter
| ) |  |

inline static

Quick hack to determine the size of the resource description for .well-known/core.

Definition at line 1125 of file net.c.

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

## handle_locally()

static int handle_locally | ( | coap_context_t * | context,
|  | coap_queue_t * | node
| ) |  |

inline static

Definition at line 1557 of file net.c.

Here is the caller graph for this function:

## handle_request()

static void handle_request | ( | coap_context_t * | context,
|  | coap_queue_t * | node
| ) |  |

static

Definition at line 1371 of file net.c.

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

## handle_response()

static void handle_response | ( | coap_context_t * | context,
|  | coap_queue_t * | sent,
|  | coap_queue_t * | rcvd
| ) |  |

inline static

Definition at line 1531 of file net.c.

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

## is_wkc()

int is_wkc | ( | coap_key_t | k | ) |

Definition at line 321 of file net.c.

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

## no_response()

static enum respond_t no_response | ( | coap_pdu_t * | request,
|  | coap_pdu_t * | response
| ) |  |

static

Checks for No-Response option in given `request` and returns `1` if `response` should be suppressed according to RFC 7967.

The value of the No-Response option is encoded as follows:

+----—+--------------------—+--------------------------------—+ | Value | Binary Representation | Description | +----—+--------------------—+--------------------------------—+ | 0 | <empty> | Interested in all responses. | +----—+--------------------—+--------------------------------—+ | 2 | 00000010 | Not interested in 2.xx responses. | +----—+--------------------—+--------------------------------—+ | 8 | 00001000 | Not interested in 4.xx responses. | +----—+--------------------—+--------------------------------—+ | 16 | 00010000 | Not interested in 5.xx responses. | +----—+--------------------—+--------------------------------—+

Parameters

  request | The CoAP request to check for the No-Response option. This parameter must not be NULL.
  response | The response that is potentially suppressed. This parameter must not be NULL.

Returns
  RESPONSE_DEFAULT when no special treatment is requested, RESPONSE_DROP when the response must be discarded, or RESPONSE_SEND when the response must be sent.

Definition at line 1334 of file net.c.

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

## token_match()

static int token_match | ( | const unsigned char * | a,
|  | size_t | alen,
|  | const unsigned char * | b,
|  | size_t | blen
| ) |  |

inline static

Definition at line 974 of file net.c.

Here is the caller graph for this function:

## Variable Documentation

## clock_offset

time_t clock_offset

Definition at line 118 of file net.c.