coap_session_internal.h
Go to the documentation of this file.
/*
* coap_session_internal.h -- Structures, Enums & Functions that are not
* exposed to application programming
*
* Copyright (C) 2010-2019 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_SESSION_INTERNAL_H_
#define COAP_SESSION_INTERNAL_H_
#include "coap_io_internal.h"
#define COAP_DEFAULT_SESSION_TIMEOUT 300
#define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND)
#define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100
struct coap_addr_hash_t {
coap_address_t remote;
uint16_t lport;
coap_proto_t proto;
};
struct coap_session_t {
coap_proto_t proto;
coap_session_type_t type;
coap_session_state_t state;
unsigned ref;
size_t tls_overhead;
size_t mtu;
coap_addr_hash_t addr_hash;
UT_hash_handle hh;
coap_addr_tuple_t addr_info;
int ifindex;
coap_socket_t sock;
coap_endpoint_t *endpoint;
coap_context_t *context;
void *tls;
uint16_t tx_mid;
uint8_t con_active;
uint8_t csm_block_supported;
coap_mid_t last_ping_mid;
coap_queue_t *delayqueue;
coap_lg_xmit_t *lg_xmit;
coap_lg_crcv_t *lg_crcv;
coap_lg_srcv_t *lg_srcv;
size_t partial_write;
uint8_t read_header[8];
size_t partial_read;
coap_pdu_t *partial_pdu;
coap_tick_t last_rx_tx;
coap_tick_t last_tx_rst;
coap_tick_t last_ping;
coap_tick_t last_pong;
coap_tick_t csm_tx;
coap_dtls_cpsk_t cpsk_setup_data;
coap_bin_const_t *psk_identity;
coap_bin_const_t *psk_key;
coap_bin_const_t *psk_hint;
void *app;
unsigned int max_retransmit;
coap_fixed_point_t ack_timeout;
coap_fixed_point_t ack_random_factor;
unsigned int dtls_timeout_count;
int dtls_event;
uint8_t block_mode;
uint64_t tx_token;
};
struct coap_endpoint_t {
struct coap_endpoint_t *next;
coap_context_t *context;
coap_proto_t proto;
uint16_t default_mtu;
coap_socket_t sock;
coap_address_t bind_addr;
coap_session_t *sessions;
};
void coap_session_send_csm(coap_session_t *session);
void coap_session_connected(coap_session_t *session);
int coap_session_refresh_psk_hint(coap_session_t *session,
const coap_bin_const_t *psk_hint);
int coap_session_refresh_psk_key(coap_session_t *session,
const coap_bin_const_t *psk_key);
coap_session_t *coap_new_server_session(
coap_context_t *ctx,
coap_endpoint_t *ep
);
ssize_t coap_session_send(coap_session_t *session,
const uint8_t *data, size_t datalen);
ssize_t coap_session_write(coap_session_t *session,
const uint8_t *data, size_t datalen);
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu);
ssize_t
coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu,
coap_queue_t *node);
coap_session_t *coap_endpoint_get_session(coap_endpoint_t *endpoint,
const coap_packet_t *packet, coap_tick_t now);
coap_session_t *coap_session_new_dtls_session(coap_session_t *session,
coap_tick_t now);
void coap_session_free(coap_session_t *session);
void coap_session_mfree(coap_session_t *session);
#define SESSIONS_ADD(e, obj) \
HASH_ADD(hh, (e), addr_hash, sizeof((obj)->addr_hash), (obj))
#define SESSIONS_DELETE(e, obj) \
HASH_DELETE(hh, (e), (obj))
#define SESSIONS_ITER(e, el, rtmp) \
HASH_ITER(hh, (e), el, rtmp)
#define SESSIONS_ITER_SAFE(e, el, rtmp) \
for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
#define SESSIONS_FIND(e, k, res) { \
HASH_FIND(hh, (e), &(k), sizeof(k), (res)); \
}
#endif /* COAP_SESSION_INTERNAL_H_ */
coap_io_internal.h
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_session_new_dtls_session
coap_session_t * coap_session_new_dtls_session(coap_session_t *session, coap_tick_t now)
Create a new DTLS session for the session.
Definition: coap_session.c:691
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_proto_t
coap_proto_t
CoAP protocol types.
Definition: pdu.h:280
coap_endpoint_get_session
coap_session_t * coap_endpoint_get_session(coap_endpoint_t *endpoint, const coap_packet_t *packet, coap_tick_t now)
Lookup the server session for the packet received on an endpoint, or create a new one.
Definition: coap_session.c:554
coap_session_delay_pdu
ssize_t coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node)
Definition: coap_session.c:312
coap_session_refresh_psk_hint
int coap_session_refresh_psk_hint(coap_session_t *session, const coap_bin_const_t *psk_hint)
Refresh the session's current Identity Hint (PSK).
Definition: coap_session.c:996
coap_session_send_csm
void coap_session_send_csm(coap_session_t *session)
Notify session transport has just connected and CSM exchange can now start.
Definition: coap_session.c:351
coap_new_server_session
coap_session_t * coap_new_server_session(coap_context_t *ctx, coap_endpoint_t *ep)
Creates a new server session for the specified endpoint.
Definition: coap_session.c:1106
coap_session_send
ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for datagram data transmission.
Definition: coap_session.c:277
coap_session_refresh_psk_key
int coap_session_refresh_psk_key(coap_session_t *session, const coap_bin_const_t *psk_key)
Refresh the session's current pre-shared key (PSK).
Definition: coap_session.c:1025
coap_session_connected
void coap_session_connected(coap_session_t *session)
Notify session that it has just connected or reconnected.
Definition: coap_session.c:399
coap_session_send_pdu
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu)
Send a pdu according to the session's protocol.
Definition: net.c:766
coap_session_free
void coap_session_free(coap_session_t *session)
Definition: coap_session.c:225
coap_session_mfree
void coap_session_mfree(coap_session_t *session)
Definition: coap_session.c:159
coap_session_write
ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for stream data transmission.
Definition: coap_session.c:298
coap_session_type_t
coap_session_type_t
coap_session_type_t values
Definition: coap_session.h:41
coap_session_state_t
coap_session_state_t
coap_session_state_t values
Definition: coap_session.h:52
coap_addr_hash_t
Only used for servers for hashing incoming packets.
Definition: coap_session_internal.h:38
coap_addr_hash_t::lport
uint16_t lport
local port
Definition: coap_session_internal.h:40
coap_addr_hash_t::remote
coap_address_t remote
remote address and port
Definition: coap_session_internal.h:39
coap_addr_hash_t::proto
coap_proto_t proto
CoAP protocol.
Definition: coap_session_internal.h:41
coap_addr_tuple_t
Definition: coap_io.h:50
coap_address_t
multi-purpose address abstraction
Definition: address.h:96
coap_bin_const_t
CoAP binary data definition with const data.
Definition: str.h:58
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition: coap_net_internal.h:45
coap_dtls_cpsk_t
The structure used for defining the Client PSK setup data to be used.
Definition: coap_dtls.h:338
coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
Definition: coap_session_internal.h:136
coap_endpoint_t::context
coap_context_t * context
endpoint's context
Definition: coap_session_internal.h:138
coap_endpoint_t::default_mtu
uint16_t default_mtu
default mtu for this interface
Definition: coap_session_internal.h:140
coap_endpoint_t::sessions
coap_session_t * sessions
hash table or list of active sessions
Definition: coap_session_internal.h:144
coap_endpoint_t::next
struct coap_endpoint_t * next
Definition: coap_session_internal.h:137
coap_endpoint_t::bind_addr
coap_address_t bind_addr
local interface address
Definition: coap_session_internal.h:143
coap_endpoint_t::sock
coap_socket_t sock
socket object for the interface, if any
Definition: coap_session_internal.h:141
coap_endpoint_t::proto
coap_proto_t proto
protocol used on this interface
Definition: coap_session_internal.h:139
coap_fixed_point_t
Abstraction of a fixed point number that can be used where necessary instead of a float.
Definition: coap_session.h:29
coap_lg_crcv_t
Structure to hold large body (many blocks) client receive information.
Definition: coap_block_internal.h:99
coap_lg_srcv_t
Structure to hold large body (many blocks) server receive information.
Definition: coap_block_internal.h:127
coap_lg_xmit_t
Structure to hold large body (many blocks) transmission information.
Definition: coap_block_internal.h:77
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_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_session_t::last_pong
coap_tick_t last_pong
Definition: coap_session_internal.h:87
coap_session_t::lg_xmit
coap_lg_xmit_t * lg_xmit
list of large transmissions
Definition: coap_session_internal.h:73
coap_session_t::dtls_timeout_count
unsigned int dtls_timeout_count
dtls setup retry counter
Definition: coap_session_internal.h:125
coap_session_t::psk_key
coap_bin_const_t * psk_key
If client, this field contains the current pre-shared key for server; When this field is NULL,...
Definition: coap_session_internal.h:100
coap_session_t::endpoint
coap_endpoint_t * endpoint
session's endpoint
Definition: coap_session_internal.h:62
coap_session_t::last_rx_tx
coap_tick_t last_rx_tx
Definition: coap_session_internal.h:84
coap_session_t::sock
coap_socket_t sock
socket object for the session, if any
Definition: coap_session_internal.h:60
coap_session_t::max_retransmit
unsigned int max_retransmit
maximum re-transmit count (default 4)
Definition: coap_session_internal.h:119
coap_session_t::partial_pdu
coap_pdu_t * partial_pdu
incomplete incoming pdu
Definition: coap_session_internal.h:83
coap_session_t::psk_identity
coap_bin_const_t * psk_identity
If client, this field contains the current identity for server; When this field is NULL,...
Definition: coap_session_internal.h:91
coap_session_t::state
coap_session_state_t state
current state of relationaship with peer
Definition: coap_session_internal.h:51
coap_session_t::hh
UT_hash_handle hh
Definition: coap_session_internal.h:57
coap_session_t::tx_token
uint64_t tx_token
Next token number to use.
Definition: coap_session_internal.h:129
coap_session_t::block_mode
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
Definition: coap_session_internal.h:128
coap_session_t::read_header
uint8_t read_header[8]
storage space for header of incoming message header
Definition: coap_session_internal.h:79
coap_session_t::addr_info
coap_addr_tuple_t addr_info
key: remote/local address info
Definition: coap_session_internal.h:58
coap_session_t::proto
coap_proto_t proto
protocol used
Definition: coap_session_internal.h:49
coap_session_t::tx_mid
uint16_t tx_mid
the last message id that was used in this session
Definition: coap_session_internal.h:65
coap_session_t::ref
unsigned ref
reference count from queues
Definition: coap_session_internal.h:53
coap_session_t::psk_hint
coap_bin_const_t * psk_hint
If client, this field contains the server provided identity hint.
Definition: coap_session_internal.h:109
coap_session_t::cpsk_setup_data
coap_dtls_cpsk_t cpsk_setup_data
client provided PSK initial setup data
Definition: coap_session_internal.h:89
coap_session_t::mtu
size_t mtu
path or CSM mtu
Definition: coap_session_internal.h:55
coap_session_t::partial_read
size_t partial_read
if > 0 indicates number of bytes already read for an incoming message
Definition: coap_session_internal.h:81
coap_session_t::dtls_event
int dtls_event
Tracking any (D)TLS events on this sesison.
Definition: coap_session_internal.h:126
coap_session_t::tls
void * tls
security parameters
Definition: coap_session_internal.h:64
coap_session_t::csm_block_supported
uint8_t csm_block_supported
CSM TCP blocks supported.
Definition: coap_session_internal.h:68
coap_session_t::ack_random_factor
coap_fixed_point_t ack_random_factor
ack random factor backoff (default 1.5)
Definition: coap_session_internal.h:123
coap_session_t::con_active
uint8_t con_active
Active CON request sent.
Definition: coap_session_internal.h:67
coap_session_t::delayqueue
coap_queue_t * delayqueue
list of delayed messages waiting to be sent
Definition: coap_session_internal.h:71
coap_session_t::tls_overhead
size_t tls_overhead
overhead of TLS layer
Definition: coap_session_internal.h:54
coap_session_t::app
void * app
application-specific data
Definition: coap_session_internal.h:118
coap_session_t::last_ping_mid
coap_mid_t last_ping_mid
the last keepalive message id that was used in this session
Definition: coap_session_internal.h:69
coap_session_t::lg_srcv
coap_lg_srcv_t * lg_srcv
Server list of expected large receives.
Definition: coap_session_internal.h:75
coap_session_t::last_ping
coap_tick_t last_ping
Definition: coap_session_internal.h:86
coap_session_t::lg_crcv
coap_lg_crcv_t * lg_crcv
Client list of expected large receives.
Definition: coap_session_internal.h:74
coap_session_t::ack_timeout
coap_fixed_point_t ack_timeout
timeout waiting for ack (default 2 secs)
Definition: coap_session_internal.h:121
coap_session_t::type
coap_session_type_t type
client or server side socket
Definition: coap_session_internal.h:50
coap_session_t::last_tx_rst
coap_tick_t last_tx_rst
Definition: coap_session_internal.h:85
coap_session_t::context
coap_context_t * context
session's context
Definition: coap_session_internal.h:63
coap_session_t::partial_write
size_t partial_write
if > 0 indicates number of bytes already written from the pdu at the head of sendqueue
Definition: coap_session_internal.h:76
coap_session_t::addr_hash
coap_addr_hash_t addr_hash
Address hash for server incoming packets.
Definition: coap_session_internal.h:56
coap_session_t::csm_tx
coap_tick_t csm_tx
Definition: coap_session_internal.h:88
coap_session_t::ifindex
int ifindex
interface index
Definition: coap_session_internal.h:59
coap_socket_t
Definition: coap_io_internal.h:23