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)); \ unsigned mtu
path or CSM mtu
struct coap_session_t coap_session_t
void coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu)
Set the endpoint's default MTU.
coap_tid_t last_ping_mid
the last keepalive message id that was used in this session
uint8_t con_active
Active CON request sent.
coap_tid_t coap_session_send_ping(coap_session_t *session)
Send a ping message for the session.
void * app
application-specific data
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.
Abstraction of a fixed point number that can be used where necessary instead of a float...
void coap_session_send_csm(coap_session_t *session)
Notify session transport has just connected and CSM exchange can now start.
struct coap_context_t * context
session's context
ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for datagram data transmission.
coap_fixed_point_t ack_timeout
timeout waiting for ack (default 2 secs)
void * tls
security parameters
void coap_session_set_mtu(coap_session_t *session, unsigned mtu)
Set the session MTU.
unsigned int coap_session_get_max_transmit(coap_session_t *session)
Get the CoAP maximum retransmit before failure.
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...
multi-purpose address abstraction
uint16_t tx_mid
the last message id that was used in this session
unsigned ref
reference count from queues
int coap_tid_t
coap_tid_t is used to store CoAP transaction id, i.e.
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.
unsigned tls_overhead
overhead of TLS layer
coap_session_t * coap_session_new_dtls_session(coap_session_t *session, coap_tick_t now)
Create a new DTLS session for the 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.
coap_address_t local_if
optional local interface address
int dtls_event
Tracking any (D)TLS events on this sesison.
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.
const char * coap_endpoint_str(const coap_endpoint_t *endpoint)
Get endpoint description.
Abstraction of virtual endpoint that can be attached to coap_context_t.
const char * coap_session_str(const coap_session_t *session)
Get session description.
void coap_session_mfree(coap_session_t *session)
unsigned int max_retransmit
maximum re-transmit count (default 4)
uint16_t fractional_part
Fractional part of fixed point variable 1/1000 (3 points) precision.
coap_pdu_t * pdu
the CoAP PDU to send
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...
struct coap_queue_t * delayqueue
list of delayed messages waiting to be sent
coap_proto_t proto
protocol used
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.
coap_addr_tuple_t addr_info
key: remote/local address info
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
COAP forward definitions.
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu)
Send a pdu according to the session's protocol.
size_t partial_read
if > 0 indicates number of bytes already read for an incoming message
coap_pdu_t * partial_pdu
incomplete incoming pdu
coap_socket_t sock
socket object for the session, if any
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_session_type_t type
client or server side socket
coap_fixed_point_t coap_session_get_ack_random_factor(coap_session_t *session)
Get the CoAP ack randomize factor.
coap_session_state_t state
current state of relationaship with peer
coap_fixed_point_t ack_random_factor
ack random factor backoff (default 1.5)
int ifindex
interface index
Pre-defined constants that reflect defaults for CoAP.
size_t partial_write
if > 0 indicates number of bytes already written from the pdu at the head of sendqueue ...
void coap_session_free(coap_session_t *session)
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)
ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for stream data transmission.
The structure used for defining the PKI setup data to be used.
uint8_t coap_session_type_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_free_endpoint(coap_endpoint_t *ep)
coap_session_t * coap_session_reference(coap_session_t *session)
Increment reference counter on a session.
coap_session_t * coap_session_get_by_peer(struct coap_context_t *ctx, const struct coap_address_t *remote_addr, int ifindex)
coap_session_t * session
the CoAP session
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...
struct coap_endpoint_t * endpoint
session's endpoint
void coap_session_set_max_retransmit(coap_session_t *session, unsigned int value)
Set the CoAP maximum retransmit count before failure.
void coap_session_release(coap_session_t *session)
Decrement reference counter on a session.
unsigned int dtls_timeout_count
dtls setup retry counter
uint16_t integer_part
Integer part of fixed point variable.
uint8_t coap_session_state_t
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
The CoAP stack's global state is stored in a coap_context_t object.
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.
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...