summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--code/ecp/Makefile.fe3102
-rw-r--r--code/ecp/Makefile.posix3
-rw-r--r--code/ecp/config_fe310.h6
-rw-r--r--code/ecp/config_posix.h10
-rw-r--r--code/ecp/core.c76
-rw-r--r--code/ecp/core.h5
-rwxr-xr-xcode/ecp/platform.sh1
7 files changed, 75 insertions, 28 deletions
diff --git a/code/ecp/Makefile.fe310 b/code/ecp/Makefile.fe310
index e753571..96b16a2 100644
--- a/code/ecp/Makefile.fe310
+++ b/code/ecp/Makefile.fe310
@@ -9,5 +9,5 @@ FE310_HOME=/opt/my/freedom-e-sdk
CC=$(FE310_HOME)/work/build/riscv-gnu-toolchain/riscv64-unknown-elf/prefix/bin/riscv64-unknown-elf-gcc
AR=$(FE310_HOME)/work/build/riscv-gnu-toolchain/riscv64-unknown-elf/prefix/bin/riscv64-unknown-elf-ar
-CFLAGS_PL=-O3 -fno-builtin-printf -march=rv32imac -mabi=ilp32 -mcmodel=medany -I$(FE310_HOME)/bsp/include -I$(FE310_HOME)/bsp/drivers -I$(FE310_HOME)/bsp/env -I$(FE310_HOME)/bsp/env/freedom-e300-hifive1
+CFLAGS_PL=-O3 -fno-builtin-printf -march=rv32imac -mabi=ilp32 -mcmodel=medany -I$(FE310_HOME)/bsp/include -I$(FE310_HOME)/bsp/drivers -I$(FE310_HOME)/bsp/env -I$(FE310_HOME)/bsp/env/freedom-e300-hifive1 -DECP_DEBUG=1
# LDFLAGS_PL=-lm -pthread \ No newline at end of file
diff --git a/code/ecp/Makefile.posix b/code/ecp/Makefile.posix
index c83e050..fe674a5 100644
--- a/code/ecp/Makefile.posix
+++ b/code/ecp/Makefile.posix
@@ -4,5 +4,6 @@ htable=htable
vconn=vconn
obj_rbuf=rbuf.o rbuf_send.o rbuf_recv.o msgq.o
-CFLAGS_PL=-O3
+CFLAGS_PL=-O3 -DECP_WITH_PTHREAD=1 -DECP_WITH_HTABLE=1 -DECP_WITH_RBUF=1 -DECP_WITH_MSGQ=1 -DECP_DEBUG=1
+
LDFLAGS_PL=-lm -pthread \ No newline at end of file
diff --git a/code/ecp/config_fe310.h b/code/ecp/config_fe310.h
deleted file mode 100644
index ff61012..0000000
--- a/code/ecp/config_fe310.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _ECP_CONFIG
-#define _ECP_CONFIG
-
-#define ECP_DEBUG 1
-
-#endif \ No newline at end of file
diff --git a/code/ecp/config_posix.h b/code/ecp/config_posix.h
deleted file mode 100644
index 51babef..0000000
--- a/code/ecp/config_posix.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef _ECP_CONFIG
-#define _ECP_CONFIG
-
-#define ECP_WITH_PTHREAD 1
-#define ECP_WITH_HTABLE 1
-#define ECP_WITH_RBUF 1
-#define ECP_WITH_MSGQ 1
-#define ECP_DEBUG 1
-
-#endif \ No newline at end of file
diff --git a/code/ecp/core.c b/code/ecp/core.c
index 0ecb51e..8a5be76 100644
--- a/code/ecp/core.c
+++ b/code/ecp/core.c
@@ -1008,7 +1008,7 @@ int ecp_conn_dhkey_get_curr(ECPConnection *conn, unsigned char *idx, unsigned ch
if (idx) *idx = _idx;
return ECP_OK;
}
-
+
ssize_t ecp_pack(ECPContext *ctx, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t pld_size) {
ssize_t rv;
@@ -1029,9 +1029,9 @@ ssize_t ecp_pack(ECPContext *ctx, unsigned char *packet, size_t pkt_size, unsign
payload[3] = (seq & 0x000000FF);
rv = ctx->cr.aead_enc(packet+ECP_SIZE_PKT_HDR, pkt_size-ECP_SIZE_PKT_HDR, payload, pld_size, shsec, nonce);
if (rv < 0) return ECP_ERR_ENCRYPT;
-
+
memcpy(nonce, packet+ECP_SIZE_PKT_HDR, ECP_AEAD_SIZE_NONCE);
-
+
return rv+ECP_SIZE_PKT_HDR;
}
@@ -1694,6 +1694,67 @@ ssize_t ecp_receive(ECPConnection *conn, unsigned char mtype, unsigned char *msg
#endif
}
+#ifdef ECP_DEBUG
+static char *_utoa(unsigned value, char *str, int base) {
+ const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+ int i, j;
+ unsigned remainder;
+ char c;
+
+ /* Check base is supported. */
+ if ((base < 2) || (base > 36))
+ {
+ str[0] = '\0';
+ return NULL;
+ }
+
+ /* Convert to string. Digits are in reverse order. */
+ i = 0;
+ do
+ {
+ remainder = value % base;
+ str[i++] = digits[remainder];
+ value = value / base;
+ } while (value != 0);
+ str[i] = '\0';
+
+ /* Reverse string. */
+ for (j = 0, i--; j < i; j++, i--)
+ {
+ c = str[j];
+ str[j] = str[i];
+ str[i] = c;
+ }
+
+ return str;
+}
+
+static char *_itoa(int value, char *str, int base) {
+ unsigned uvalue;
+ int i = 0;
+
+ /* Check base is supported. */
+ if ((base < 2) || (base > 36))
+ {
+ str[0] = '\0';
+ return NULL;
+ }
+
+ /* Negative numbers are only supported for decimal.
+ * Cast to unsigned to avoid overflow for maximum negative value. */
+ if ((base == 10) && (value < 0))
+ {
+ str[i++] = '-';
+ uvalue = (unsigned)-value;
+ }
+ else
+ uvalue = (unsigned)value;
+
+ _utoa(uvalue, &str[i], base);
+ return str;
+}
+#endif
+
static int recv_p(ECPSocket *sock, ECPNetAddr *addr, ECPBuffer *packet, size_t size) {
ECP2Buffer bufs;
ECPBuffer payload;
@@ -1727,7 +1788,14 @@ int ecp_receiver(ECPSocket *sock) {
rv = sock->ctx->tr.recv(&sock->sock, &packet, &addr, next ? next : sock->poll_timeout);
if (rv > 0) {
int _rv = recv_p(sock, &addr, &packet, rv);
- DPRINT(_rv, "ERR:recv_p - RV:%d\n", _rv);
+#ifdef ECP_DEBUG
+ if (_rv) {
+ char b[16];
+ puts("ERR:");
+ puts(_itoa(_rv, b, 10));
+ puts("\n");
+ }
+#endif
}
next = ecp_timer_exe(sock);
}
diff --git a/code/ecp/core.h b/code/ecp/core.h
index 244df4d..b1a4e7f 100644
--- a/code/ecp/core.h
+++ b/code/ecp/core.h
@@ -3,8 +3,6 @@
#include <stdint.h>
#include <string.h>
-#include "config.h"
-
#ifdef ECP_WITH_PTHREAD
#include <pthread.h>
#endif
@@ -133,9 +131,6 @@ typedef uint32_t ecp_seq_t;
#ifdef ECP_DEBUG
#include <stdio.h>
-#define DPRINT(cnd, format, ...) { if (cnd) { fprintf (stderr, format, __VA_ARGS__); } }
-#else
-#define DPRINT(cnd, format, ...) {}
#endif
struct ECPBuffer;
diff --git a/code/ecp/platform.sh b/code/ecp/platform.sh
index b265bd7..854fbba 100755
--- a/code/ecp/platform.sh
+++ b/code/ecp/platform.sh
@@ -12,5 +12,4 @@ PLATFORM=$1
rm -f $BASEDIR/platform
ln -sf ./$PLATFORM $BASEDIR/platform
-ln -sf ./config_$PLATFORM.h $BASEDIR/config.h
ln -sf ./Makefile.$PLATFORM $BASEDIR/Makefile.platform