Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit a71b296

Browse files
committed
feat(endpoint): Integration with Legato
The files and directory structure are changed. The directory endpoint/endpointComp is for building the Legato app. The endpoint/endpoint.c is renamed as endpoint/endpoint_core.c to separate the core functions. Same as the endpoint/endpoint.h. New: To build the endpoint Legato app, use the command 'make legato'. It is implemented with the mkapp command. Besides, the shared library libendpoint.so can be generated with Bazel as well. Close #576.
1 parent b2c2979 commit a71b296

File tree

10 files changed

+285
-14
lines changed

10 files changed

+285
-14
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,10 @@ docs/html/
9494
__pycache__/
9595

9696
# Certificate for build system
97-
pem/*.inc
97+
pem/*.inc
98+
99+
# Legato app related files
100+
resolv.conf
101+
output_base/
102+
_build_endpoint/
103+
endpoint.wp77xx.update

Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ DCURL_LIB := $(DCURL_DIR)/build/libdcurl.so
33
MOSQUITTO_DIR := third_party/mosquitto
44
MOSQUITTO_LIB := $(MOSQUITTO_DIR)/lib/libmosquitto.so.1
55
PEM_DIR = pem
6-
DEPS += $(DCURL_LIB)
76
PEM := $(PEM_DIR)/cert.pem
7+
NAMESERVER := 8.8.8.8
8+
RESOLV_CONF_DIR := endpoint/endpointComp
9+
OUTPUT_BASE_DIR := output_base
10+
DEPS += $(DCURL_LIB)
811

912
all: $(DEPS) cert
1013

11-
.PHONY: $(DCURL_LIB) $(MOSQUITTO_LIB) cert check_pem
14+
.PHONY: $(DCURL_LIB) $(MOSQUITTO_LIB) legato cert check_pem
1215

1316
$(DCURL_LIB): $(DCURL_DIR)
1417
git submodule update --init $^
@@ -23,6 +26,20 @@ $(MOSQUITTO_LIB): $(MOSQUITTO_DIR)
2326
@echo
2427
$(MAKE) -C $^ WITH_DOCS=no
2528

29+
# Build endpoint Legato app
30+
legato:
31+
# Generate resolv.conf
32+
echo "nameserver $(NAMESERVER)" > $(RESOLV_CONF_DIR)/resolv.conf
33+
# Fetch the required external source code
34+
# FIXME: Use 'fetch' instead of 'build' to avoid extra building actions.
35+
# The 'build' option is for getting the header file like 'mam/mam/mam_endpoint_t_set.h',
36+
# which can not be downloaded when the 'fetch' option is used.
37+
bazel --output_base=$(OUTPUT_BASE_DIR) build //endpoint:libendpoint.so
38+
# Add the soft link for handling the preprocessing of header file path inclusion like Bazel does
39+
ln -f -s ./lib/high/Keccak/FIPS202 ./$(OUTPUT_BASE_DIR)/external/keccak/keccak
40+
# Generate endpoint Legato app
41+
(cd endpoint && leaf shell -c "mkapp -v -t wp77xx endpoint.adef")
42+
2643
cert: check_pem
2744
@xxd -i $(PEM) > $(PEM_DIR)/ca_crt.inc
2845
@sed -E \

endpoint/BUILD

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cc_library(
2-
name = "endpoint",
3-
srcs = ["endpoint.c"],
4-
hdrs = ["endpoint.h"],
2+
name = "endpoint_core",
3+
srcs = ["endpoint_core.c"],
4+
hdrs = ["endpoint_core.h"],
55
defines = [
66
"ENDPOINT_HOST=\"localhost\"",
77
"ENDPOINT_PORT=\"443\"",
@@ -18,13 +18,44 @@ cc_library(
1818
)
1919

2020
cc_test(
21-
name = "test_endpoint",
21+
name = "test_endpoint_core",
2222
srcs = [
23-
"test_endpoint.c",
23+
"test_endpoint_core.c",
2424
],
2525
deps = [
26-
":endpoint",
26+
":endpoint_core",
2727
"//common",
2828
"//tests:test_define",
2929
],
3030
)
31+
32+
cc_binary(
33+
name = "libendpoint.so",
34+
srcs = [
35+
"endpoint_core.c",
36+
"endpoint_core.h",
37+
],
38+
defines = [
39+
"TA_HOST=\"localhost\"",
40+
"TA_PORT=\"443\"",
41+
"TA_SSL_SEED=\"nonce\"",
42+
],
43+
linkshared = True,
44+
deps = [
45+
"//common",
46+
"//utils:cipher",
47+
"//utils:https",
48+
"//utils:text_serializer",
49+
"//utils:tryte_byte_conv",
50+
],
51+
)
52+
53+
platform(
54+
name = "linux_arm",
55+
constraint_values = [
56+
"@platforms//os:linux",
57+
# FIXME: The generic CPU name will be replaced in the future
58+
# ref: https://github.com/bazelbuild/platforms/blob/master/cpu/BUILD
59+
"@platforms//cpu:arm",
60+
],
61+
)

endpoint/endpoint.adef

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
executables:
2+
{
3+
endpoint = ( endpointComp )
4+
}
5+
6+
processes:
7+
{
8+
run:
9+
{
10+
(endpoint)
11+
}
12+
}
13+
14+
start: manual

endpoint/endpointComp/Component.cdef

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
sources:
2+
{
3+
${CURDIR}/../endpoint_core.c
4+
5+
${CURDIR}/../../output_base/external/http_parser/http_parser.c
6+
7+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/aes.c
8+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/arc4.c
9+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/asn1parse.c
10+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/asn1write.c
11+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/base64.c
12+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/bignum.c
13+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/blowfish.c
14+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/camellia.c
15+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ccm.c
16+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/certs.c
17+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/chacha20.c
18+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/chachapoly.c
19+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/cipher.c
20+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/cipher_wrap.c
21+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ctr_drbg.c
22+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/debug.c
23+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/des.c
24+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/dhm.c
25+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ecdh.c
26+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ecdsa.c
27+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ecp.c
28+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ecp_curves.c
29+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/entropy.c
30+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/entropy_poll.c
31+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/gcm.c
32+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/hmac_drbg.c
33+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/md5.c
34+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/md.c
35+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/md_wrap.c
36+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/net_sockets.c
37+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/oid.c
38+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/pem.c
39+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/pk.c
40+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/pkcs12.c
41+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/pkcs5.c
42+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/pkparse.c
43+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/pk_wrap.c
44+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/platform_util.c
45+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/poly1305.c
46+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ripemd160.c
47+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/rsa.c
48+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/rsa_internal.c
49+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/sha1.c
50+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/sha256.c
51+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/sha512.c
52+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ssl_ciphersuites.c
53+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ssl_cli.c
54+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ssl_srv.c
55+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/ssl_tls.c
56+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/timing.c
57+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/x509.c
58+
${CURDIR}/../../output_base/external/mbedtls_2_16_6/library/x509_crt.c
59+
60+
${CURDIR}/../../utils/cipher.c
61+
${CURDIR}/../../utils/connectivity/conn_http.c
62+
${CURDIR}/../../utils/https.c
63+
${CURDIR}/../../utils/text_serializer.c
64+
${CURDIR}/../../utils/tryte_byte_conv.c
65+
66+
endpoint.c
67+
}
68+
69+
cflags:
70+
{
71+
-g -O0
72+
73+
-I${CURDIR}/../..
74+
75+
// The header files under this directory are downloaded only when the corresponding 'bazel build' command is used
76+
-I${CURDIR}/../../output_base/execroot/__main__/bazel-out/k8-fastbuild/bin/external/entangled
77+
78+
-I${CURDIR}/../../output_base/external/com_github_uthash/src
79+
-I${CURDIR}/../../output_base/external/entangled
80+
-I${CURDIR}/../../output_base/external/http_parser
81+
-I${CURDIR}/../../output_base/external/keccak
82+
-I${CURDIR}/../../output_base/external/keccak/lib/high/Keccak
83+
-I${CURDIR}/../../output_base/external/keccak/lib/common
84+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/OptimizedAVX512a
85+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/OptimizedAsmX86-64
86+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Inplace32BI
87+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/OptimizedXOP
88+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/OptimizedAVX512c
89+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Optimized32biAsmARM
90+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/OptimizedAsmAVR8
91+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/OptimizedAVX2
92+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/OptimizedAsmARM
93+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Compact64
94+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Reference
95+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Optimized64/CompiledByGCC474forNehalem
96+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Optimized64/CompiledByGCC474forHaswell
97+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Optimized64
98+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Optimized64/CompiledByGCC474forSandyBridge
99+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Reference32BI
100+
-I${CURDIR}/../../output_base/external/keccak/lib/low/KeccakP-1600/Optimized64AsmARM
101+
-I${CURDIR}/../../output_base/external/mbedtls_2_16_6/include
102+
}
103+
104+
bundles:
105+
{
106+
// List of files copied from the build host into the App for runtime usage
107+
file:
108+
{
109+
resolv.conf /etc/
110+
}
111+
}
112+
113+
requires:
114+
{
115+
device:
116+
{
117+
[rw] /dev/ttyHS0 /dev/ttyHS0
118+
}
119+
}

endpoint/endpointComp/endpoint.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors
3+
* All Rights Reserved.
4+
* This is free software; you can redistribute it and/or modify it under the
5+
* terms of the MIT license. A copy of the license can be found in the file
6+
* "LICENSE" at the root of this distribution.
7+
*/
8+
9+
#include "endpoint.h"
10+
11+
#include "legato.h"
12+
13+
#include "endpoint/endpoint_core.h"
14+
#include "utils/cipher.h"
15+
16+
#define TEST_VALUE 0
17+
#define TEST_MESSAGE "THISISMSG9THISISMSG9THISISMSG"
18+
#define TEST_MESSAGE_FMT "ascii"
19+
#define TEST_TAG "POWEREDBYTANGLEACCELERATOR9"
20+
#define TEST_ADDRESS \
21+
"POWEREDBYTANGLEACCELERATOR999999999999999999999999999999999999999999999999" \
22+
"999999A"
23+
#define TEST_NEXT_ADDRESS \
24+
"POWEREDBYTANGLEACCELERATOR999999999999999999999999999999999999999999999999" \
25+
"999999B"
26+
#define TEST_DEVICE_ID "470010171566423"
27+
28+
const uint8_t test_key[32] = {82, 142, 184, 64, 74, 105, 126, 65, 154, 116, 14, 193, 208, 41, 8, 115,
29+
158, 252, 228, 160, 79, 5, 167, 185, 13, 159, 135, 113, 49, 209, 58, 68};
30+
const uint8_t test_iv[AES_IV_SIZE] = {164, 3, 98, 193, 52, 162, 107, 252, 184, 42, 74, 225, 157, 26, 88, 72};
31+
32+
static void print_help(void) {
33+
puts(
34+
"NAME\n"
35+
"endpoint - The endpoint for sending transactions to Tangle-accelerator.\n"
36+
"\n"
37+
"SYNOPSIS\n"
38+
" endpoint [-h]\n"
39+
" endpoint [--help]\n"
40+
"\n"
41+
"OPTIONS\n"
42+
" -h\n"
43+
" --help\n"
44+
" Print the information for helping the users. Ignore other arguments.\n"
45+
"\n");
46+
47+
exit(EXIT_SUCCESS);
48+
}
49+
50+
COMPONENT_INIT {
51+
// FIXME:
52+
// The current code is a prototype for passing the CI.
53+
// The initialization of hardware and the input from hardware are not implemented yet.
54+
le_arg_SetFlagCallback(print_help, "h", "help");
55+
le_arg_Scan();
56+
57+
uint8_t iv[AES_IV_SIZE] = {0};
58+
59+
memcpy(iv, test_iv, AES_IV_SIZE);
60+
srand(time(NULL));
61+
62+
while (true) {
63+
send_transaction_information(TEST_VALUE, TEST_MESSAGE, TEST_MESSAGE_FMT, TEST_TAG, TEST_ADDRESS, TEST_NEXT_ADDRESS,
64+
test_key, TEST_DEVICE_ID, iv);
65+
sleep(10);
66+
}
67+
}

