Go to the documentation of this file.
14 #ifndef COAP_SESSION_H_
15 #define COAP_SESSION_H_
34 #define COAP_DEFAULT_SESSION_TIMEOUT 300
35 #define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND)
36 #define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100
38 #define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
39 #define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS)
45 #define COAP_SESSION_TYPE_CLIENT 1
46 #define COAP_SESSION_TYPE_SERVER 2
47 #define COAP_SESSION_TYPE_HELLO 3
49 typedef uint8_t coap_session_state_t;
53 #define COAP_SESSION_STATE_NONE 0
54 #define COAP_SESSION_STATE_CONNECTING 1
55 #define COAP_SESSION_STATE_HANDSHAKE 2
56 #define COAP_SESSION_STATE_CSM 3
57 #define COAP_SESSION_STATE_ESTABLISHED 4
201 const char *identity,
254 const uint8_t *data,
size_t datalen);
270 const uint8_t *data,
size_t datalen);
375 #define COAP_DEFAULT_ACK_TIMEOUT ((coap_fixed_point_t){2,0})
382 #define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500})
388 #define COAP_DEFAULT_MAX_RETRANSMIT 4
395 #define COAP_DEFAULT_NSTART 1
480 #define SESSIONS_ADD(e, obj) \
481 HASH_ADD(hh, (e), addr_info, sizeof((obj)->addr_info), (obj))
483 #define SESSIONS_DELETE(e, obj) \
484 HASH_DELETE(hh, (e), (obj))
486 #define SESSIONS_ITER(e, el, rtmp) \
487 HASH_ITER(hh, (e), el, rtmp)
489 #define SESSIONS_ITER_SAFE(e, el, rtmp) \
490 for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
492 #define SESSIONS_FIND(e, k, res) { \
493 HASH_FIND(hh, (e), &(k), sizeof(k), (res)); \
coap_session_t * coap_new_client_session(struct coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto)
Creates a new client session to the designated server.
void coap_session_send_csm(coap_session_t *session)
Notify session transport has just connected and CSM exchange can now start.
coap_session_t * coap_endpoint_get_session(coap_endpoint_t *endpoint, const struct coap_packet_t *packet, coap_tick_t now)
Lookup the server session for the packet received on an endpoint, or create a new one.
void * coap_session_get_app_data(const coap_session_t *session)
Returns any application-specific data that has been stored with session using the function coap_sessi...
struct coap_context_t * context
session's context
const char * coap_session_str(const coap_session_t *session)
coap_fixed_point_t coap_session_get_ack_timeout(coap_session_t *session)
Get the CoAP initial ack response timeout before the next re-transmit.
void coap_session_release(coap_session_t *session)
Decrement reference counter on a session.
int dtls_event
Tracking any (D)TLS events on this sesison.
unsigned int coap_session_get_max_transmit(coap_session_t *session)
Get the CoAP maximum retransmit before failure.
unsigned mtu
path or CSM mtu
void * app
application-specific data
unsigned tls_overhead
overhead of TLS layer
unsigned ref
reference count from queues
coap_session_t * coap_new_client_session_psk(struct coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, const char *identity, const uint8_t *key, unsigned key_len)
Creates a new client session to the designated server with PSK credentials.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
uint16_t fractional_part
Fractional part of fixed point variable 1/1000 (3 points) precision.
void coap_session_set_mtu(coap_session_t *session, unsigned mtu)
Set the session MTU.
void * tls
security parameters
uint16_t tx_mid
the last message id that was used in this session
uint8_t con_active
Active CON request sent.
coap_session_t * coap_session_new_dtls_session(coap_session_t *session, coap_tick_t now)
Create a new DTLS session for the session.
The CoAP stack's global state is stored in a coap_context_t object.
void coap_session_mfree(coap_session_t *session)
COAP forward definitions.
coap_address_t local_if
optional local interface address
size_t coap_session_max_pdu_size(const coap_session_t *session)
Get maximum acceptable PDU size.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
multi-purpose address abstraction
struct coap_fixed_point_t coap_fixed_point_t
Abstraction of a fixed point number that can be used where necessary instead of a float.
unsigned int max_retransmit
maximum re-transmit count (default 4)
void coap_session_set_ack_timeout(coap_session_t *session, coap_fixed_point_t value)
Set the CoAP initial ack response timeout before the next re-transmit.
coap_addr_tuple_t addr_info
key: remote/local address info
coap_session_t * coap_new_client_session_pki(struct coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, struct coap_dtls_pki_t *setup_data)
Creates a new client session to the designated server with PKI credentials.
void coap_session_set_app_data(coap_session_t *session, void *data)
Stores data with the given session.
The structure used for defining the PKI setup data to be used.
coap_fixed_point_t coap_session_get_ack_random_factor(coap_session_t *session)
Get the CoAP ack randomize factor.
const char * coap_endpoint_str(const coap_endpoint_t *endpoint)
Pre-defined constants that reflect defaults for CoAP.
coap_session_t * coap_new_server_session(struct coap_context_t *ctx, struct coap_endpoint_t *ep)
Creates a new server session for the specified endpoint.
coap_session_t * session
the CoAP session
int ifindex
interface index
struct coap_queue_t * delayqueue
list of delayed messages waiting to be sent
size_t partial_write
if > 0 indicates number of bytes already written from the pdu at the head of sendqueue
coap_proto_t proto
protocol used
size_t partial_read
if > 0 indicates number of bytes already read for an incoming message
struct coap_session_t coap_session_t
void coap_session_set_ack_random_factor(coap_session_t *session, coap_fixed_point_t value)
Set the CoAP ack randomize factor.
void coap_session_connected(coap_session_t *session)
Notify session that it has just connected or reconnected.
ssize_t coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, struct coap_queue_t *node)
coap_session_type_t type
client or server side socket
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu)
Send a pdu according to the session's protocol.
coap_socket_t sock
socket object for the session, if any
coap_pdu_t * partial_pdu
incomplete incoming pdu
void coap_session_free(coap_session_t *session)
coap_session_state_t state
current state of relationaship with peer
int coap_tid_t
coap_tid_t is used to store CoAP transaction id, i.e.
coap_pdu_t * pdu
the CoAP PDU to send
coap_session_t * coap_session_reference(coap_session_t *session)
Increment reference counter on a session.
void coap_session_set_max_retransmit(coap_session_t *session, unsigned int value)
Set the CoAP maximum retransmit count before failure.
coap_session_t * coap_session_get_by_peer(struct coap_context_t *ctx, const struct coap_address_t *remote_addr, int ifindex)
uint16_t integer_part
Integer part of fixed point variable.
coap_fixed_point_t ack_random_factor
ack random factor backoff (default 1.5)
uint8_t coap_session_type_t
struct coap_endpoint_t * endpoint
session's endpoint
unsigned int dtls_timeout_count
dtls setup retry counter
ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for stream data transmission.
uint8_t coap_session_state_t
coap_endpoint_t * coap_new_endpoint(struct coap_context_t *context, const coap_address_t *listen_addr, coap_proto_t proto)
Create a new endpoint for communicating with peers.
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
Abstraction of virtual endpoint that can be attached to coap_context_t.
void coap_free_endpoint(coap_endpoint_t *ep)
ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for datagram data transmission.
Abstraction of a fixed point number that can be used where necessary instead of a float.
uint8_t read_header[8]
storage space for header of incoming message header
coap_fixed_point_t ack_timeout
timeout waiting for ack (default 2 secs)
void coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu)
Set the endpoint's default MTU.
coap_tid_t coap_session_send_ping(coap_session_t *session)
Send a ping message for the session.
coap_tid_t last_ping_mid
the last keepalive message id that was used in this session