libcoap  4.3.0
coap_session_internal.h
Go to the documentation of this file.
1 /*
2  * coap_session_internal.h -- Structures, Enums & Functions that are not
3  * exposed to application programming
4  *
5  * Copyright (C) 2010-2019 Olaf Bergmann <bergmann@tzi.org>
6  *
7  * SPDX-License-Identifier: BSD-2-Clause
8  *
9  * This file is part of the CoAP library libcoap. Please see README for terms
10  * of use.
11  */
12 
18 #ifndef COAP_SESSION_INTERNAL_H_
19 #define COAP_SESSION_INTERNAL_H_
20 
21 #include "coap_io_internal.h"
22 
23 #define COAP_DEFAULT_SESSION_TIMEOUT 300
24 #define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND)
25 #define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100
26 
40  uint16_t lport;
42 };
43 
48 struct coap_session_t {
53  unsigned ref;
54  size_t tls_overhead;
55  size_t mtu;
57  UT_hash_handle hh;
59  int ifindex;
64  void *tls;
65  uint16_t tx_mid;
67  uint8_t con_active;
76  size_t partial_write;
79  uint8_t read_header[8];
81  size_t partial_read;
118  void *app;
119  unsigned int max_retransmit;
125  unsigned int dtls_timeout_count;
128  uint8_t block_mode;
129  uint64_t tx_token;
130 };
131 
140  uint16_t default_mtu;
145 };
146 
153 
160 
172  const coap_bin_const_t *psk_hint);
173 
185  const coap_bin_const_t *psk_key);
186 
196  coap_context_t *ctx,
197  coap_endpoint_t *ep
198 );
199 
212 ssize_t coap_session_send(coap_session_t *session,
213  const uint8_t *data, size_t datalen);
214 
228 ssize_t coap_session_write(coap_session_t *session,
229  const uint8_t *data, size_t datalen);
230 
242 ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu);
243 
244 ssize_t
246  coap_queue_t *node);
247 
258  const coap_packet_t *packet, coap_tick_t now);
259 
272  coap_tick_t now);
273 
274 void coap_session_free(coap_session_t *session);
275 void coap_session_mfree(coap_session_t *session);
276 
279 #define SESSIONS_ADD(e, obj) \
280  HASH_ADD(hh, (e), addr_hash, sizeof((obj)->addr_hash), (obj))
281 
282 #define SESSIONS_DELETE(e, obj) \
283  HASH_DELETE(hh, (e), (obj))
284 
285 #define SESSIONS_ITER(e, el, rtmp) \
286  HASH_ITER(hh, (e), el, rtmp)
287 
288 #define SESSIONS_ITER_SAFE(e, el, rtmp) \
289 for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
290 
291 #define SESSIONS_FIND(e, k, res) { \
292  HASH_FIND(hh, (e), &(k), sizeof(k), (res)); \
293  }
294 
295 #endif /* COAP_SESSION_INTERNAL_H_ */
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:122
coap_session_t * coap_session_new_dtls_session(coap_session_t *session, coap_tick_t now)
Create a new DTLS session for the session.
Definition: coap_session.c:691
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition: pdu.h:231
coap_proto_t
CoAP protocol types.
Definition: pdu.h:280
coap_session_t * coap_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.
Definition: coap_session.c:554
ssize_t coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node)
Definition: coap_session.c:312
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).
Definition: coap_session.c:996
void coap_session_send_csm(coap_session_t *session)
Notify session transport has just connected and CSM exchange can now start.
Definition: coap_session.c:351
coap_session_t * coap_new_server_session(coap_context_t *ctx, coap_endpoint_t *ep)
Creates a new server session for the specified endpoint.
ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for datagram data transmission.
Definition: coap_session.c:277
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).
void coap_session_connected(coap_session_t *session)
Notify session that it has just connected or reconnected.
Definition: coap_session.c:399
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu)
Send a pdu according to the session's protocol.
Definition: net.c:766
void coap_session_free(coap_session_t *session)
Definition: coap_session.c:225
void coap_session_mfree(coap_session_t *session)
Definition: coap_session.c:159
ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for stream data transmission.
Definition: coap_session.c:298
coap_session_type_t
coap_session_type_t values
Definition: coap_session.h:41
coap_session_state_t
coap_session_state_t values
Definition: coap_session.h:52
Only used for servers for hashing incoming packets.
uint16_t lport
local port
coap_address_t remote
remote address and port
coap_proto_t proto
CoAP protocol.
multi-purpose address abstraction
Definition: address.h:96
CoAP binary data definition with const data.
Definition: str.h:58
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:338
Abstraction of virtual endpoint that can be attached to coap_context_t.
coap_context_t * context
endpoint's context
uint16_t default_mtu
default mtu for this interface
coap_session_t * sessions
hash table or list of active sessions
struct coap_endpoint_t * next
coap_address_t bind_addr
local interface address
coap_socket_t sock
socket object for the interface, if any
coap_proto_t proto
protocol used on this interface
Abstraction of a fixed point number that can be used where necessary instead of a float.
Definition: coap_session.h:29
Structure to hold large body (many blocks) client receive information.
Structure to hold large body (many blocks) server receive information.
Structure to hold large body (many blocks) transmission information.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Queue entry.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_lg_xmit_t * lg_xmit
list of large transmissions
unsigned int dtls_timeout_count
dtls setup retry counter
coap_bin_const_t * psk_key
If client, this field contains the current pre-shared key for server; When this field is NULL,...
coap_endpoint_t * endpoint
session's endpoint
coap_socket_t sock
socket object for the session, if any
unsigned int max_retransmit
maximum re-transmit count (default 4)
coap_pdu_t * partial_pdu
incomplete incoming pdu
coap_bin_const_t * psk_identity
If client, this field contains the current identity for server; When this field is NULL,...
coap_session_state_t state
current state of relationaship with peer
uint64_t tx_token
Next token number to use.
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
uint8_t read_header[8]
storage space for header of incoming message header
coap_addr_tuple_t addr_info
key: remote/local address info
coap_proto_t proto
protocol used
uint16_t tx_mid
the last message id that was used in this session
unsigned ref
reference count from queues
coap_bin_const_t * psk_hint
If client, this field contains the server provided identity hint.
coap_dtls_cpsk_t cpsk_setup_data
client provided PSK initial setup data
size_t mtu
path or CSM mtu
size_t partial_read
if > 0 indicates number of bytes already read for an incoming message
int dtls_event
Tracking any (D)TLS events on this sesison.
void * tls
security parameters
uint8_t csm_block_supported
CSM TCP blocks supported.
coap_fixed_point_t ack_random_factor
ack random factor backoff (default 1.5)
uint8_t con_active
Active CON request sent.
coap_queue_t * delayqueue
list of delayed messages waiting to be sent
size_t tls_overhead
overhead of TLS layer
void * app
application-specific data
coap_mid_t last_ping_mid
the last keepalive message id that was used in this session
coap_lg_srcv_t * lg_srcv
Server list of expected large receives.
coap_lg_crcv_t * lg_crcv
Client list of expected large receives.
coap_fixed_point_t ack_timeout
timeout waiting for ack (default 2 secs)
coap_session_type_t type
client or server side socket
coap_context_t * context
session's context
size_t partial_write
if > 0 indicates number of bytes already written from the pdu at the head of sendqueue
coap_addr_hash_t addr_hash
Address hash for server incoming packets.
int ifindex
interface index