libcoap 4.3.1
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*
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7* This file is part of the CoAP library libcoap. Please see
8* README for terms of use.
9*/
10
16#ifndef COAP_SESSION_H_
17#define COAP_SESSION_H_
18
30typedef struct coap_fixed_point_t {
31 uint16_t integer_part;
32 uint16_t fractional_part;
35
36#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
37#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS)
38
42typedef enum coap_session_type_t {
49
60
68
77
86 coap_nack_reason_t reason);
87
95void coap_session_set_app_data(coap_session_t *session, void *data);
96
106void *coap_session_get_app_data(const coap_session_t *session);
107
116 const coap_session_t *session);
117
126 const coap_session_t *session);
127
136
145
154
162int coap_session_get_ifindex(const coap_session_t *session);
163
177void *coap_session_get_tls(const coap_session_t *session,
178 coap_tls_library_t *tls_lib);
179
188
201
209void coap_session_set_mtu(coap_session_t *session, unsigned mtu);
210
217size_t coap_session_max_pdu_size(const coap_session_t *session);
218
229 coap_context_t *ctx,
230 const coap_address_t *local_if,
231 const coap_address_t *server,
232 coap_proto_t proto
233);
234
248 coap_context_t *ctx,
249 const coap_address_t *local_if,
250 const coap_address_t *server,
251 coap_proto_t proto,
252 const char *identity,
253 const uint8_t *key,
254 unsigned key_len
255);
256
273 coap_context_t *ctx,
274 const coap_address_t *local_if,
275 const coap_address_t *server,
276 coap_proto_t proto,
277 coap_dtls_cpsk_t *setup_data
278);
279
288 const coap_session_t *session);
289
298 const coap_session_t *session);
307 const coap_session_t *session);
308
325 coap_context_t *ctx,
326 const coap_address_t *local_if,
327 const coap_address_t *server,
328 coap_proto_t proto,
329 coap_dtls_pki_t *setup_data
330);
331
340void coap_session_init_token(coap_session_t *session, size_t length,
341 const uint8_t *token);
342
351void coap_session_new_token(coap_session_t *session, size_t *length,
352 uint8_t *token);
353
361const char *coap_session_str(const coap_session_t *session);
362
372
380void coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu);
381
383
393const char *coap_endpoint_str(const coap_endpoint_t *endpoint);
394
396 const coap_address_t *remote_addr, int ifindex);
397
415#define COAP_DEFAULT_ACK_TIMEOUT ((coap_fixed_point_t){2,0})
416
424#define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500})
425
432#define COAP_DEFAULT_MAX_RETRANSMIT (4U)
433
441#define COAP_DEFAULT_NSTART (1U)
442
449#define COAP_DEFAULT_DEFAULT_LEISURE ((coap_fixed_point_t){5,0})
450
457#define COAP_DEFAULT_PROBING_RATE (1U)
458
463#define COAP_DEFAULT_MAX_LATENCY (100U)
464
477 coap_fixed_point_t value);
478
491
504 coap_fixed_point_t value);
505
518 const coap_session_t *session);
519
531 uint16_t value);
532
543uint16_t coap_session_get_max_retransmit(const coap_session_t *session);
544
554 uint16_t value);
555
564uint16_t coap_session_get_nstart(const coap_session_t *session);
565
575 coap_fixed_point_t value);
576
586 const coap_session_t *session);
587
596void coap_session_set_probing_rate(coap_session_t *session, uint32_t value);
597
606uint32_t coap_session_get_probing_rate(const coap_session_t *session);
607
616
623
624#endif /* COAP_SESSION_H */
coap_nack_reason_t
Definition: coap_io.h:69
coap_mid_t coap_session_send_ping(coap_session_t *session)
Send a ping message for the session.
Definition: coap_session.c:516
coap_session_t * coap_session_get_by_peer(const coap_context_t *ctx, const coap_address_t *remote_addr, int ifindex)
void coap_session_set_no_observe_cancel(coap_session_t *session)
Disable client automatically sending observe cancel on session close.
coap_fixed_point_t coap_session_get_default_leisure(const coap_session_t *session)
Get the CoAP default leisure time RFC7252 DEFAULT_LEISURE.
Definition: coap_session.c:116
void coap_session_set_max_retransmit(coap_session_t *session, uint16_t value)
Set the CoAP maximum retransmit count before failure.
Definition: coap_session.c:58
void coap_session_set_ack_random_factor(coap_session_t *session, coap_fixed_point_t value)
Set the CoAP ack randomize factor.
Definition: coap_session.c:47
coap_fixed_point_t coap_session_get_ack_random_factor(const coap_session_t *session)
Get the CoAP ack randomize factor.
Definition: coap_session.c:101
uint16_t coap_session_get_max_retransmit(const coap_session_t *session)
Get the CoAP maximum retransmit before failure.
Definition: coap_session.c:106
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.
Definition: coap_session.c:121
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.
Definition: coap_session.c:37
void coap_session_set_nstart(coap_session_t *session, uint16_t value)
Set the CoAP maximum concurrent transmission count of Confirmable messages RFC7252 NSTART.
Definition: coap_session.c:67
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.
Definition: coap_session.c:87
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.
Definition: coap_session.c:76
uint16_t coap_session_get_nstart(const coap_session_t *session)
Get the CoAP maximum concurrent transmission count of Confirmable messages RFC7252 NSTART.
Definition: coap_session.c:111
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.
Definition: coap_session.c:96
coap_tls_library_t
Definition: coap_dtls.h:64
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: pdu.h:243
coap_proto_t
CoAP protocol types.
Definition: pdu.h:292
coap_session_type_t
coap_session_type_t values
Definition: coap_session.h:42
void coap_free_endpoint(coap_endpoint_t *ep)
void coap_session_set_mtu(coap_session_t *session, unsigned mtu)
Set the session MTU.
Definition: coap_session.c:387
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 from the session.
coap_proto_t coap_session_get_proto(const coap_session_t *session)
Get the session protocol type.
size_t coap_session_max_pdu_size(const coap_session_t *session)
Get maximum acceptable PDU size.
Definition: coap_session.c:361
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
Definition: coap_session.h:53
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.
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.
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.
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.
void coap_session_new_token(coap_session_t *session, size_t *length, uint8_t *token)
Creates a new token for use.
const coap_bin_const_t * coap_session_get_psk_identity(const coap_session_t *session)
Get the server session's current PSK identity (PSK).
void coap_session_set_app_data(coap_session_t *session, void *data)
Stores data with the given session.
Definition: coap_session.c:154
void coap_session_release(coap_session_t *session)
Decrement reference counter on a session.
Definition: coap_session.c:132
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).
const coap_address_t * coap_session_get_addr_remote(const coap_session_t *session)
Get the remote IP address from the session.
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.
int coap_session_set_type_client(coap_session_t *session)
Set the session type to client.
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.
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
Definition: coap_session.c:593
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.
coap_session_t * coap_session_reference(coap_session_t *session)
Increment reference counter on a session.
Definition: coap_session.c:126
int coap_session_get_ifindex(const coap_session_t *session)
Get the session if index.
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...
Definition: coap_session.c:160
coap_session_type_t coap_session_get_type(const coap_session_t *session)
Get the session type.
@ COAP_SESSION_TYPE_NONE
Not defined.
Definition: coap_session.h:43
@ COAP_SESSION_TYPE_HELLO
server-side ephemeral session for responding to a client hello
Definition: coap_session.h:46
@ COAP_SESSION_TYPE_SERVER
server-side
Definition: coap_session.h:45
@ COAP_SESSION_TYPE_CLIENT
client-side
Definition: coap_session.h:44
@ COAP_SESSION_STATE_HANDSHAKE
Definition: coap_session.h:56
@ COAP_SESSION_STATE_CSM
Definition: coap_session.h:57
@ COAP_SESSION_STATE_ESTABLISHED
Definition: coap_session.h:58
@ COAP_SESSION_STATE_NONE
Definition: coap_session.h:54
@ COAP_SESSION_STATE_CONNECTING
Definition: coap_session.h:55
multi-purpose address abstraction
Definition: coap_address.h:96
CoAP binary data definition with const data.
Definition: str.h:64
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:350
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:256
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.
Definition: coap_session.h:30
uint16_t fractional_part
Fractional part of fixed point variable 1/1000 (3 points) precision.
Definition: coap_session.h:32
uint16_t integer_part
Integer part of fixed point variable.
Definition: coap_session.h:31
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...