9 #ifndef COAP_SESSION_H_ 10 #define COAP_SESSION_H_ 31 #define COAP_DEFAULT_SESSION_TIMEOUT 300 32 #define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND) 33 #define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100 35 #define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS) 36 #define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS) 42 #define COAP_SESSION_TYPE_CLIENT 1 43 #define COAP_SESSION_TYPE_SERVER 2 44 #define COAP_SESSION_TYPE_HELLO 3 46 typedef uint8_t coap_session_state_t; 50 #define COAP_SESSION_STATE_NONE 0 51 #define COAP_SESSION_STATE_CONNECTING 1 52 #define COAP_SESSION_STATE_HANDSHAKE 2 53 #define COAP_SESSION_STATE_CSM 3 54 #define COAP_SESSION_STATE_ESTABLISHED 4 198 const char *identity,
253 const uint8_t *data,
size_t datalen);
269 const uint8_t *data,
size_t datalen);
388 #define COAP_DEFAULT_ACK_TIMEOUT ((coap_fixed_point_t){2,0}) 395 #define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500}) 401 #define COAP_DEFAULT_MAX_RETRANSMIT 4 408 #define COAP_DEFAULT_NSTART 1 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.
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)
struct coap_endpoint_t * next
void * tls
security parameters
void coap_session_set_mtu(coap_session_t *session, unsigned mtu)
Set the session MTU.
coap_session_t * sessions
list of active sessions
coap_endpoint_t * endpoint
the endpoints used for listening
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
uint16_t default_mtu
default mtu for this interface
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
struct coap_session_t * next
int dtls_event
Tracking any (D)TLS events on this sesison.
coap_session_t * coap_endpoint_new_dtls_session(coap_endpoint_t *endpoint, const struct coap_packet_t *packet, coap_tick_t now)
Create a new DTLS session for the endpoint.
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.
struct coap_context_t * context
endpoint's context
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.
coap_address_t local_addr
local address and port
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.
size_t coap_session_max_pdu_size(const coap_session_t *session)
Get maximum acceptable PDU size.
coap_address_t remote_addr
remote address and port
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.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
coap_session_t hello
special session of DTLS hello messages
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
coap_proto_t proto
protocol used on this interface
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.
struct coap_endpoint_t coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
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_socket_t sock
socket object for the interface, if any
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.
coap_address_t bind_addr
local interface address
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...