forked from DLTcollab/TA-endpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate ta-endpoint into legato
Add legato build target into gitignore. Add new file util/utils.h util/utils.c for utitlity functions. Add build libta_endpoint.so library target for legato app ta_app into Makefile. Add ta_app build target and cleanup target into Makefile. Remove redefined macro inside `conn_http.h`. Add new directory endpointComponent and files for legato app ta_app. Move utility functions inside `main.c` into utils.h utils.c. Add doxgen comment for utils.h. Fix compile warning inside utils directory files. Closes DLTcollab#20
- Loading branch information
Showing
15 changed files
with
343 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
sources: | ||
{ | ||
endpoint.c | ||
} | ||
|
||
cflags: | ||
{ | ||
-g -O0 | ||
-DDEBUG=1 | ||
-I$CURDIR/../utils | ||
-I$CURDIR/../connectivity | ||
-I$CURDIR/../third_party/http-parser | ||
-I$CURDIR/../third_party/mbedtls/include | ||
} | ||
|
||
ldflags: | ||
{ | ||
-L$CURDIR/../ | ||
} | ||
|
||
bundles: | ||
{ | ||
file: | ||
{ | ||
[r] resolv.conf /etc/ | ||
$CURDIR/../libta_endpoint.so /lib/ | ||
} | ||
} | ||
|
||
requires: | ||
{ | ||
device: | ||
{ | ||
[rw] /dev/ttyHS0 /dev/ttyHS0 | ||
} | ||
|
||
lib: | ||
{ | ||
libta_endpoint.so | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "interfaces.h" | ||
#include "legato.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <termios.h> | ||
#include "connectivity/conn_http.h" | ||
#include "utils/crypto_utils.h" | ||
#include "utils/serializer.h" | ||
#include "utils/tryte_byte_conv.h" | ||
#include "utils/uart_utils.h" | ||
#include "utils/utils.h" | ||
|
||
#define MSG "%s:%s" | ||
|
||
COMPONENT_INIT { | ||
uint8_t ciphertext[1024] = {0}, iv[16] = {0}, raw_msg[1000] = {0}; | ||
uint32_t raw_msg_len = 1 + ADDR_LEN + 20, ciphertext_len = 0, msg_len; | ||
char tryte_msg[1024] = {0}, msg[1024] = {0}, addr[ADDR_LEN + 1] = ADDRESS, next_addr[ADDR_LEN + 1] = {0}; | ||
srand(time(NULL)); | ||
|
||
// init uart for modem | ||
int fd = uart_init(); | ||
if (fd < 0) { | ||
LE_ERROR("Error in initializing UART\n"); | ||
} | ||
|
||
// create log file | ||
if (log_address(next_addr) != 0) { | ||
LE_ERROR("log address failed\n"); | ||
} | ||
|
||
char *response = NULL; | ||
time_t timer; | ||
char time_str[26]; | ||
struct tm *tm_info; | ||
|
||
fd_set rset; | ||
struct timeval tv; | ||
tv.tv_sec = 0; | ||
tv.tv_usec = 500; | ||
// TODO:change to none blocking I/O descriptor | ||
while (true) { | ||
FD_ZERO(&rset); | ||
FD_SET(fd, &rset); | ||
select(fd + 1, &rset, NULL, NULL, &tv); | ||
|
||
if (FD_ISSET(fd, &rset)) { | ||
time(&timer); | ||
tm_info = localtime(&timer); | ||
strftime(time_str, 26, "%Y-%m-%d %H:%M:%S", tm_info); | ||
printf("%s\n", time_str); | ||
gen_trytes(ADDR_LEN, next_addr); | ||
|
||
response = uart_read(fd); | ||
// real transmitted data | ||
snprintf((char *)raw_msg, raw_msg_len, MSG, next_addr, response); | ||
LE_DEBUG("Raw_msg:%s\n", raw_msg); | ||
uint8_t private_key[AES_BLOCK_SIZE * 2] = {0}; | ||
uint8_t id[IMSI_LEN + 1] = {0}; | ||
|
||
if (get_aes_key(private_key) != 0) { | ||
LE_ERROR("%s\n", "get aes key error"); | ||
} | ||
// fetch Device_ID (IMSI, len <= 15) | ||
if (get_device_id((char *)id) != 0) { | ||
LE_ERROR("%s\n", "get device id error"); | ||
} | ||
|
||
ciphertext_len = ta_encrypt(raw_msg, strlen((char *)raw_msg), ciphertext, 1024, iv, private_key, id); | ||
if (ciphertext_len == 0) { | ||
LE_ERROR("%s\n", "ta_encrypt msg error"); | ||
} | ||
serialize_msg(iv, ciphertext_len, ciphertext, msg, &msg_len); | ||
bytes_to_trytes((const unsigned char *)msg, msg_len, tryte_msg); | ||
|
||
// Init http session. verify: check the server CA cert. | ||
char msg_body[1024]; | ||
gen_tryte_msg(tryte_msg, addr, msg_body); | ||
if (send_https_msg(HOST, PORT, API, msg_body, 1024) != HTTP_OK) { | ||
LE_ERROR("Response from ta server failed\n"); | ||
} | ||
|
||
strncpy(addr, next_addr, ADDR_LEN); | ||
free(response); | ||
response = NULL; | ||
printf( | ||
"========================Finishing Sending " | ||
"Transaction========================\n\n"); | ||
} | ||
if (tcflush(fd, TCIOFLUSH) != 0) { | ||
perror("tcflush error"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nameserver 8.8.8.8 | ||
nameserver 8.8.4.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.