forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsm.h
125 lines (110 loc) · 3.4 KB
/
dsm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup net_dsm DTLS Session Management (DSM)
* @ingroup net net_dtls
* @brief This module provides functionality to store and retrieve session
* information of DTLS connections.
*
* dsm allows to store necessary session information so that not every application
* has to provide the potentially maximum number of possible session objects.
* Session storage can be offloaded to this generic module.
*
* @{\
*
* @file
* @brief DTLS session management module definition
*
* @note This module does not accept or close DTLS sessions, it merely
* provides a place to store session objects.
*
* @author János Brodbeck <janos.brodbeck@ml-pa.com>
*/
#ifndef NET_DSM_H
#define NET_DSM_H
#include <stdint.h>
#include "dtls.h"
#include "net/sock/dtls.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Maximum number of maintained DTLS sessions (tinyDTLS)
*/
#ifndef CONFIG_DSM_PEER_MAX
#define CONFIG_DSM_PEER_MAX (CONFIG_DTLS_PEER_MAX)
#endif
/**
* @brief Session management states
*/
typedef enum {
NO_SPACE = -1,
SESSION_STATE_NONE = 0,
SESSION_STATE_HANDSHAKE,
SESSION_STATE_ESTABLISHED
} dsm_state_t;
/**
* @brief Initialize the DTLS session management
*
* Must call once before first use.
*/
void dsm_init(void);
/**
* @brief Stores a session
*
* Stores a given session in the internal storage of the session management.
* If the session is already stored only the state will be updated when the session
* gets established.
*
* @param[in] sock @ref sock_dtls_t, which the session is created on
* @param[in] session Session to store
* @param[in] new_state New state of the session
* @param[in] restore Indicates, whether the session object should be restored
* when an already established session is found
*
* @return Previous state of the session. If no session existed before it returns
* SESSION_STATE_NONE. If no space is available it returns NO_SPACE.
*/
dsm_state_t dsm_store(sock_dtls_t *sock, sock_dtls_session_t *session,
dsm_state_t new_state, bool restore);
/**
* @brief Removes a session
*
* Removes a given session in the internal storage of the session management.
*
* @param[in] sock @ref sock_dtls_t, which the session is created on
* @param[in] session Session to store
*/
void dsm_remove(sock_dtls_t *sock, sock_dtls_session_t *session);
/**
* @brief Returns the maximum number of sessions slots
*
* @return Number of session slots.
*/
uint8_t dsm_get_num_maximum_slots(void);
/**
* @brief Returns the number of available session slots
*
* @return Number of available session slots in the session management.
*/
uint8_t dsm_get_num_available_slots(void);
/**
* @brief Returns the least recently used session
*
* @param[in] sock @ref sock_dtls_t, which the session is created on
* @param[out] session Oldest used session
*
* @return 1, on success
* @return -1, when no session is stored
*/
ssize_t dsm_get_least_recently_used_session(sock_dtls_t *sock, sock_dtls_session_t *session);
#ifdef __cplusplus
}
#endif
#endif /* NET_DSM_H */
/** @} */