From 9c3cb27bd205faa7b77b9215d3a432214b8342fb Mon Sep 17 00:00:00 2001
From: "7u83@mail.ru" <7u83@mail.ru@noemail.net>
Date: Sat, 7 Feb 2015 01:59:05 +0000
Subject: [PATCH] Iital commit
Common bio functions for openssl and gnutls
FossilOrigin-Name: a9deeccfbf93e8e82afe15621ea8df4aeceb7d8a03f0756c897d4fe09d40b572
---
src/capwap/dtls_bio.c | 69 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 src/capwap/dtls_bio.c
diff --git a/src/capwap/dtls_bio.c b/src/capwap/dtls_bio.c
new file mode 100644
index 00000000..251d5854
--- /dev/null
+++ b/src/capwap/dtls_bio.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of libcapwap.
+
+ libcapwap is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ libcapwap is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Foobar. If not, see .
+
+*/
+
+#include
+
+#include "cw_log.h"
+#include "dtls.h"
+
+
+
+int dtls_bio_read(struct conn *conn, char *out, int maxlen)
+{
+ if (conn->dtls_buffer_len == 0) {
+ int len = conn->recv_packet(conn, conn->dtls_buffer, 2048);
+ if (len < 4)
+ return 0;
+ conn->dtls_buffer_len = len - 4;
+ conn->dtls_buffer_pos = 4;
+ }
+
+ if (conn->dtls_buffer_len > maxlen) {
+ memcpy(out, conn->dtls_buffer + conn->dtls_buffer_pos, maxlen);
+ conn->dtls_buffer_len -= maxlen;
+ conn->dtls_buffer_pos += maxlen;
+ cw_dbg(DBG_DTLS_BIO, "SSL BIO read: (maxlen = %d), remain %d", maxlen,conn->dtls_buffer_len);
+ cw_dbg_dmp(DBG_DTLS_BIO_DMP,(uint8_t*)out,maxlen,"Dump...");
+
+ return maxlen;
+
+ }
+ memcpy(out, conn->dtls_buffer + conn->dtls_buffer_pos, conn->dtls_buffer_len);
+ int ret = conn->dtls_buffer_len;
+ conn->dtls_buffer_len = 0;
+ cw_dbg(DBG_DTLS_BIO, "SSL BIO read: (maxlen = %d), remain %d", ret,conn->dtls_buffer_len);
+ cw_dbg_dmp(DBG_DTLS_BIO_DMP,(uint8_t*)out,ret,"Dump...");
+ return ret;
+}
+
+
+int dtls_bio_write(struct conn * conn, const char *data, int len)
+{
+ uint8_t buffer[2048];
+ *((uint32_t *) buffer) = htonl(1 << 24);
+ memcpy(buffer + 4, data, len);
+ int rc = conn->send_packet(conn, buffer, len + 4);
+
+ cw_dbg(DBG_DTLS_BIO, "SSL BIO write: %d bytes, rc=%d, ptr: %p", len, rc, data);
+ cw_dbg_dmp(DBG_DTLS_BIO_DMP,(uint8_t*)data,len,"Dump ...");
+
+ if (rc < 0)
+ return rc;
+ return rc - 4;
+}
+