libcoap  4.3.0
coap_session.c File Reference
#include "coap3/coap_internal.h"
#include <stdio.h>
#include <errno.h>
+ Include dependency graph for coap_session.c:

Go to the source code of this file.

Macros

#define COAP_SESSION_C_
 
#define OFF_CONTENT_TYPE   0 /* offset of content_type in dtls_record_handshake_t */
 
#define DTLS_CT_ALERT   21 /* Content Type Alert */
 
#define DTLS_CT_HANDSHAKE   22 /* Content Type Handshake */
 
#define OFF_HANDSHAKE_TYPE   13 /* offset of handshake in dtls_record_handshake_t */
 
#define DTLS_HT_CLIENT_HELLO   1 /* Client Hello handshake type */
 
#define INET6_ADDRSTRLEN   40
 

Functions

void coap_session_set_max_retransmit (coap_session_t *session, unsigned int value)
 Set the CoAP maximum retransmit count before failure. More...
 
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. More...
 
void coap_session_set_ack_random_factor (coap_session_t *session, coap_fixed_point_t value)
 Set the CoAP ack randomize factor. More...
 
unsigned int coap_session_get_max_retransmit (const coap_session_t *session)
 Get the CoAP maximum retransmit before failure. More...
 
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. More...
 
coap_fixed_point_t coap_session_get_ack_random_factor (const coap_session_t *session)
 Get the CoAP ack randomize factor. More...
 
coap_session_tcoap_session_reference (coap_session_t *session)
 Increment reference counter on a session. More...
 
void coap_session_release (coap_session_t *session)
 Decrement reference counter on a session. More...
 
void coap_session_set_app_data (coap_session_t *session, void *app_data)
 Stores data with the given session. More...
 
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_session_set_app_data(). More...
 
static coap_session_tcoap_make_session (coap_proto_t proto, coap_session_type_t type, const coap_addr_hash_t *addr_hash, const coap_address_t *local_addr, const coap_address_t *remote_addr, int ifindex, coap_context_t *context, coap_endpoint_t *endpoint)
 
void coap_session_mfree (coap_session_t *session)
 
void coap_session_free (coap_session_t *session)
 
size_t coap_session_max_pdu_size (const coap_session_t *session)
 Get maximum acceptable PDU size. More...
 
void coap_session_set_mtu (coap_session_t *session, unsigned mtu)
 Set the session MTU. More...
 
ssize_t coap_session_send (coap_session_t *session, const uint8_t *data, size_t datalen)
 Function interface for datagram data transmission. More...
 
ssize_t coap_session_write (coap_session_t *session, const uint8_t *data, size_t datalen)
 Function interface for stream data transmission. More...
 
ssize_t coap_session_delay_pdu (coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node)
 
void coap_session_send_csm (coap_session_t *session)
 Notify session transport has just connected and CSM exchange can now start. More...
 
coap_mid_t coap_session_send_ping (coap_session_t *session)
 Send a ping message for the session. More...
 
void coap_session_connected (coap_session_t *session)
 Notify session that it has just connected or reconnected. More...
 
void coap_session_disconnected (coap_session_t *session, coap_nack_reason_t reason)
 Notify session that it has failed. More...
 
static void coap_make_addr_hash (coap_addr_hash_t *addr_hash, coap_proto_t proto, const coap_addr_tuple_t *addr_info)
 
coap_session_tcoap_endpoint_get_session (coap_endpoint_t *endpoint, const coap_packet_t *packet, coap_tick_t now)
 Lookup the server session for the packet received on an endpoint, or create a new one. More...
 
coap_session_tcoap_session_new_dtls_session (coap_session_t *session, coap_tick_t now)
 Create a new DTLS session for the session. More...
 
static coap_session_tcoap_session_create_client (coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto)
 
static coap_session_tcoap_session_connect (coap_session_t *session)
 
static coap_session_tcoap_session_accept (coap_session_t *session)
 
coap_session_tcoap_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. More...
 
coap_session_tcoap_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. More...
 
coap_session_tcoap_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. More...
 
int coap_session_refresh_psk_hint (coap_session_t *session, const coap_bin_const_t *psk_hint)
 Refresh the session's current Identity Hint (PSK). More...
 
int coap_session_refresh_psk_key (coap_session_t *session, const coap_bin_const_t *psk_key)
 Refresh the session's current pre-shared key (PSK). More...
 
const coap_bin_const_tcoap_session_get_psk_hint (const coap_session_t *session)
 Get the server session's current Identity Hint (PSK). More...
 
const coap_bin_const_tcoap_session_get_psk_key (const coap_session_t *session)
 Get the session's current pre-shared key (PSK). More...
 
coap_session_tcoap_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. More...
 
coap_session_tcoap_new_server_session (coap_context_t *ctx, coap_endpoint_t *ep)
 Creates a new server session for the specified endpoint. More...
 
void coap_session_init_token (coap_session_t *session, size_t len, const uint8_t *data)
 Initializes the token value to use as a starting point. More...
 
void coap_session_new_token (coap_session_t *session, size_t *len, uint8_t *data)
 Creates a new token for use. More...
 
uint16_t coap_new_message_id (coap_session_t *session)
 Returns a new message id and updates session->tx_mid accordingly. More...
 
const coap_address_tcoap_session_get_addr_remote (const coap_session_t *session)
 Get the remote IP address from the session. More...
 
const coap_address_tcoap_session_get_addr_local (const coap_session_t *session)
 Get the local IP address from the session. More...
 
coap_context_tcoap_session_get_context (const coap_session_t *session)
 Get the session context. More...
 
coap_proto_t coap_session_get_proto (const coap_session_t *session)
 Get the session protocol type. More...
 
