coap_net_internal.h
Go to the documentation of this file.
/*
* coap_context_internal.h -- Structures, Enums & Functions that are not
* exposed to application programming
*
* Copyright (C) 2010-2021 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_NET_INTERNAL_H_
#define COAP_NET_INTERNAL_H_
struct coap_queue_t {
struct coap_queue_t *next;
coap_tick_t t;
unsigned char retransmit_cnt;
unsigned int timeout;
coap_session_t *session;
coap_mid_t id;
coap_pdu_t *pdu;
};
struct coap_context_t {
coap_opt_filter_t known_options;
coap_resource_t *resources;
coap_resource_t *unknown_resource;
coap_resource_t *proxy_uri_resource;
coap_resource_release_userdata_handler_t release_userdata;
#ifndef WITHOUT_ASYNC
coap_async_t *async_state;
#endif /* WITHOUT_ASYNC */
coap_tick_t sendqueue_basetime;
coap_queue_t *sendqueue;
coap_endpoint_t *endpoint;
coap_session_t *sessions;
#ifdef WITH_CONTIKI
struct uip_udp_conn *conn;
struct etimer retransmit_timer;
struct etimer notify_timer;
#endif /* WITH_CONTIKI */
#ifdef WITH_LWIP
uint8_t timer_configured;
#endif /* WITH_LWIP */
coap_response_handler_t response_handler;
coap_nack_handler_t nack_handler;
coap_ping_handler_t ping_handler;
coap_pong_handler_t pong_handler;
coap_event_handler_t handle_event;
ssize_t (*network_send)(coap_socket_t *sock, const coap_session_t *session,
const uint8_t *data, size_t datalen);
ssize_t (*network_read)(coap_socket_t *sock, coap_packet_t *packet);
size_t(*get_client_psk)(const coap_session_t *session, const uint8_t *hint,
size_t hint_len, uint8_t *identity,
size_t *identity_len, size_t max_identity_len,
uint8_t *psk, size_t max_psk_len);
size_t(*get_server_psk)(const coap_session_t *session,
const uint8_t *identity, size_t identity_len,
uint8_t *psk, size_t max_psk_len);
size_t(*get_server_hint)(const coap_session_t *session, uint8_t *hint,
size_t max_hint_len);
void *dtls_context;
coap_dtls_spsk_t spsk_setup_data;
unsigned int session_timeout;
unsigned int max_idle_sessions;
unsigned int max_handshake_sessions;
unsigned int ping_timeout;
unsigned int csm_timeout;
uint8_t observe_pending;
uint8_t block_mode;
uint64_t etag;
coap_cache_entry_t *cache;
uint16_t *cache_ignore_options;
size_t cache_ignore_count;
void *app;
#ifdef COAP_EPOLL_SUPPORT
int epfd;
int eptimerfd;
coap_tick_t next_timeout;
#endif /* COAP_EPOLL_SUPPORT */
};
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node);
int coap_delete_node(coap_queue_t *node);
void coap_delete_all(coap_queue_t *queue);
coap_queue_t *coap_new_node(void);
unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now);
coap_queue_t *coap_peek_next( coap_context_t *context );
coap_queue_t *coap_pop_next( coap_context_t *context );
coap_mid_t coap_retransmit(coap_context_t *context, coap_queue_t *node);
int coap_handle_dgram(coap_context_t *ctx, coap_session_t *session, uint8_t *data, size_t data_len);
int coap_remove_from_queue(coap_queue_t **queue,
coap_session_t *session,
coap_mid_t id,
coap_queue_t **node);
coap_mid_t
coap_wait_ack( coap_context_t *context, coap_session_t *session,
coap_queue_t *node);
void coap_cancel_all_messages(coap_context_t *context,
coap_session_t *session,
const uint8_t *token,
size_t token_length);
void
coap_cancel_session_messages(coap_context_t *context,
coap_session_t *session,
coap_nack_reason_t reason);
void coap_dispatch(coap_context_t *context, coap_session_t *session,
coap_pdu_t *pdu);
int coap_option_check_critical(coap_context_t *ctx,
coap_pdu_t *pdu,
coap_opt_filter_t *unknown);
coap_pdu_t *coap_wellknown_response(coap_context_t *context,
coap_session_t *session,
coap_pdu_t *request);
unsigned int coap_calc_timeout(coap_session_t *session, unsigned char r);
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu);
#endif /* COAP_NET_INTERNAL_H_ */
coap_nack_reason_t
coap_nack_reason_t
Definition: coap_io.h:64
coap_tick_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:122
coap_resource_release_userdata_handler_t
void(* coap_resource_release_userdata_handler_t)(void *user_data)
Definition of release resource user_data callback function.
Definition: resource.h:212
coap_peek_next
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
Definition: net.c:274
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.
Definition: net.c:157
coap_delete_all
void coap_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
Definition: net.c:251
coap_remove_from_queue
int coap_remove_from_queue(coap_queue_t **queue, coap_session_t *session, coap_mid_t id, coap_queue_t **node)
This function removes the element with given id from the list given list.
Definition: net.c:1935
coap_delete_node
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
Definition: net.c:231
coap_new_node
coap_queue_t * coap_new_node(void)
Creates a new node suitable for adding to the CoAP sendqueue.
Definition: net.c:260
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: net.c:282
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.
Definition: net.c:2188
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: net.c:2980
coap_send_internal
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
Definition: net.c:1154
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.
Definition: net.c:194
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',...
Definition: net.c:947
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.
Definition: net.c:700
coap_retransmit
coap_mid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
Definition: net.c:1337
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.
Definition: net.c:2016
coap_wait_ack
coap_mid_t coap_wait_ack(coap_context_t *context, coap_session_t *session, coap_queue_t *node)
Definition: net.c:973
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.
Definition: net.c:1979
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.
Definition: net.c:1898
coap_pong_handler_t
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.
Definition: net.h:90
coap_response_handler_t
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.
Definition: net.h:54
coap_ping_handler_t
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.
Definition: net.h:79
coap_nack_handler_t
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.
Definition: net.h:67
coap_event_handler_t
int(* coap_event_handler_t)(coap_session_t *session, const coap_event_t event)
Type for event handler functions that can be registered with a CoAP context using the unction coap_se...
Definition: coap_event.h:63
coap_mid_t
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition: pdu.h:231
coap_async_t
Definition: coap_async_internal.h:33
coap_cache_entry_t
Definition: coap_cache_internal.h:38
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition: coap_net_internal.h:45
coap_context_t::sendqueue_basetime
coap_tick_t sendqueue_basetime
The time stamp in the first element of the sendqeue is relative to sendqueue_basetime.
Definition: coap_net_internal.h:66
coap_context_t::pong_handler
coap_pong_handler_t pong_handler
Definition: coap_net_internal.h:87
coap_context_t::etag
uint64_t etag
Next ETag to use.
Definition: coap_net_internal.h:131
coap_context_t::csm_timeout
unsigned int csm_timeout
Timeout for waiting for a CSM from the remote side.
Definition: coap_net_internal.h:127
coap_context_t::app
void * app
application-specific data
Definition: coap_net_internal.h:138
coap_context_t::async_state
coap_async_t * async_state
list of asynchronous message ids
Definition: coap_net_internal.h:60
coap_context_t::sessions
coap_session_t * sessions
client sessions
Definition: coap_net_internal.h:69
coap_context_t::nack_handler
coap_nack_handler_t nack_handler
Definition: coap_net_internal.h:85
coap_context_t::ping_timeout
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
Definition: coap_net_internal.h:124
coap_context_t::get_server_psk
size_t(* get_server_psk)(const coap_session_t *session, const uint8_t *identity, size_t identity_len, uint8_t *psk, size_t max_psk_len)
Definition: coap_net_internal.h:104
coap_context_t::resources
coap_resource_t * resources
hash table or list of known resources
Definition: coap_net_internal.h:47
coap_context_t::network_send
ssize_t(* network_send)(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
Definition: coap_net_internal.h:95
coap_context_t::cache_ignore_options
uint16_t * cache_ignore_options
CoAP options to ignore when creating a cache-key.
Definition: coap_net_internal.h:134
coap_context_t::dtls_context
void * dtls_context
Definition: coap_net_internal.h:110
coap_context_t::known_options
coap_opt_filter_t known_options
Definition: coap_net_internal.h:46
coap_context_t::release_userdata
coap_resource_release_userdata_handler_t release_userdata
function to release user_data when resource is deleted
Definition: coap_net_internal.h:53
coap_context_t::ping_handler
coap_ping_handler_t ping_handler
Definition: coap_net_internal.h:86
coap_context_t::cache_ignore_count
size_t cache_ignore_count
The number of CoAP options to ignore when creating a cache-key.
Definition: coap_net_internal.h:136
coap_context_t::max_handshake_sessions
unsigned int max_handshake_sessions
Maximum number of simultaneous negotating sessions per endpoint.
Definition: coap_net_internal.h:121
coap_context_t::sendqueue
coap_queue_t * sendqueue
Definition: coap_net_internal.h:67
coap_context_t::response_handler
coap_response_handler_t response_handler
Definition: coap_net_internal.h:84
coap_context_t::cache
coap_cache_entry_t * cache
CoAP cache-entry cache.
Definition: coap_net_internal.h:133
coap_context_t::observe_pending
uint8_t observe_pending
Observe response pending.
Definition: coap_net_internal.h:129
coap_context_t::endpoint
coap_endpoint_t * endpoint
the endpoints used for listening
Definition: coap_net_internal.h:68
coap_context_t::get_server_hint
size_t(* get_server_hint)(const coap_session_t *session, uint8_t *hint, size_t max_hint_len)
Definition: coap_net_internal.h:107
coap_context_t::handle_event
coap_event_handler_t handle_event
Callback function that is used to signal events to the application.
Definition: coap_net_internal.h:93
coap_context_t::session_timeout
unsigned int session_timeout
Number of seconds of inactivity after which an unused session will be closed.
Definition: coap_net_internal.h:115
coap_context_t::network_read
ssize_t(* network_read)(coap_socket_t *sock, coap_packet_t *packet)
Definition: coap_net_internal.h:98
coap_context_t::get_client_psk
size_t(* get_client_psk)(const coap_session_t *session, const uint8_t *hint, size_t hint_len, uint8_t *identity, size_t *identity_len, size_t max_identity_len, uint8_t *psk, size_t max_psk_len)
Definition: coap_net_internal.h:100
coap_context_t::proxy_uri_resource
coap_resource_t * proxy_uri_resource
can be used for handling proxy URI resources
Definition: coap_net_internal.h:51
coap_context_t::spsk_setup_data
coap_dtls_spsk_t spsk_setup_data
Contains the initial PSK server setup data.
Definition: coap_net_internal.h:112
coap_context_t::block_mode
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
Definition: coap_net_internal.h:130
coap_context_t::unknown_resource
coap_resource_t * unknown_resource
can be used for handling unknown resources
Definition: coap_net_internal.h:49
coap_context_t::max_idle_sessions
unsigned int max_idle_sessions
Maximum number of simultaneous unused sessions per endpoint.
Definition: coap_net_internal.h:118
coap_dtls_spsk_t
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:425
coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
Definition: coap_session_internal.h:136
coap_opt_filter_t
Definition: option.h:100
coap_packet_t
Definition: coap_io_internal.h:160
coap_pdu_t
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: coap_pdu_internal.h:94
coap_queue_t
Queue entry.
Definition: coap_net_internal.h:31
coap_queue_t::session
coap_session_t * session
the CoAP session
Definition: coap_net_internal.h:37
coap_queue_t::pdu
coap_pdu_t * pdu
the CoAP PDU to send
Definition: coap_net_internal.h:39
coap_queue_t::timeout
unsigned int timeout
the randomized timeout value
Definition: coap_net_internal.h:36
coap_queue_t::next
struct coap_queue_t * next
Definition: coap_net_internal.h:32
coap_queue_t::id
coap_mid_t id
CoAP message id.
Definition: coap_net_internal.h:38
coap_queue_t::t
coap_tick_t t
when to send PDU for the next time
Definition: coap_net_internal.h:33
coap_queue_t::retransmit_cnt
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
Definition: coap_net_internal.h:34
coap_resource_t
Abstraction of resource that can be attached to coap_context_t.
Definition: coap_resource_internal.h:42
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition: coap_session_internal.h:48
coap_socket_t
Definition: coap_io_internal.h:23