Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed tinydtls
Fork of tinydtls_test_ethernet by
Diff: tinydtls/peer.c
- Revision:
- 0:6ae42a2aff75
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tinydtls/peer.c Wed Oct 09 14:48:52 2013 +0000
@@ -0,0 +1,101 @@
+/* dtls -- a very basic DTLS implementation
+ *
+ * Copyright (C) 2011--2013 Olaf Bergmann <bergmann@tzi.org>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "peer.h"
+#include "debug.h"
+
+#ifndef NDEBUG
+#include <stdio.h>
+
+extern size_t dsrv_print_addr(const session_t *addr, unsigned char *buf,
+ size_t len);
+#endif /* NDEBUG */
+
+#ifndef WITH_CONTIKI
+void peer_init()
+{
+}
+
+static inline dtls_peer_t *
+dtls_malloc_peer() {
+ return (dtls_peer_t *)malloc(sizeof(dtls_peer_t));
+}
+
+void
+dtls_free_peer(dtls_peer_t *peer) {
+ free(peer);
+}
+#else /* WITH_CONTIKI */
+PROCESS(dtls_retransmit_process, "DTLS retransmit process");
+
+#include "memb.h"
+MEMB(peer_storage, dtls_peer_t, DTLS_PEER_MAX);
+
+void
+peer_init() {
+ memb_init(&peer_storage);
+}
+
+static inline dtls_peer_t *
+dtls_malloc_peer() {
+ return memb_alloc(&peer_storage);
+}
+
+void
+dtls_free_peer(dtls_peer_t *peer) {
+ memb_free(&peer_storage, peer);
+}
+#endif /* WITH_CONTIKI */
+
+dtls_peer_t *
+dtls_new_peer(const session_t *session) {
+ dtls_peer_t *peer;
+
+ peer = dtls_malloc_peer();
+ if (peer) {
+ memset(peer, 0, sizeof(dtls_peer_t));
+ memcpy(&peer->session, session, sizeof(session_t));
+
+#ifndef NDEBUG
+ if (dtls_get_log_level() >= LOG_DEBUG) {
+ unsigned char addrbuf[72];
+ dsrv_print_addr(session, addrbuf, sizeof(addrbuf));
+ printf("dtls_new_peer: %s\n", addrbuf);
+ }
+#endif
+ /* initially allow the NULL cipher */
+ CURRENT_CONFIG(peer)->cipher = TLS_NULL_WITH_NULL_NULL;
+
+ /* initialize the handshake hash wrt. the hard-coded DTLS version */
+ debug("DTLSv12: initialize HASH_SHA256\n");
+ /* TLS 1.2: PRF(secret, label, seed) = P_<hash>(secret, label + seed) */
+ /* FIXME: we use the default SHA256 here, might need to support other
+ hash functions as well */
+ dtls_hash_init(&peer->hs_state.hs_hash);
+ }
+
+ return peer;
+}
+
