From fd501b976df6e9be9fe67b8edb4bf3d8bcc0fa95 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 13 Mar 2019 14:59:07 +0100 Subject: [PATCH] [CI] Added test-expect-version tool --- tools/test-expect-version/Makefile | 11 ++ .../test-expect-version/test-expect-version.c | 109 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 tools/test-expect-version/Makefile create mode 100644 tools/test-expect-version/test-expect-version.c diff --git a/tools/test-expect-version/Makefile b/tools/test-expect-version/Makefile new file mode 100644 index 00000000..5d4d1094 --- /dev/null +++ b/tools/test-expect-version/Makefile @@ -0,0 +1,11 @@ +CC=gcc +CFLAGS=-Wall -DWOLFSSL_DTLS -DWOLFSSL_DEBUG -DTFM_TIMING_RESISTANT -g -ggdb +EXE=test-expect-version + +LIBS=-lwolfssl -lpthread + +$(EXE): $(EXE).o + $(CC) -o $@ $^ $(CFLAGS) $(LIBS) + +clean: + rm -f *.o $(EXE) diff --git a/tools/test-expect-version/test-expect-version.c b/tools/test-expect-version/test-expect-version.c new file mode 100644 index 00000000..42db0146 --- /dev/null +++ b/tools/test-expect-version/test-expect-version.c @@ -0,0 +1,109 @@ +/* test-update-server.c + * + * Copyright (C) 2006-2019 wolfSSL Inc. + * + * This file is part of wolfSSL. (formerly known as CyaSSL) + * + * wolfSSL 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 2 of the License, or + * (at your option) any later version. + * + * wolfSSL 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + *============================================================================= + * + * OTA Upgrade mechanism implemented using DTLS 1.2 + * + */ + +#define _XOPEN_SOURCE 600 + +#include /* standard in/out procedures */ +#include /* defines system calls */ +#include /* necessary for memset */ +#include +#include /* used for all socket calls */ +#include /* used for sockaddr_in6 */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define MSGLEN (4 + 4 + 8) +#define PORT "/dev/ttyS0" + +void alarm_handler(int signo) +{ + printf("0\n"); + exit(0); +} + + + +int main(int argc, char** argv) +{ + struct termios tty; + int res, serialfd; + int star = 0; + int i = 3; + uint32_t ver = 0; + sigset(SIGALRM, alarm_handler); + + + if (argc != 1) { + printf("Usage: %s\n", argv[0]); + exit(1); + } + + serialfd = open(PORT, O_RDWR | O_NOCTTY); + tcgetattr(serialfd, &tty); + cfsetospeed(&tty, B115200); + cfsetispeed(&tty, B115200); + tty.c_cflag = (tty.c_cflag & ~CSIZE) | (CS8); + tty.c_iflag &= ~(IGNBRK | IXON | IXOFF | IXANY| INLCR | ICRNL); + tty.c_oflag &= ~OPOST; + tty.c_oflag &= ~(ONLCR|OCRNL); + tty.c_cflag &= ~(PARENB | PARODD | CSTOPB); + tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + tty.c_iflag &= ~ISTRIP; + tty.c_cc[VMIN] = 0; + tty.c_cc[VTIME] = 5; + tcsetattr(serialfd, TCSANOW, &tty); + + alarm(30); + + while (i >= 0) { + char c; + res = read(serialfd, &c, 1); + if (res <= 0) { + usleep(10000); + continue; + } + if (!star) { + if (c == '*') { + star = 1; + i = 3; + } else { + star = 0; + } + } else { + ver += (((uint32_t)c) << (i-- * 8)); + } + } + printf("%d\n", ver); + close(serialfd); + return 0; +} +