coap_session_type_t coap_session_get_type (const coap_session_t *session)
 Get the session type. More...
 
int coap_session_set_type_client (coap_session_t *session)
 Set the session type to client. More...
 
coap_session_state_t coap_session_get_state (const coap_session_t *session)
 Get the session state. More...
 
int coap_session_get_ifindex (const coap_session_t *session)
 Get the session if index. More...
 
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) More...
 
coap_endpoint_tcoap_new_endpoint (coap_context_t *context, const coap_address_t *listen_addr, coap_proto_t proto)
 Create a new endpoint for communicating with peers. More...
 
void coap_endpoint_set_default_mtu (coap_endpoint_t *ep, unsigned mtu)
 Set the endpoint's default MTU. More...
 
void coap_free_endpoint (coap_endpoint_t *ep)
 
coap_session_tcoap_session_get_by_peer (const coap_context_t *ctx, const coap_address_t *remote_addr, int ifindex)
 
const char * coap_session_str (const coap_session_t *session)
 Get session description. More...
 
const char * coap_endpoint_str (const coap_endpoint_t *endpoint)
 Get endpoint description. More...
 

Macro Definition Documentation

◆ COAP_SESSION_C_

#define COAP_SESSION_C_

Definition at line 14 of file coap_session.c.

◆ DTLS_CT_ALERT

#define DTLS_CT_ALERT   21 /* Content Type Alert */

◆ DTLS_CT_HANDSHAKE

#define DTLS_CT_HANDSHAKE   22 /* Content Type Handshake */

◆ DTLS_HT_CLIENT_HELLO

#define DTLS_HT_CLIENT_HELLO   1 /* Client Hello handshake type */

◆ INET6_ADDRSTRLEN

#define INET6_ADDRSTRLEN   40

◆ OFF_CONTENT_TYPE

#define OFF_CONTENT_TYPE   0 /* offset of content_type in dtls_record_handshake_t */

◆ OFF_HANDSHAKE_TYPE

#define OFF_HANDSHAKE_TYPE   13 /* offset of handshake in dtls_record_handshake_t */

Function Documentation

◆ coap_make_addr_hash()

static void coap_make_addr_hash ( coap_addr_hash_t addr_hash,
coap_proto_t  proto,
const coap_addr_tuple_t addr_info 
)
static

Definition at line 545 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_make_session()

static coap_session_t* coap_make_session ( coap_proto_t  proto,
coap_session_type_t  type,
const coap_addr_hash_t addr_hash,
const coap_address_t local_addr,
const coap_address_t remote_addr,
int  ifindex,
coap_context_t context,
coap_endpoint_t endpoint 
)
static

Definition at line 110 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_session_accept()

static coap_session_t* coap_session_accept ( coap_session_t session)
static

Definition at line 869 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_session_connect()

static coap_session_t* coap_session_connect ( coap_session_t session)
static

Definition at line 821 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_session_create_client()

static coap_session_t* coap_session_create_client ( coap_context_t ctx,
const coap_address_t local_if,
const coap_address_t server,
coap_proto_t  proto 
)
static

Definition at line 741 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_session_get_ack_random_factor()

coap_fixed_point_t coap_session_get_ack_random_factor ( const coap_session_t session)

Get the CoAP ack randomize factor.

A factor that is used to randomize the wait time before a message is retransmitted to prevent synchronization effects.

Parameters
sessionThe CoAP session.
Returns
Current ack randomize value

Definition at line 65 of file coap_session.c.

◆ coap_session_get_ack_timeout()

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.

Number of seconds when to expect an ACK or a response to an outstanding CON message.

Parameters
sessionThe CoAP session.
Returns
Current ack response timeout value

Definition at line 60 of file coap_session.c.

◆ coap_session_get_by_peer()

coap_session_t* coap_session_get_by_peer ( const coap_context_t ctx,
const coap_address_t remote_addr,
int  ifindex 
)

Definition at line 1360 of file coap_session.c.

+ Here is the call graph for this function:

◆ coap_session_get_max_retransmit()

unsigned int coap_session_get_max_retransmit ( const coap_session_t session)

Get the CoAP maximum retransmit before failure.

Number of message retransmissions before message sending is stopped

Parameters
sessionThe CoAP session.
Returns
Current maximum retransmit value

Definition at line 55 of file coap_session.c.

◆ coap_session_send_ping()

coap_mid_t coap_session_send_ping ( coap_session_t session)

Send a ping message for the session.

Parameters
sessionThe CoAP session.
Returns
COAP_INVALID_MID if there is an error

Definition at line 381 of file coap_session.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_session_set_ack_random_factor()

void coap_session_set_ack_random_factor ( coap_session_t session,
coap_fixed_point_t  value 
)

Set the CoAP ack randomize factor.

A factor that is used to randomize the wait time before a message is retransmitted to prevent synchronization effects.

Parameters
sessionThe CoAP session.
valueThe value to set to. The default is 1.5 and should not normally get changed.

Definition at line 44 of file coap_session.c.

+ Here is the call graph for this function:

◆ coap_session_set_ack_timeout()

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.

Number of seconds when to expect an ACK or a response to an outstanding CON message.

Parameters
sessionThe CoAP session.
valueThe value to set to. The default is 2 and should not normally get changed.

Definition at line 34 of file coap_session.c.

+ Here is the call graph for this function:

◆ coap_session_set_max_retransmit()

void coap_session_set_max_retransmit ( coap_session_t session,
unsigned int  value 
)

Set the CoAP maximum retransmit count before failure.

Number of message retransmissions before message sending is stopped

Parameters
sessionThe CoAP session.
valueThe value to set to. The default is 4 and should not normally get changed.

Definition at line 25 of file coap_session.c.

+ Here is the call graph for this function: