tinydtls  0.8.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
peer.h
Go to the documentation of this file.
1 /* dtls -- a very basic DTLS implementation
2  *
3  * Copyright (C) 2011--2013 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
31 #ifndef _DTLS_PEER_H_
32 #define _DTLS_PEER_H_
33 
34 #include <sys/types.h>
35 
36 #include "tinydtls.h"
37 #include "global.h"
38 #include "session.h"
39 
40 #include "state.h"
41 #include "crypto.h"
42 
43 #ifndef WITH_CONTIKI
44 #include "uthash.h"
45 #endif /* WITH_CONTIKI */
46 
48 
52 typedef struct dtls_peer_t {
53 #ifndef WITH_CONTIKI
55 #else /* WITH_CONTIKI */
56  struct dtls_peer_t *next;
57 #endif /* WITH_CONTIKI */
58 
66 } dtls_peer_t;
67 
69 {
70  if (peer->security_params[0] && peer->security_params[0]->epoch == epoch) {
71  return peer->security_params[0];
72  } else if (peer->security_params[1] && peer->security_params[1]->epoch == epoch) {
73  return peer->security_params[1];
74  } else {
75  return NULL;
76  }
77 }
78 
80 {
81  return peer->security_params[0];
82 }
83 
85 {
86  if (peer->security_params[1])
88 
90  if (!peer->security_params[1]) {
91  return NULL;
92  }
93  peer->security_params[1]->epoch = peer->security_params[0]->epoch + 1;
94  return peer->security_params[1];
95 }
96 
98 {
99  dtls_security_parameters_t * security0 = peer->security_params[0];
100  dtls_security_parameters_t * security1 = peer->security_params[1];
101 
102  if (!security0 || !security1 || security0->epoch < security1->epoch)
103  return;
104 
105  dtls_security_free(security1);
106  peer->security_params[1] = NULL;
107 }
108 
109 static inline void dtls_security_params_switch(dtls_peer_t *peer)
110 {
111  dtls_security_parameters_t * security = peer->security_params[1];
112 
113  peer->security_params[1] = peer->security_params[0];
114  peer->security_params[0] = security;
115 }
116 
117 void peer_init();
118 
131 
133 void dtls_free_peer(dtls_peer_t *peer);
134 
136 static inline dtls_state_t dtls_peer_state(const dtls_peer_t *peer) {
137  return peer->state;
138 }
139 
144 static inline int dtls_peer_is_connected(const dtls_peer_t *peer) {
145  return peer->state == DTLS_STATE_CONNECTED;
146 }
147 
148 #endif /* _DTLS_PEER_H_ */
static dtls_state_t dtls_peer_state(const dtls_peer_t *peer)
Definition: peer.h:136
public tinydtls API
dtls_state_t
Definition: state.h:40
struct dtls_peer_t dtls_peer_t
void peer_init()
Definition: peer.c:31
dtls_state_t state
Definition: peer.h:62
static dtls_security_parameters_t * dtls_security_params_epoch(dtls_peer_t *peer, uint16_t epoch)
Definition: peer.h:68
dtls_peer_t * dtls_new_peer(const session_t *session)
Definition: peer.c:72
session_t session
Definition: peer.h:59
static void dtls_security_params_free_other(dtls_peer_t *peer)
Definition: peer.h:97
dtls_handshake_parameters_t * handshake_params
Definition: peer.h:65
static dtls_security_parameters_t * dtls_security_params(dtls_peer_t *peer)
Definition: peer.h:79
static void dtls_security_params_switch(dtls_peer_t *peer)
Definition: peer.h:109
dtls_peer_type
Definition: peer.h:47
void dtls_security_free(dtls_security_parameters_t *security)
Definition: crypto.c:174
dtls_security_parameters_t * security_params[2]
Definition: peer.h:64
state information for DTLS FSM
UT_hash_handle hh
Definition: peer.h:54
dtls_security_parameters_t * dtls_security_new()
Definition: crypto.c:155
static dtls_security_parameters_t * dtls_security_params_next(dtls_peer_t *peer)
Definition: peer.h:84
void dtls_free_peer(dtls_peer_t *peer)
Definition: peer.c:41
static int dtls_peer_is_connected(const dtls_peer_t *peer)
Definition: peer.h:144
dtls_peer_type role
Definition: peer.h:61