Documentation
Includes
coap_io.h
#include "coap_io.h"
coap_time.h
#include "coap_time.h"
pdu.h
#include "pdu.h"
Macros
Marco COAP_SESSION_H_
#define COAP_SESSION_H_
Marco COAP_DEFAULT_SESSION_TIMEOUT
#define COAP_DEFAULT_SESSION_TIMEOUT 300
Marco COAP_PARTIAL_SESSION_TIMEOUT_TICKS
#define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND)
Marco COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS
#define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100
Marco COAP_PROTO_NOT_RELIABLE(p)
#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
Marco COAP_PROTO_RELIABLE(p)
#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS)
Marco COAP_SESSION_TYPE_CLIENT
#define COAP_SESSION_TYPE_CLIENT 1 /**< client-side */
Marco COAP_SESSION_TYPE_SERVER
#define COAP_SESSION_TYPE_SERVER 2 /**< server-side */
Marco COAP_SESSION_TYPE_HELLO
#define COAP_SESSION_TYPE_HELLO 3 /**< server-side ephemeral session for responding to a client hello */
Marco COAP_SESSION_STATE_NONE
#define COAP_SESSION_STATE_NONE 0
Marco COAP_SESSION_STATE_CONNECTING
#define COAP_SESSION_STATE_CONNECTING 1
Marco COAP_SESSION_STATE_HANDSHAKE
#define COAP_SESSION_STATE_HANDSHAKE 2
Marco COAP_SESSION_STATE_CSM
#define COAP_SESSION_STATE_CSM 3
Marco COAP_SESSION_STATE_ESTABLISHED
#define COAP_SESSION_STATE_ESTABLISHED 4
Marco COAP_DEFAULT_ACK_TIMEOUT
#define COAP_DEFAULT_ACK_TIMEOUT ((coap_fixed_point_t){2,0})
Marco COAP_DEFAULT_ACK_RANDOM_FACTOR
#define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500})
Marco COAP_DEFAULT_MAX_RETRANSMIT
#define COAP_DEFAULT_MAX_RETRANSMIT 4
Marco COAP_DEFAULT_NSTART
#define COAP_DEFAULT_NSTART 1
Functions
Func coap_session_release
void coap_session_release(coap_session_t *session);
Func coap_session_set_app_data
void coap_session_set_app_data(coap_session_t *session, void *data);
Func coap_session_get_app_data
void *coap_session_get_app_data(const coap_session_t *session);
Func coap_session_disconnected
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason);
Func coap_session_send_csm
void coap_session_send_csm(coap_session_t *session);
Func coap_session_connected
void coap_session_connected(coap_session_t *session);
Func coap_session_set_mtu
void coap_session_set_mtu(coap_session_t *session, unsigned mtu);
Func coap_session_max_pdu_size
size_t coap_session_max_pdu_size(const coap_session_t *session);
Func coap_session_send
ssize_t coap_session_send(coap_session_t *session,
const uint8_t *data, size_t datalen);
Func coap_session_write
ssize_t coap_session_write(coap_session_t *session,
const uint8_t *data, size_t datalen);
Func coap_session_send_pdu
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu);
Func coap_session_delay_pdu
ssize_t
coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu,
struct coap_queue_t *node);
Func coap_endpoint_set_default_mtu
void coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu);
Func coap_free_endpoint
void coap_free_endpoint(coap_endpoint_t *ep);
Func coap_session_free
void coap_session_free(coap_session_t *session);
Func coap_session_mfree
void coap_session_mfree(coap_session_t *session);
Func coap_session_set_max_retransmit
void coap_session_set_max_retransmit(coap_session_t *session,
unsigned int value);
Func coap_session_set_ack_timeout
void coap_session_set_ack_timeout(coap_session_t *session,
coap_fixed_point_t value);
Func coap_session_set_ack_random_factor
void coap_session_set_ack_random_factor(coap_session_t *session,
coap_fixed_point_t value);
Func coap_session_get_max_transmit
unsigned int coap_session_get_max_transmit(coap_session_t *session);
Func coap_session_send_ping
coap_tid_t coap_session_send_ping(coap_session_t *session);
Vars
Variable coap_endpoint_t
struct coap_endpoint_t;
Variable coap_context_t
struct coap_context_t;
Variable coap_queue_t
struct coap_queue_t;
Variable coap_session_t
coap_session_t *coap_session_reference(coap_session_t *session);
Variable coap_session_t
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
);
Variable coap_session_t
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
);
Variable coap_dtls_pki_t
struct coap_dtls_pki_t;
Variable coap_session_t
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
);
Variable coap_session_t
coap_session_t *coap_new_server_session(
struct coap_context_t *ctx,
struct coap_endpoint_t *ep
);
Variable coap_endpoint_t
coap_endpoint_t *coap_new_endpoint(struct coap_context_t *context, const coap_address_t *listen_addr, coap_proto_t proto);
Variable coap_session_t
coap_session_t *coap_endpoint_get_session(coap_endpoint_t *endpoint,
const struct coap_packet_t *packet, coap_tick_t now);
Variable coap_session_t
coap_session_t *coap_endpoint_new_dtls_session(coap_endpoint_t *endpoint,
const struct coap_packet_t *packet, coap_tick_t now);
Variable coap_session_t
coap_session_t *coap_session_get_by_peer(struct coap_context_t *ctx,
const struct coap_address_t *remote_addr, int ifindex);
Variable coap_fixed_point_t
coap_fixed_point_t coap_session_get_ack_timeout(coap_session_t *session);
Variable coap_fixed_point_t
coap_fixed_point_t coap_session_get_ack_random_factor(coap_session_t *session);
Consts
Const
const char *coap_session_str(const coap_session_t *session);
Const
const char *coap_endpoint_str(const coap_endpoint_t *endpoint);
Types
Typedefs
Typedef coap_fixed_point_t;
typedef struct coap_fixed_point_t {
uint16_t integer_part; /**< Integer part of fixed point variable */
uint16_t fractional_part; /**< Fractional part of fixed point variable
1/1000 (3 points) precision */
} coap_fixed_point_t;
Typedef coap_session_type_t
typedef uint8_t coap_session_type_t;
Typedef coap_session_state_t
typedef uint8_t coap_session_state_t;
Typedef coap_session_t;
typedef struct coap_session_t {
struct coap_session_t *next;
coap_proto_t proto; /**< protocol used */
coap_session_type_t type; /**< client or server side socket */
coap_session_state_t state; /**< current state of relationaship with peer */
unsigned ref; /**< reference count from queues */
unsigned tls_overhead; /**< overhead of TLS layer */
unsigned mtu; /**< path or CSM mtu */
coap_address_t local_if; /**< optional local interface address */
coap_address_t remote_addr; /**< remote address and port */
coap_address_t local_addr; /**< local address and port */
int ifindex; /**< interface index */
coap_socket_t sock; /**< socket object for the session, if any */
struct coap_endpoint_t *endpoint; /**< session's endpoint */
struct coap_context_t *context; /**< session's context */
void *tls; /**< security parameters */
uint16_t tx_mid; /**< the last message id that was used in this session */
uint8_t con_active; /**< Active CON request sent */
struct coap_queue_t *delayqueue; /**< list of delayed messages waiting to be sent */
size_t partial_write; /**< if > 0 indicates number of bytes already written from the pdu at the head of sendqueue */
uint8_t read_header[8]; /**< storage space for header of incoming message header */
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_tick_t last_rx_tx;
coap_tick_t last_tx_rst;
coap_tick_t last_ping;
coap_tick_t last_pong;
coap_tick_t csm_tx;
uint8_t *psk_identity;
size_t psk_identity_len;
uint8_t *psk_key;
size_t psk_key_len;
void *app; /**< application-specific data */
unsigned int max_retransmit; /**< maximum re-transmit count (default 4) */
coap_fixed_point_t ack_timeout; /**< timeout waiting for ack (default 2 secs) */
coap_fixed_point_t ack_random_factor; /**< ack random factor backoff (default 1.5) */
unsigned int dtls_timeout_count; /**< dtls setup retry counter */
int dtls_event; /**< Tracking any (D)TLS events on this sesison */
} coap_session_t;
Typedef coap_endpoint_t;
typedef struct coap_endpoint_t {
struct coap_endpoint_t *next;
struct coap_context_t *context; /**< endpoint's context */
coap_proto_t proto; /**< protocol used on this interface */
uint16_t default_mtu; /**< default mtu for this interface */
coap_socket_t sock; /**< socket object for the interface, if any */
coap_address_t bind_addr; /**< local interface address */
coap_session_t *sessions; /**< list of active sessions */
coap_session_t hello; /**< special session of DTLS hello messages */
} coap_endpoint_t;