endpoint/endpointComp/endpoint.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors
3+
* All Rights Reserved.
4+
* This is free software; you can redistribute it and/or modify it under the
5+
* terms of the MIT license. A copy of the license can be found in the file
6+
* "LICENSE" at the root of this distribution.
7+
*/
8+
9+
#ifndef ENDPOINT_H
10+
#define ENDPOINT_H
11+
12+
/**
13+
* @brief Print the help message of endpoint application
14+
*/
15+
static void print_help(void);
16+
17+
#endif // ENDPOINT_H

endpoint/endpoint.c renamed to endpoint/endpoint_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* "LICENSE" at the root of this distribution.
77
*/
88

9-
#include "endpoint.h"
9+
#include "endpoint_core.h"
1010
#include <stdio.h>
1111
#include <stdlib.h>
1212
#include <string.h>

endpoint/endpoint.h renamed to endpoint/endpoint_core.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* "LICENSE" at the root of this distribution.
77
*/
88

9-
#ifndef ENDPOINT_H
10-
#define ENDPOINT_H
9+
#ifndef ENDPOINT_CORE_H
10+
#define ENDPOINT_CORE_H
1111

1212
#define ADDR_LEN 81
1313
#define MAX_MSG_LEN 1024
@@ -36,4 +36,4 @@ status_t send_transaction_information(const int value, const char* message, cons
3636
const char* address, const char* next_address, const uint8_t* private_key,
3737
const char* device_id, uint8_t* iv);
3838

39-
#endif // ENDPOINT_H
39+
#endif // ENDPOINT_CORE_H

endpoint/test_endpoint.c renamed to endpoint/test_endpoint_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <time.h>
1313
#include "common/macros.h"
1414
#include "common/ta_errors.h"
15-
#include "endpoint.h"
15+
#include "endpoint_core.h"
1616
#include "tests/test_define.h"
1717
#include "utils/cipher.h"
1818

0 commit comments

Comments
 (0)