18#ifndef COAP_SESSION_INTERNAL_H_
19#define COAP_SESSION_INTERNAL_H_
24#define COAP_DEFAULT_SESSION_TIMEOUT 300
25#define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND)
26#define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100
64#if COAP_SERVER_SUPPORT
78#if COAP_CLIENT_SUPPORT
81#if COAP_SERVER_SUPPORT
160#if COAP_SERVER_SUPPORT
230#if COAP_SERVER_SUPPORT
258 const uint8_t *data,
size_t datalen);
274 const uint8_t *data,
size_t datalen);
293#if COAP_SERVER_SUPPORT
332#define COAP_SESSION_REF(s) ((s)->ref
335#define COAP_ACK_TIMEOUT(s) ((s)->ack_timeout)
336#define COAP_ACK_RANDOM_FACTOR(s) ((s)->ack_random_factor)
337#define COAP_MAX_RETRANSMIT(s) ((s)->max_retransmit)
338#define COAP_NSTART(s) ((s)->nstart)
339#define COAP_DEFAULT_LEISURE(s) ((s)->default_leisure)
340#define COAP_PROBING_RATE(s) ((s)->probing_rate)
348#define COAP_DEFAULT_LEISURE_TICKS(s) \
349 (COAP_DEFAULT_LEISURE(s).integer_part * COAP_TICKS_PER_SECOND + \
350 COAP_DEFAULT_LEISURE(s).fractional_part * COAP_TICKS_PER_SECOND / 1000)
357#define COAP_MAX_TRANSMIT_SPAN(s) \
358 (((s)->ack_timeout.integer_part * 1000 + (s)->ack_timeout.fractional_part) * \
359 ((1 << ((s)->max_retransmit)) -1) * \
360 ((s)->ack_random_factor.integer_part * 1000 + \
361 (s)->ack_random_factor.fractional_part) \
370#define COAP_MAX_TRANSMIT_WAIT(s) \
371 (((s)->ack_timeout.integer_part * 1000 + (s)->ack_timeout.fractional_part) * \
372 ((1 << ((s)->max_retransmit + 1)) -1) * \
373 ((s)->ack_random_factor.integer_part * 1000 + \
374 (s)->ack_random_factor.fractional_part) \
377#define COAP_MAX_TRANSMIT_WAIT_TICKS(s) \
378 (COAP_MAX_TRANSMIT_WAIT(s) * COAP_TICKS_PER_SECOND)
386#define COAP_PROCESSING_DELAY(s) \
387 (((s)->ack_timeout.integer_part * 1000 + (s)->ack_timeout.fractional_part + \
396#define COAP_MAX_RTT(s) \
397 ((2 * COAP_DEFAULT_MAX_LATENCY) + COAP_PROCESSING_DELAY(s))
405#define COAP_EXCHANGE_LIFETIME(s) \
406 (COAP_MAX_TRANSMIT_SPAN(s) + (2 * COAP_DEFAULT_MAX_LATENCY) + \
407 COAP_PROCESSING_DELAY(s))
415#define COAP_NON_LIFETIME(s) \
416 (COAP_MAX_TRANSMIT_SPAN(s) + COAP_DEFAULT_MAX_LATENCY)
420#define SESSIONS_ADD(e, obj) \
421 HASH_ADD(hh, (e), addr_hash, sizeof((obj)->addr_hash), (obj))
423#define SESSIONS_DELETE(e, obj) \
424 HASH_DELETE(hh, (e), (obj))
426#define SESSIONS_ITER(e, el, rtmp) \
427 HASH_ITER(hh, (e), el, rtmp)
429#define SESSIONS_ITER_SAFE(e, el, rtmp) \
430for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
432#define SESSIONS_FIND(e, k, res) { \
433 HASH_FIND(hh, (e), &(k), sizeof(k), (res)); \
Pulls together all the internal only header files.
Internal network I/O functions.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
coap_session_t * coap_session_new_dtls_session(coap_session_t *session, coap_tick_t now)
Create a new DTLS session for the session.
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
coap_proto_t
CoAP protocol types.
coap_session_t * coap_new_server_session(coap_context_t *ctx, coap_endpoint_t *ep)
Creates a new server session for the specified endpoint.
ssize_t coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node)
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).
void coap_session_send_csm(coap_session_t *session)
Notify session transport has just connected and CSM exchange can now start.
size_t coap_session_max_pdu_rcv_size(const coap_session_t *session)
Get maximum acceptable receive PDU size.
ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for datagram data transmission.
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.
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).
void coap_session_connected(coap_session_t *session)
Notify session that it has just connected or reconnected.
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu)
Send a pdu according to the session's protocol.
void coap_session_free(coap_session_t *session)
void coap_session_mfree(coap_session_t *session)
int coap_session_refresh_psk_identity(coap_session_t *session, const coap_bin_const_t *psk_identity)
Refresh the session's current pre-shared identity (PSK).
ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for stream data transmission.
coap_session_type_t
coap_session_type_t values
coap_session_state_t
coap_session_state_t values
Only used for servers for hashing incoming packets.
coap_address_t remote
remote address and port
coap_proto_t proto
CoAP protocol.
multi-purpose address abstraction
CoAP binary data definition with const data.
The CoAP stack's global state is stored in a coap_context_t object.
The structure used for defining the Client PSK setup data to be used.
Abstraction of virtual endpoint that can be attached to coap_context_t.
coap_context_t * context
endpoint's context
uint16_t default_mtu
default mtu for this interface
coap_session_t * sessions
hash table or list of active sessions
struct coap_endpoint_t * next
coap_address_t bind_addr
local interface address
coap_socket_t sock
socket object for the interface, if any
coap_proto_t proto
protocol used on this interface
Abstraction of a fixed point number that can be used where necessary instead of a float.
Structure to hold large body (many blocks) client receive information.
Structure to hold large body (many blocks) server receive information.
Structure to hold large body (many blocks) transmission information.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_lg_xmit_t * lg_xmit
list of large transmissions
unsigned int dtls_timeout_count
dtls setup retry counter
coap_bin_const_t * psk_key
If client, this field contains the current pre-shared key for server; When this field is NULL,...
coap_endpoint_t * endpoint
session's endpoint
uint8_t doing_first
Set if doing client's first request.
uint8_t delay_recursive
Set if in coap_client_delay_first()
coap_socket_t sock
socket object for the session, if any
coap_pdu_t * partial_pdu
incomplete incoming pdu
uint16_t nstart
maximum concurrent confirmable xmits (default 1)
coap_bin_const_t * psk_identity
If client, this field contains the current identity for server; When this field is NULL,...
coap_session_state_t state
current state of relationaship with peer
uint8_t csm_bert_rem_support
CSM TCP BERT blocks supported (remote)
uint64_t tx_token
Next token number to use.
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
uint8_t read_header[8]
storage space for header of incoming message header
uint8_t csm_bert_loc_support
CSM TCP BERT blocks supported (local)
coap_addr_tuple_t addr_info
key: remote/local address info
coap_proto_t proto
protocol used
uint16_t tx_mid
the last message id that was used in this session
unsigned ref
reference count from queues
size_t csm_rcv_mtu
CSM mtu (rcv)
coap_bin_const_t * psk_hint
If client, this field contains the server provided identity hint.
coap_bin_const_t * last_token
coap_dtls_cpsk_t cpsk_setup_data
client provided PSK initial setup data
size_t mtu
path or CSM mtu (xmt)
uint8_t no_observe_cancel
Set if do not cancel observe on session close.
size_t partial_read
if > 0 indicates number of bytes already read for an incoming message
int dtls_event
Tracking any (D)TLS events on this sesison.
void * tls
security parameters
uint16_t max_retransmit
maximum re-transmit count (default 4)
uint8_t csm_block_supported
CSM TCP blocks supported.
coap_fixed_point_t ack_random_factor
ack random factor backoff (default 1.5)
uint8_t proxy_session
Set if this is an ongoing proxy session.
uint8_t con_active
Active CON request sent.
coap_queue_t * delayqueue
list of delayed messages waiting to be sent
size_t tls_overhead
overhead of TLS layer
void * app
application-specific data
uint32_t tx_rtag
Next Request-Tag number to use.
coap_mid_t last_ping_mid
the last keepalive message id that was used in this session
coap_lg_srcv_t * lg_srcv
Server list of expected large receives.
coap_lg_crcv_t * lg_crcv
Client list of expected large receives.
coap_fixed_point_t ack_timeout
timeout waiting for ack (default 2.0 secs)
coap_fixed_point_t default_leisure
Mcast leisure time (default 5.0 secs)
coap_mid_t last_con_mid
The last CON mid that has been been processed.
coap_session_type_t type
client or server side socket
uint32_t probing_rate
Max transfer wait when remote is not respoding (default 1 byte/sec)
coap_mid_t last_ack_mid
The last ACK mid that has been been processed.
coap_context_t * context
session's context
size_t partial_write
if > 0 indicates number of bytes already written from the pdu at the head of sendqueue
coap_addr_hash_t addr_hash
Address hash for server incoming packets.
int ifindex
interface index
coap_bin_const_t * echo
last token used to make a request