Version 0.5.0 of tinydtls
Dependents: tinydtls_test_cellular tinydtls_test_ethernet tiny-dtls
peer.h
00001 /* dtls -- a very basic DTLS implementation 00002 * 00003 * Copyright (C) 2011--2013 Olaf Bergmann <bergmann@tzi.org> 00004 * 00005 * Permission is hereby granted, free of charge, to any person 00006 * obtaining a copy of this software and associated documentation 00007 * files (the "Software"), to deal in the Software without 00008 * restriction, including without limitation the rights to use, copy, 00009 * modify, merge, publish, distribute, sublicense, and/or sell copies 00010 * of the Software, and to permit persons to whom the Software is 00011 * furnished to do so, subject to the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be 00014 * included in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00020 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00021 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00023 * SOFTWARE. 00024 */ 00025 00026 /** 00027 * @file peer.h 00028 * @brief information about peers in a DTLS session 00029 */ 00030 00031 #ifndef _PEER_H_ 00032 #define _PEER_H_ 00033 00034 #include "config.h" 00035 #include "global.h" 00036 00037 #include "state.h" 00038 #include "crypto.h" 00039 00040 #ifndef WITH_CONTIKI 00041 #include "uthash.h" 00042 #endif /* WITH_CONTIKI */ 00043 00044 typedef enum { DTLS_CLIENT=0, DTLS_SERVER } dtls_peer_type; 00045 00046 /** 00047 * Holds security parameters, local state and the transport address 00048 * for each peer. */ 00049 typedef struct dtls_peer_t { 00050 #ifndef WITH_CONTIKI 00051 UT_hash_handle hh; 00052 #else /* WITH_CONTIKI */ 00053 struct dtls_peer_t *next; 00054 #endif /* WITH_CONTIKI */ 00055 00056 session_t session; /**< peer address and local interface */ 00057 00058 dtls_peer_type role; /**< denotes if this host is DTLS_CLIENT or DTLS_SERVER */ 00059 dtls_state_t state; /**< DTLS engine state */ 00060 uint16 epoch; /**< counter for cipher state changes*/ 00061 uint48 rseq; /**< sequence number of last record sent */ 00062 00063 dtls_hs_state_t hs_state; /**< handshake protocol status */ 00064 00065 dtls_security_parameters_t security_params; 00066 dtls_handshake_parameters_t handshake_params; 00067 } dtls_peer_t; 00068 00069 void peer_init(); 00070 00071 /** 00072 * Creates a new peer for given @p session. The current configuration 00073 * is initialized with the cipher suite TLS_NULL_WITH_NULL_NULL (i.e. 00074 * no security at all). This function returns a pointer to the new 00075 * peer or NULL on error. The caller is responsible for releasing the 00076 * storage allocated for this peer using dtls_free_peer(). 00077 * 00078 * @param session The remote peer's address and local interface index. 00079 * @return A pointer to a newly created and initialized peer object 00080 * or NULL on error. 00081 */ 00082 dtls_peer_t *dtls_new_peer(const session_t *session); 00083 00084 /** Releases the storage allocated to @p peer. */ 00085 void dtls_free_peer(dtls_peer_t *peer); 00086 00087 /** Returns the current state of @p peer. */ 00088 static inline dtls_state_t dtls_peer_state(const dtls_peer_t *peer) { 00089 return peer->state; 00090 } 00091 00092 /** 00093 * Checks if given @p peer is connected. This function returns 00094 * @c 1 if connected, or @c 0 otherwise. 00095 */ 00096 static inline int dtls_peer_is_connected(const dtls_peer_t *peer) { 00097 return peer->state == DTLS_STATE_CONNECTED; 00098 } 00099 00100 #endif /* _PEER_H_ */
Generated on Tue Jul 12 2022 21:37:38 by 1.7.2