Loading...
Searching...
No Matches
coap_net_internal.h
Go to the documentation of this file.
/*
* coap_net_internal.h -- CoAP context internal information
* exposed to application programming
*
* Copyright (C) 2010-2023 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_
#include "coap_internal.h"
#include "coap_subscribe.h"
struct coap_queue_t {
struct coap_queue_t *next;
coap_tick_t t;
unsigned char retransmit_cnt;
uint8_t is_mcast;
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;
#if COAP_SERVER_SUPPORT
coap_resource_t *resources;
coap_resource_t *unknown_resource;
coap_resource_t *proxy_uri_resource;
coap_resource_release_userdata_handler_t release_userdata;
#endif /* COAP_SERVER_SUPPORT */
#if COAP_ASYNC_SUPPORT
coap_async_t *async_state;
#endif /* COAP_ASYNC_SUPPORT */
coap_tick_t sendqueue_basetime;
coap_queue_t *sendqueue;
#if COAP_SERVER_SUPPORT
coap_endpoint_t *endpoint;
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
coap_session_t *sessions;
#endif /* COAP_CLIENT_SUPPORT */
#ifdef WITH_CONTIKI
struct uip_udp_conn *conn;
struct ctimer prepare_timer;
#endif /* WITH_CONTIKI */
#ifdef WITH_LWIP
coap_lwip_input_wait_handler_t input_wait;
void *input_arg;
uint8_t timer_configured;
#endif /* WITH_LWIP */
#if COAP_OSCORE_SUPPORT
struct oscore_ctx_t *p_osc_ctx;
#endif /* COAP_OSCORE_SUPPORT */
#if COAP_CLIENT_SUPPORT
coap_response_handler_t response_handler;
#endif /* COAP_CLIENT_SUPPORT */
coap_nack_handler_t nack_handler;
coap_ping_handler_t ping_handler;
coap_pong_handler_t pong_handler;
#if COAP_SERVER_SUPPORT
coap_observe_added_t observe_added;
coap_observe_deleted_t observe_deleted;
void *observe_user_data;
uint32_t observe_save_freq;
coap_track_observe_value_t track_observe_value;
coap_dyn_resource_added_t dyn_resource_added;
coap_resource_deleted_t resource_deleted;
#if COAP_WITH_OBSERVE_PERSIST
coap_bin_const_t *dyn_resource_save_file;
coap_bin_const_t *obs_cnt_save_file;
coap_bin_const_t *observe_save_file;
coap_pdu_t *unknown_pdu;
coap_session_t *unknown_session;
#endif /* COAP_WITH_OBSERVE_PERSIST */
#endif /* COAP_SERVER_SUPPORT */
coap_event_handler_t handle_event;
void *dtls_context;
#if COAP_SERVER_SUPPORT
coap_dtls_spsk_t spsk_setup_data;
#endif /* COAP_SERVER_SUPPORT */
unsigned int session_timeout;
unsigned int max_idle_sessions;
unsigned int max_handshake_sessions;
unsigned int ping_timeout;
unsigned int csm_timeout;
uint32_t csm_max_message_size;
uint64_t etag;
#if COAP_SERVER_SUPPORT
coap_cache_entry_t *cache;
uint16_t *cache_ignore_options;
size_t cache_ignore_count;
#endif /* COAP_SERVER_SUPPORT */
void *app;
uint32_t max_token_size;
#ifdef COAP_EPOLL_SUPPORT
int epfd;
int eptimerfd;
coap_tick_t next_timeout;
#else /* ! COAP_EPOLL_SUPPORT */
fd_set readfds, writefds, exceptfds;
coap_socket_t *sockets[64];
unsigned int num_sockets;
#endif /* ! COAP_EPOLL_SUPPORT */
#if COAP_SERVER_SUPPORT
uint8_t observe_pending;
uint8_t observe_no_clear;
uint8_t mcast_per_resource;
#endif /* COAP_SERVER_SUPPORT */
uint8_t block_mode;
};
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,
coap_bin_const_t *token);
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_session_t *session,
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);
int coap_client_delay_first(coap_session_t *session);
extern int coap_started;
#endif /* COAP_NET_INTERNAL_H_ */
coap_async_t
struct coap_async_t coap_async_t
Async Entry information.
Definition coap_forward_decls.h:43
coap_internal.h
Pulls together all the internal only header files.
coap_nack_reason_t
coap_nack_reason_t
Definition coap_io.h:69
coap_started
int coap_started
Definition coap_net.c:3980
coap_subscribe.h
Defines the application visible subscribe information.
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:144
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 coap_resource.h:331
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 coap_net.c:129
coap_delete_all
void coap_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
Definition coap_net.c:223
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 coap_net.c:2237
coap_delete_node
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
Definition coap_net.c:203
coap_peek_next
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
Definition coap_net.c:246
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.
coap_client_delay_first
int coap_client_delay_first(coap_session_t *session)
Delay the sending of the first client request until some other negotiation has completed.
Definition coap_net.c:986
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 coap_net.c:254
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 coap_net.c:3517
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 coap_net.c:1381
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 coap_net.c:166
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 coap_net.c:881
coap_retransmit
coap_mid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
Definition coap_net.c:1610
coap_option_check_critical
int coap_option_check_critical(coap_session_t *session, coap_pdu_t *pdu, coap_opt_filter_t *unknown)
Verifies that pdu contains no unknown critical options.
Definition coap_net.c:655
coap_wait_ack
coap_mid_t coap_wait_ack(coap_context_t *context, coap_session_t *session, coap_queue_t *node)
Definition coap_net.c:907
coap_new_node
coap_queue_t * coap_new_node(void)
Creates a new node suitable for adding to the CoAP sendqueue.
Definition coap_net.c:232
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 coap_net.c:2282
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 coap_net.c:2200
coap_cancel_all_messages
void coap_cancel_all_messages(coap_context_t *context, coap_session_t *session, coap_bin_const_t *token)
Cancels all outstanding messages for session session that have the specified token.
Definition coap_net.c:2323
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 coap_net.h:98
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 coap_net.h:62
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 coap_net.h:87
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 coap_net.h:75
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 function coap_s...
Definition coap_event.h:142
coap_lwip_input_wait_handler_t
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.
Definition coap_net.h:783
coap_dyn_resource_added_t
int(* coap_dyn_resource_added_t)(coap_session_t *session, coap_str_const_t *resource_name, coap_bin_const_t *raw_packet, void *user_data)
Callback handler definition called when a dynamic resource is getting created, as defined in coap_per...
Definition coap_subscribe.h:141
coap_resource_deleted_t
int(* coap_resource_deleted_t)(coap_context_t *context, coap_str_const_t *resource_name, void *user_data)
Callback handler definition called when resource is removed, as defined in coap_persist_track_funcs()...
Definition coap_subscribe.h:160
coap_observe_added_t
int(* coap_observe_added_t)(coap_session_t *session, coap_subscription_t *observe_key, coap_proto_t e_proto, coap_address_t *e_listen_addr, coap_addr_tuple_t *s_addr_info, coap_bin_const_t *raw_packet, coap_bin_const_t *oscore_info, void *user_data)
Callback handler definition called when a new observe has been set up, as defined in coap_persist_tra...
Definition coap_subscribe.h:84
coap_track_observe_value_t
int(* coap_track_observe_value_t)(coap_context_t *context, coap_str_const_t *resource_name, uint32_t observe_num, void *user_data)
Callback handler definition called when an observe unsolicited response is being sent,...
Definition coap_subscribe.h:123
coap_observe_deleted_t
int(* coap_observe_deleted_t)(coap_session_t *session, coap_subscription_t *observe_key, void *user_data)
Callback handler definition called when an observe is being removed, as defined in coap_persist_track...
Definition coap_subscribe.h:104
coap_mid_t
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition coap_pdu.h:255
coap_bin_const_t
CoAP binary data definition with const data.
Definition coap_str.h:64
coap_cache_entry_t
Definition coap_cache_internal.h:41
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition coap_net_internal.h:49
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:72
coap_context_t::pong_handler
coap_pong_handler_t pong_handler
Called when a ping response is received.
Definition coap_net_internal.h:105
coap_context_t::etag
uint64_t etag
Next ETag to use.
Definition coap_net_internal.h:162
coap_context_t::sockets
coap_socket_t * sockets[64]
Track different socket information in coap_io_process_with_fds.
Definition coap_net_internal.h:180
coap_context_t::observe_added
coap_observe_added_t observe_added
Called when there is a new observe subscription request.
Definition coap_net_internal.h:109
coap_context_t::csm_timeout
unsigned int csm_timeout
Timeout for waiting for a CSM from the remote side.
Definition coap_net_internal.h:159
coap_context_t::app
void * app
application-specific data
Definition coap_net_internal.h:171
coap_context_t::num_sockets
unsigned int num_sockets
Number of sockets being tracked.
Definition coap_net_internal.h:182
coap_context_t::sessions
coap_session_t * sessions
client sessions
Definition coap_net_internal.h:78
coap_context_t::exceptfds
fd_set exceptfds
Used for select call in coap_io_process_with_fds()
Definition coap_net_internal.h:178
coap_context_t::readfds
fd_set readfds
Definition coap_net_internal.h:178
coap_context_t::nack_handler
coap_nack_handler_t nack_handler
Called when a response issue has occurred.
Definition coap_net_internal.h:102
coap_context_t::ping_timeout
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
Definition coap_net_internal.h:156
coap_context_t::resources
coap_resource_t * resources
hash table or list of known resources
Definition coap_net_internal.h:52
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:166
coap_context_t::dtls_context
void * dtls_context
Definition coap_net_internal.h:140
coap_context_t::dyn_resource_added
coap_dyn_resource_added_t dyn_resource_added
Callback to save dynamic resource when created.
Definition coap_net_internal.h:118
coap_context_t::known_options
coap_opt_filter_t known_options
Definition coap_net_internal.h:50
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:58
coap_context_t::ping_handler
coap_ping_handler_t ping_handler
Called when a CoAP ping is received.
Definition coap_net_internal.h:104
coap_context_t::csm_max_message_size
uint32_t csm_max_message_size
Value for CSM Max-Message-Size.
Definition coap_net_internal.h:161
coap_context_t::observe_user_data
void * observe_user_data
App provided data for use in observe_added or observe_deleted.
Definition coap_net_internal.h:113
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:168
coap_context_t::max_handshake_sessions
unsigned int max_handshake_sessions
Maximum number of simultaneous negotating sessions per endpoint.
Definition coap_net_internal.h:153
coap_context_t::sendqueue
coap_queue_t * sendqueue
Definition coap_net_internal.h:73
coap_context_t::max_token_size
uint32_t max_token_size
Largest token size supported RFC8974.
Definition coap_net_internal.h:172
coap_context_t::response_handler
coap_response_handler_t response_handler
Called when a response is received.
Definition coap_net_internal.h:99
coap_context_t::writefds
fd_set writefds
Definition coap_net_internal.h:178
coap_context_t::cache
coap_cache_entry_t * cache
CoAP cache-entry cache.
Definition coap_net_internal.h:165
coap_context_t::track_observe_value
coap_track_observe_value_t track_observe_value
Callback to save observe value when updated.
Definition coap_net_internal.h:116
coap_context_t::mcast_per_resource
uint8_t mcast_per_resource
Mcast controlled on a per resource basis.
Definition coap_net_internal.h:188
coap_context_t::observe_pending
uint8_t observe_pending
Observe response pending.
Definition coap_net_internal.h:185
coap_context_t::endpoint
coap_endpoint_t * endpoint
the endpoints used for listening
Definition coap_net_internal.h:75
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:138
coap_context_t::observe_save_freq
uint32_t observe_save_freq
How frequently to update observe value.
Definition coap_net_internal.h:115
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:147
coap_context_t::observe_no_clear
uint8_t observe_no_clear
Observe 4.04 not to be sent on deleting resource.
Definition coap_net_internal.h:186
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:56
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:143
coap_context_t::observe_deleted
coap_observe_deleted_t observe_deleted
Called when there is a observe subscription de-register request.
Definition coap_net_internal.h:111
coap_context_t::block_mode
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
Definition coap_net_internal.h:191
coap_context_t::unknown_resource
coap_resource_t * unknown_resource
can be used for handling unknown resources
Definition coap_net_internal.h:54
coap_context_t::resource_deleted
coap_resource_deleted_t resource_deleted
Invoked when resource is deleted.
Definition coap_net_internal.h:120
coap_context_t::max_idle_sessions
unsigned int max_idle_sessions
Maximum number of simultaneous unused sessions per endpoint.
Definition coap_net_internal.h:150
coap_dtls_spsk_t
The structure used for defining the Server PSK setup data to be used.
Definition coap_dtls.h:465
coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
Definition coap_session_internal.h:219
coap_opt_filter_t
Definition coap_option.h:101
coap_pdu_t
structure for CoAP PDUs
Definition coap_pdu_internal.h:119
coap_queue_t
Queue entry.
Definition coap_net_internal.h:34
coap_queue_t::session
coap_session_t * session
the CoAP session
Definition coap_net_internal.h:41
coap_queue_t::pdu
coap_pdu_t * pdu
the CoAP PDU to send
Definition coap_net_internal.h:43
coap_queue_t::timeout
unsigned int timeout
the randomized timeout value
Definition coap_net_internal.h:40
coap_queue_t::is_mcast
uint8_t is_mcast
Set if this is a queued mcast response.
Definition coap_net_internal.h:39
coap_queue_t::next
struct coap_queue_t * next
Definition coap_net_internal.h:35
coap_queue_t::id
coap_mid_t id
CoAP message id.
Definition coap_net_internal.h:42
coap_queue_t::t
coap_tick_t t
when to send PDU for the next time
Definition coap_net_internal.h:36
coap_queue_t::retransmit_cnt
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
Definition coap_net_internal.h:37
coap_resource_t
Abstraction of resource that can be attached to coap_context_t.
Definition coap_resource_internal.h:53
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:68
coap_socket_t
Definition coap_io_internal.h:34
oscore_ctx_t
Definition oscore_context.h:84