libcoap 4.3.5-develop-ea01661
Loading...
Searching...
No Matches
coap_session.h
Go to the documentation of this file.
1/* coap_session.h -- Session management for libcoap
2 *
3 * Copyright (C) 2017 Jean-Claue Michelou <jcm@spinetix.com>
4 * Copyright (C) 2023-2025 Jon Shallow <supjps-libcoap@jpshallow.com>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see
9 * README for terms of use.
10*/
11
17#ifndef COAP_SESSION_H_
18#define COAP_SESSION_H_
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
40
41#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
42#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS || \
43 (p)==COAP_PROTO_WS || (p)==COAP_PROTO_WSS)
44
55
66
74
83
92 coap_nack_reason_t reason);
93
104 void *data);
105
116void *coap_session_get_app_data(const coap_session_t *session);
117
124typedef void (*coap_app_data_free_callback_t)(void *data);
125
142COAP_API void *coap_session_set_app_data2(coap_session_t *session, void *data,
144
157 const coap_session_t *session);
158
171 const coap_session_t *session);
172
181 const coap_session_t *session);
182
191
200
209
218
226int coap_session_get_ifindex(const coap_session_t *session);
227
241void *coap_session_get_tls(const coap_session_t *session,
242 coap_tls_library_t *tls_lib);
243
252
271
291
299void coap_session_set_mtu(coap_session_t *session, unsigned mtu);
300
309
325 const coap_address_t *local_if,
326 const coap_address_t *server,
327 coap_proto_t proto
328 );
329
350 const coap_address_t *local_if,
351 const coap_address_t *server,
352 coap_proto_t proto,
353 const char *identity,
354 const uint8_t *key,
355 unsigned key_len
356 );
357
374 const coap_address_t *local_if,
375 const coap_address_t *server,
376 coap_proto_t proto,
377 coap_dtls_cpsk_t *setup_data
378 );
379
388 const coap_session_t *session);
389
398 const coap_session_t *session);
407 const coap_session_t *session);
408
425 const coap_address_t *local_if,
426 const coap_address_t *server,
427 coap_proto_t proto,
428 coap_dtls_pki_t *setup_data
429 );
430
439void coap_session_init_token(coap_session_t *session, size_t length,
440 const uint8_t *token);
441
450void coap_session_new_token(coap_session_t *session, size_t *length,
451 uint8_t *token);
452
460const char *coap_session_str(const coap_session_t *session);
461
475 const coap_address_t *listen_addr,
476 coap_proto_t proto);
477
485void coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu);
486
493
504
523
534 const coap_address_t *remote_addr,
535 int ifindex);
536
546const char *coap_endpoint_str(const coap_endpoint_t *endpoint);
547
566#define COAP_DEFAULT_ACK_TIMEOUT ((coap_fixed_point_t){2,0})
567
575#define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500})
576
583#define COAP_DEFAULT_MAX_RETRANSMIT (4U)
584
592#define COAP_DEFAULT_NSTART (1U)
593
600#define COAP_DEFAULT_DEFAULT_LEISURE ((coap_fixed_point_t){5,0})
601
608#define COAP_DEFAULT_PROBING_RATE (1U)
609
617#define COAP_DEFAULT_MAX_PAYLOADS (10U)
618
626#define COAP_DEFAULT_NON_MAX_RETRANSMIT (4U)
627
635#define COAP_DEFAULT_NON_TIMEOUT ((coap_fixed_point_t){2,0})
636
644#define COAP_DEFAULT_NON_RECEIVE_TIMEOUT ((coap_fixed_point_t){4,0})
645
650#define COAP_DEFAULT_MAX_LATENCY (100U)
651
664 coap_fixed_point_t value);
665
678
691 coap_fixed_point_t value);
692
705 const coap_session_t *session);
706
718 uint16_t value);
719
730uint16_t coap_session_get_max_retransmit(const coap_session_t *session);
731
741 uint16_t value);
742
751uint16_t coap_session_get_nstart(const coap_session_t *session);
752
762 coap_fixed_point_t value);
763
773 const coap_session_t *session);
774
783void coap_session_set_probing_rate(coap_session_t *session, uint32_t value);
784
793uint32_t coap_session_get_probing_rate(const coap_session_t *session);
794
805 uint16_t value);
806
816uint16_t coap_session_get_max_payloads(const coap_session_t *session);
817
828 uint16_t value);
829
840
853 coap_fixed_point_t value);
854
867
879 coap_fixed_point_t value);
880
892 const coap_session_t *session);
893
903
910
911#ifdef __cplusplus
912}
913#endif
914
915#endif /* COAP_SESSION_H */
coap_nack_reason_t
Definition coap_io.h:66
#define COAP_API
COAP_API coap_mid_t coap_session_send_ping(coap_session_t *session)
Send a ping message for the session.
void coap_session_set_no_observe_cancel(coap_session_t *session)
Disable client automatically sending observe cancel on session close.
uint16_t coap_session_get_non_max_retransmit(const coap_session_t *session)
Get the CoAP NON maximum retransmit count of missing Q-Block1 or Q-Block2 requested before there is a...
coap_fixed_point_t coap_session_get_default_leisure(const coap_session_t *session)
Get the CoAP default leisure time RFC7252 DEFAULT_LEISURE.
void coap_session_set_max_retransmit(coap_session_t *session, uint16_t value)
Set the CoAP maximum retransmit count before failure.
coap_fixed_point_t coap_session_get_non_timeout(const coap_session_t *session)
Get the CoAP MAX_PAYLOADS limit delay timeout.
void coap_session_set_ack_random_factor(coap_session_t *session, coap_fixed_point_t value)
Set the CoAP ack randomize factor.
coap_fixed_point_t coap_session_get_ack_random_factor(const coap_session_t *session)
Get the CoAP ack randomize factor.
uint16_t coap_session_get_max_retransmit(const coap_session_t *session)
Get the CoAP maximum retransmit before failure.
void coap_session_set_max_payloads(coap_session_t *session, uint16_t value)
Set the CoAP maximum payloads count of Q-Block1 or Q-Block2 before delay is introduced RFC9177 MAX_PA...
uint32_t coap_session_get_probing_rate(const coap_session_t *session)
Get the CoAP probing rate when there is no response RFC7252 PROBING_RATE.
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.
void coap_session_set_non_receive_timeout(coap_session_t *session, coap_fixed_point_t value)
Set the CoAP non receive timeout delay timeout.
void coap_session_set_nstart(coap_session_t *session, uint16_t value)
Set the CoAP maximum concurrent transmission count of Confirmable messages RFC7252 NSTART.
void coap_session_set_non_max_retransmit(coap_session_t *session, uint16_t value)
Set the CoAP NON maximum retransmit count of missing Q-Block1 or Q-Block2 requested before there is a...
uint16_t coap_session_get_max_payloads(const coap_session_t *session)
Get the CoAP maximum payloads count of Q-Block1 or Q-Block2 before delay is introduced RFC9177 MAX_PA...
void coap_session_set_probing_rate(coap_session_t *session, uint32_t value)
Set the CoAP probing rate when there is no response RFC7252 PROBING_RATE.
void coap_session_set_default_leisure(coap_session_t *session, coap_fixed_point_t value)
Set the CoAP default leisure time (for multicast) RFC7252 DEFAULT_LEISURE.
coap_fixed_point_t coap_session_get_non_receive_timeout(const coap_session_t *session)
Get the CoAP non receive timeout delay timeout.
uint16_t coap_session_get_nstart(const coap_session_t *session)
Get the CoAP maximum concurrent transmission count of Confirmable messages RFC7252 NSTART.
coap_fixed_point_t coap_session_get_ack_timeout(const coap_session_t *session)
Get the CoAP initial ack response timeout before the next re-transmit.
void coap_session_set_non_timeout(coap_session_t *session, coap_fixed_point_t value)
Set the CoAP non timeout delay timeout.
coap_tls_library_t
Definition coap_dtls.h:74
const char * coap_endpoint_str(const coap_endpoint_t *endpoint)
Get endpoint description.
const char * coap_session_str(const coap_session_t *session)
Get session description.
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition coap_pdu.h:268
coap_proto_t
CoAP protocol types.
Definition coap_pdu.h:317
COAP_DEPRECATED void coap_session_set_app_data(coap_session_t *session, void *data)
Stores data with the given session.
COAP_API coap_session_t * coap_session_reference(coap_session_t *session)
Increment reference counter on a session.
coap_session_type_t
coap_session_type_t values
COAP_API void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
COAP_API void * coap_endpoint_set_app_data(coap_endpoint_t *endpoint, void *data, coap_app_data_free_callback_t callback)
Stores data with the given endpoint, returning the previously stored value or NULL.
void coap_session_set_mtu(coap_session_t *session, unsigned mtu)
Set the session MTU.
coap_context_t * coap_session_get_context(const coap_session_t *session)
Get the session context.
const coap_address_t * coap_session_get_addr_local(const coap_session_t *session)
Get the local IP address and port from the session.
coap_proto_t coap_session_get_proto(const coap_session_t *session)
Get the session protocol type.
COAP_API int coap_session_set_type_client(coap_session_t *session)
Set the session type to client.
const coap_bin_const_t * coap_session_get_psk_key(const coap_session_t *session)
Get the session's current pre-shared key (PSK).
void * coap_session_get_tls(const coap_session_t *session, coap_tls_library_t *tls_lib)
Get the session TLS security ptr (TLS type dependent)
coap_session_state_t coap_session_get_state(const coap_session_t *session)
Get the session state.
coap_session_state_t
coap_session_state_t values
void * coap_endpoint_get_app_data(const coap_endpoint_t *endpoint)
Returns any application-specific data that has been stored with endpoint using the function coap_endp...
coap_endpoint_t * coap_session_get_endpoint(const coap_session_t *session)
Get the endpoint of a session.
COAP_API coap_session_t * coap_new_client_session_pki(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *setup_data)
Creates a new client session to the designated server with PKI credentials.
void coap_session_init_token(coap_session_t *session, size_t length, const uint8_t *token)
Initializes the token value to use as a starting point.
void coap_session_new_token(coap_session_t *session, size_t *length, uint8_t *token)
Creates a new token for use.
COAP_API coap_session_t * coap_new_client_session(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.
const coap_bin_const_t * coap_session_get_psk_identity(const coap_session_t *session)
Get the server session's current PSK identity (PSK).
coap_session_t * coap_session_get_by_peer(const coap_context_t *context, const coap_address_t *remote_addr, int ifindex)
Get the session associated with the specified remote_addr and index.
void coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu)
Set the endpoint's default MTU.
const coap_bin_const_t * coap_session_get_psk_hint(const coap_session_t *session)
Get the server session's current Identity Hint (PSK).
COAP_API coap_endpoint_t * coap_new_endpoint(coap_context_t *context, const coap_address_t *listen_addr, coap_proto_t proto)
Create a new endpoint for communicating with peers.
const coap_address_t * coap_session_get_addr_remote(const coap_session_t *session)
Get the remote IP address and port from the session.
COAP_API void coap_free_endpoint(coap_endpoint_t *endpoint)
Release an endpoint and all the structures associated with it.
COAP_API void coap_session_release(coap_session_t *session)
Decrement reference counter on a session.
COAP_API coap_session_t * coap_new_client_session_psk2(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *setup_data)
Creates a new client session to the designated server with PSK credentials.
const coap_address_t * coap_session_get_addr_mcast(const coap_session_t *session)
Get the remote multicast IP address and port from the session if the original target IP was multicast...
COAP_API size_t coap_session_max_pdu_size(const coap_session_t *session)
Get maximum acceptable PDU size.
COAP_API int coap_session_set_type_server(coap_session_t *session)
Set the session type to server.
COAP_API coap_session_t * coap_new_client_session_psk(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.
int coap_session_get_ifindex(const coap_session_t *session)
Get the session if index.
void(* coap_app_data_free_callback_t)(void *data)
Callback to free off the app data when the entry is being deleted / freed off.
COAP_API void * coap_session_set_app_data2(coap_session_t *session, void *data, coap_app_data_free_callback_t callback)
Stores data with the given session, returning the previously stored value or NULL.
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...
coap_session_type_t coap_session_get_type(const coap_session_t *session)
Get the session type.
@ COAP_SESSION_TYPE_NONE
Not defined.
@ COAP_SESSION_TYPE_HELLO
server-side ephemeral session for responding to a client hello
@ COAP_SESSION_TYPE_SERVER
server-side
@ COAP_SESSION_TYPE_CLIENT
client-side
@ COAP_SESSION_STATE_HANDSHAKE
@ COAP_SESSION_STATE_CSM
@ COAP_SESSION_STATE_ESTABLISHED
@ COAP_SESSION_STATE_NONE
@ COAP_SESSION_STATE_CONNECTING
#define COAP_DEPRECATED
Definition libcoap.h:66
Multi-purpose address abstraction.
CoAP binary data definition with const data.
Definition coap_str.h:67
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.
Definition coap_dtls.h:414
The structure used for defining the PKI setup data to be used.
Definition coap_dtls.h:316
Abstraction of virtual endpoint that can be attached to coap_context_t.
Abstraction of a fixed point number that can be used where necessary instead of a float.
uint16_t fractional_part
Fractional part of fixed point variable 1/1000 (3 points) precision.
uint16_t integer_part
Integer part of fixed point variable.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...